Skip to:
Content
Pages
Categories
Search
Top
Bottom

deny access to admins – PHP errors


  • maelga
    Participant

    @maelga

    Hi, I’m using the below snippet from @danbp

    // 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 );

    When enabling WP_DEBUG, I get the following errors:

    • Use of undefined constant bp_is_profile – assumed ‘bp_is_profile’ in …/fonctions.php in line 291
    • Undefined property: stdClass::$id in …/fonctions.php in line 291

    Although the redirect works fine, is there any way to resolve these 2 errors?

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

  • shanebp
    Moderator

    @shanebp

    Try:

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

    maelga
    Participant

    @maelga

    Thanks @shanebp

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