Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of Hugo

Support: Creating & Extending

Existing and new plugins/components and themes.

bp_core_new_subnav_item won’t create item under Profile section? (5 posts)

Started 5 months ago by: Sameera

  • Profile picture of Sameera Sameera said 5 months ago:

    Hi,
    I’m trying to add an admin-only sub tab under the profile section of users. Here’s my code:

    bp_core_new_subnav_item( array(
    								'name' =>  __( 'Test', 'buddypress' ),
    								'slug' => 	'test',
    								'parent_url' => trailingslashit( bp_displayed_user_domain() . $bp->profile->slug ),
    								'parent_slug'  => $bp->profile->slug,
    								'screen_function' => 'test_something',
    								'position' 			=> 40,
    								'user_has_access' 	=> current_user_can('edit_users'),
    						        'site_admin_only' 	=> true,
    						        'item_css_id'   	=> $bp->profile->id
    							) );

    I know I’m doing this mostly right, because I can get the tab on my own (admin) profile page. However, I can’t see the tab on anybody else’s. If I change the slug to settings, I will see the tab on any of the users as expected.
    Therefore, this looks like this behavior is specific to Profile section.

    In bp-members-loader.php : Line 137, I see the following code that cancels the sub nav creation for anybody other than the current user.

    if ( !is_user_logged_in() && !bp_is_user() )
     return;

    Is this the reason why adding sub menu doesn’t work? Is there a way around this?

  • Profile picture of modemlooper modemlooper said 5 months ago:

    Get rid of user_has_access and site_admin_only

    use:

    if ( !is_user_logged_in() && !is_super_admin() )
    return false;

  • Profile picture of Sameera Sameera said 5 months ago:

    Removing user_has_access and site_admin_only alone didn’t work.

    Did you mean to replace the code in bp-members-loader.php : Line 137 to

    if ( !is_user_logged_in() && !is_super_admin() )
    return false;

    ?
    I don’t think I wanna edit core files :(

  • Profile picture of Boone Gorges Boone Gorges said 5 months ago:

    @sameeraperera You’re correct that this is an xprofile-only problem.

    In bp-default, we don’t show the options_nav at all (where subnav items appear) on others’ profiles. See http://buddypress.trac.wordpress.org/browser/tags/1.5.2/bp-themes/bp-default/members/single/profile.php#L12

    This does not seem like the optimal design to me. I’ve opened a ticket to fix it in a future release: http://buddypress.trac.wordpress.org/ticket/3877 In the meantime, you can override members/single/profile.php in your theme, and remove the bp_is_my_profile() check.

  • Profile picture of Sameera Sameera said 5 months ago:

    @boonebgorges
    Thanks!!
    I actually added a
    || current_user_can('edit_users')
    to the bp_is_my_profile() check. Otherwise bad things were gonna happen :)