This topic has 6 replies, 2 voices, and was last updated 7 years by ysfcn.

  • Author
  • #175309
     ysfcn
    Participant

    hi, ı want to restrict buddypress access for non-logged user. ı am adding this code to my  functions.php file in the child theme but it is not working. what am ı doing wrong ? ı dont know. can you help me please?

    COPY CODE
    /**
    * 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' );
    #175343
     Kieran_SQ
    Moderator

    Hi,

    Thanks for reaching out about redirecting logged out users to the register page, I think the issue may be coming from not having bbPress installed, if that is the case changing the code to remove the bbPress element should work. Please add the below to the end of your KLEO Child theme’s functions.php file by going to Appearance > Editor > KLEO Child > functions.php

    COPY CODE
    // Redirect logged out to register page if pages are BuddyPress
    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' );

    Thanks,

    Kieran.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #175571
     ysfcn
    Participant

    unfortunately this code did not work by the way bbPress installed.

    // Redirect logged out to register page if pages are BuddyPress
    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’ );

    #175576
     ysfcn
    Participant

    ı think my KLEO Child theme’s functions.php is not working. because ı paste this code and try it bot not working. 🙂

    add_action( ‘wp_footer’, ‘message_when_logged_in’ );

    function message_when_logged_in() {
    if ( is_user_logged_in() ) {
    echo ‘logged in’;
    } else {
    echo ‘not logged in’;
    }
    }

    #175578
     ysfcn
    Participant

    ı paste this code kleo/function.php and its work succesfully. why kleo chilt function.php doesnt work?

    // Redirect logged out to register page if pages are BuddyPress
    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’ );

    #175777
     Kieran_SQ
    Moderator

    Hi,

    Please can you update this ticket with admin credentials in a private reply so I can take a look at your child theme.

    Thanks,

    Kieran.

    Hi there!!! Help others from the community and mark any reply as solution if it solved your question. Mark as a solution

    If you like the theme or the support you've received please consider leaving us a review on Themeforest!

    Custom development requests can be sent to dev@seventhqueen.com, one of the development team will be happy to discuss your needs.

    #176146
     ysfcn
    Participant
    This reply has been set as private.
Viewing 7 posts - 1 through 7 (of 7 total)

The forum ‘General questions’ is closed to new topics and replies.

Log in with your credentials

Forgot your details?