BuddyDev

Search

[Resolved] Redirect BuddyPress Members from everyone except Site admin to search page

  • Participant
    Level: Enlightened
    Posts: 130
    giuseppe on #44784

    Hello,

    I have added your snippet and works.

    function buddydev_hide_members_directory_for_all_except_admin() {
    if ( bp_is_members_directory() && ! is_super_admin() ) {
    bp_do_404();
    load_template( get_404_template() );
    exit( 0 );
    }
    }

    add_action( ‘bp_template_redirect’, ‘buddydev_hide_members_directory_for_all_except_admin’ );

    Only, I’d like to send not admin to another page not 404.

    How could I do?

    Many thanks,

    Giuseppe

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #44791

    Hi Giuseppe,
    Thank you for the question.

    Please remove the above code and use this instead

    
    
    // Redirect from members directory.
    function buddydev_hide_members_directory_for_all_except_admin() {
    	if ( bp_is_members_directory() && ! is_super_admin() ) {
    		$url_to_redirect_to = "http://example.com/some-page";
    		bp_core_redirect( $url_to_redirect_to );
    	}
    }
    
    add_action( 'bp_template_redirect', 'buddydev_hide_members_directory_for_all_except_admin' );
    
    

    Please make sure to change your own url.

    Regards
    Brajesh

  • Participant
    Level: Enlightened
    Posts: 130
    giuseppe on #44803

    Perfect,

    thanks.

    Giuseppe

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #44811

    You are welcome.

The topic ‘ [Resolved] Redirect BuddyPress Members from everyone except Site admin to search page’ is closed to new replies.

This topic is: resolved