Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Profile tabs – show_for_displayed_user & is_site_admin() ?


  • bigkahunaburger
    Participant

    @bigkahunaburger

    When creating a new profile tab I want it displayed only to the profile owner and the admin. I got the owner part but can’t figure out the admin part:

    	bp_core_new_nav_item( array(
    		'name'                  => 'My Stuff',
    		'slug'                  => 'stuff',
    		'parent_url'            => $bp->displayed_user->domain,
    		'parent_slug'           => $bp->profile->slug,
    		'screen_function'       => 'stuff_screen',			
    		'position'              => 200,
    		'default_subnav_slug'   => 'more_stuff',
    		'show_for_displayed_user' => false
    	) );

    Thanks

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

  • bigkahunaburger
    Participant

    @bigkahunaburger

    Anyone know how to do this?

    Thanks


    danbp
    Moderator

    @danbp

    @bigkahunaburger,

    Allow admin: current_user_can( 'manage_options' )

    Allow the profile owner: bp_loggedin_user_id() == bp_displayed_user_id()

    You might use it like this:

    if ( current_user_can( 'manage_options' ) || bp_loggedin_user_id() == bp_displayed_user_id() ) {
       //do something
    }

    It is also best practice to check that the component is active to avoid errors on update or when BP is deactivated. In this case, xprofile.

    if ( bp_is_active( 'xprofile' ) )


    shanebp
    Moderator

    @shanebp

    A bit simpler approach is to create a variable:

    $display = false;
    if ( is_super_admin() || bp_is_my_profile() )
       $display = true; 

    Then use it:

    ...
    'show_for_displayed_user' => $display
    ...

    bigkahunaburger
    Participant

    @bigkahunaburger

    THANKS @danbp & @shanebp

    I used @shanebp’s solution, but they both worked.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Resolved] Profile tabs – show_for_displayed_user & is_site_admin() ?’ is closed to new replies.
Skip to toolbar