Skip to:
Content
Pages
Categories
Search
Top
Bottom

bp_core_new_subnav_item won’t create item under Profile section?

  • @sameeraperera

    Member

    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?

Viewing 4 replies - 1 through 4 (of 4 total)
  • @modemlooper

    Moderator

    Get rid of user_has_access and site_admin_only

    use:

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

    @sameeraperera

    Member

    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 :(

    @boonebgorges

    Keymaster

    @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 https://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: https://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.

    @sameeraperera

    Member

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

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘bp_core_new_subnav_item won’t create item under Profile section?’ is closed to new replies.
Skip to toolbar