Skip to:
Content
Pages
Categories
Search
Top
Bottom

Hide everything from BuddyPress to non-logged in users


  • benofinil
    Participant

    @benofinil

    Hello !

    First of all, I apologize if the answer already exists, but I am new to the php language, and I do not understand much …

    I created a website for an organization, and I set up a community space thanks to Buddy Press and Youzify.

    Here is my question: I want to make this space completely closed, and not accessible to non-logged in users. I tried putting this php code in wp-content / plugins / bp-custom.php:

    <? php
    / **
    * Redirect the Buddypress directories to the login page for non logged in users.
    * /
    function yzc_redirect_bp_directories_to_login_page () {

    if (! is_user_logged_in () && (bp_is_groups_directory () || bp_is_members_directory ())) {

    // Get pages Buddypress;
    $ bp_pages = get_option (‘bp-pages’);

    // Get the redirection URL
    $ redirect_url = youzify_get_login_page_url ();

    wp_redirect ($ redirect_url);
    go out();
    }
    }

    add_action (‘template_redirect’, ‘yzc_redirect_bp_directories_to_login_page’);

    Now unconnected users cannot have access to member directory and groups directory, but I would like to block access to all BuddyPress pages (such as member profile pages, activity page. ..) and redirect to the login page.

    Could someone help me complete this piece of code?
    Thank you for your help

Viewing 2 replies - 1 through 2 (of 2 total)

  • benofinil
    Participant

    @benofinil

    I found this code and it works perfectly !
    Hope it will help some of you…

    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( ‘/login/’ ) );
    exit();
    }
    }
    add_action( ‘template_redirect’, ‘kleo_page_template_redirect’ );


    aztechnet
    Participant

    @aztechnet

    I too am new to this. I tried your code and it did not work. I changed
    function kleo_page_template_redirect() to function hello_elementor_child_redirect() and add_action( ‘template_redirect’, ‘kleo_page_template_redirect’ ); to add_action( ‘template_redirect’, ‘hello_elementor_child_redirect’ );

    What am doing wrong?

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar