Skip to:
Content
Pages
Categories
Search
Top
Bottom

Deny access to admins profile not working


  • Kristian Yngve
    Participant

    @kristianngve

    Even after removing all probably issues in my plugins, functions and bp-custim.php, I can’t seem to get the ‘Deny access to admins profile not working’ to work:

    //deny access to admins profile. User is redirected to the homepage
    function bpfr_hide_admins_profile() {
    	global $bp; 
    	if(bp_is_profile && $bp->displayed_user->id == 1 && $bp->loggedin_user->id != 1) :
    		wp_redirect( home_url() );
    	exit;
    	endif;
    }
    add_action( 'wp', 'bpfr_hide_admins_profile', 1 );

    I have everything up to date as much as possible.

    Any ideas?

    Have also tried: bp_is_user()

    many thanks

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

  • shanebp
    Moderator

    @shanebp

    I’m surprised that your code ever worked.

    Try:

    function bpfr_hide_admins_profile() {
         if( bp_is_user() && bp_displayed_user_id() == 1 && bp_loggedin_user_id() != 1 ) {
    	bp_core_redirect( site_url() );
         }
    }
    add_action( 'bp_ready', 'bpfr_hide_admins_profile', 1 );

    Of course – this assumes that there is only one site admin and the user_id for that admin is 1.


    Kristian Yngve
    Participant

    @kristianngve

    It all works, thank you so much @shanebp!

    so if there are more than one admin profiles, i can just use commas?

    for eg:

    function bpfr_hide_admins_profile() {
         if( bp_is_user() && bp_displayed_user_id() == 1,2,3 && bp_loggedin_user_id() != 1,2,3 ) {
    	bp_core_redirect( site_url() );
         }
    }
    add_action( 'bp_ready', 'bpfr_hide_admins_profile', 1,2,3 );
    

    This to do like that correct?


    Tekpolis
    Participant

    @tekpolis

    Hello,
    I have the same problem, any idea ? Thanks


    shanebp
    Moderator

    @shanebp

    function bpfr_hide_admins_profile() {
    	
        $admin_ids = array( 1, 22, 48 );
    	
        if( bp_is_user() ) {
    	if ( in_array( bp_displayed_user_id(), $admin_ids ) && ! in_array( bp_loggedin_user_id(), $admin_ids ) ) {
    		bp_core_redirect( site_url() );
            }
        }
    	
    }
    add_action( 'bp_ready', 'bpfr_hide_admins_profile', 1 );

    Kristian Yngve
    Participant

    @kristianngve

    Test this, and it works! @shanebp, thank you for all your help in this – finally a resolution to this issue spanning 5 -6 years!

    Thanks again.

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