protect all BuddyPress & bbPress pages

Welcome mkmcst community Forum Web programming WordPress buddypress protect all BuddyPress & bbPress pages

Viewing 0 reply threads
  • Author
    Posts
    • #8857
      Michael Mc
      Keymaster
      @mkmcst

      So if a user, that doesn’t have an account, visits your BuddyPress Members page, an user Profile page, groups, a Group page, activity page or any other bbPress forums pages will get redirected to the Registration page.
      It is a good idea to use it if you want to force users to register before seeing other members or other social functionality.

      Just add this code to your functions.php file in the child theme and the magic will happen.

      
      /**
      * Redirect buddypress and bbpress pages to registration page
      */
      function kleo_page_template_redirect()
      {
          //if not logged in and on a bp page except registration or activation
          if( ! is_user_logged_in() &&
              ( ( ! bp_is_blog_page() && ! bp_is_activation_page() && ! bp_is_register_page() ) || is_bbpress() )
          )
          {
              wp_redirect( home_url( '/register/' ) );
              exit();
          }
      }
      

      add_action( ‘template_redirect’, ‘kleo_page_template_redirect’ );
      If you want to restrict only BuddyPress pages from guest users then use this code snippet:

      
      /**
      * Redirect buddypress pages to registration page
      */
      function kleo_page_template_redirect()
      {
          //if not logged in and on a bp page except registration or activation
          if( ! is_user_logged_in() && ! bp_is_blog_page() && ! bp_is_activation_page() && ! bp_is_register_page() ) {
              wp_redirect( home_url( '/register/' ) );
              exit();
          }
      }
      

      add_action( ‘template_redirect’, ‘kleo_page_template_redirect’ );
      If you want to restrict only bbPress pages from guest users then use this code snippet:

      
      /**
      * Redirect bbPress pages to registration page
      */
      function kleo_page_template_redirect()
      {
          //if not logged in and on a bp page except registration or activation
          if( ! is_user_logged_in() && is_bbpress() ) {
              wp_redirect( home_url( '/register/' ) );
              exit();
          }
      }
      add_action( 'template_redirect', 'kleo_page_template_redirect' );
Viewing 0 reply threads
  • You must be logged in to reply to this topic.