admin管理员组

文章数量:1415653

I create a new tab in my Buddypress groups like so:

bp_core_new_subnav_item( array( 
    'name' => "new tab <span>$count</span>",
    'slug' => 'namings', 
    'parent_url' => $group_link, 
    'parent_slug' => $bp->groups->current_group->slug,
    'screen_function' => 'bp_group_namings', 
    'position' => 50, 
    'user_has_access' => $user_access, 
    'item_css_id' => 'namings' 
));

The $count variable has a value. But, the span is consistently removed from the tab title.

How to get a count in the tab title?

I create a new tab in my Buddypress groups like so:

bp_core_new_subnav_item( array( 
    'name' => "new tab <span>$count</span>",
    'slug' => 'namings', 
    'parent_url' => $group_link, 
    'parent_slug' => $bp->groups->current_group->slug,
    'screen_function' => 'bp_group_namings', 
    'position' => 50, 
    'user_has_access' => $user_access, 
    'item_css_id' => 'namings' 
));

The $count variable has a value. But, the span is consistently removed from the tab title.

How to get a count in the tab title?

Share Improve this question asked Aug 28, 2019 at 23:35 MastaBabaMastaBaba 3113 silver badges12 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 2

You are using the BP Nouveau templates, correct? Span tag works fine in the Legacy templates.

In Nouveau, all links are stripped of span tags. See the calls to function _bp_strip_spans_from_title and functions like bp_nouveau_get_nav_link_text in buddypress\bp-templates\bp-nouveau\includes\template-tags.php.

So remove your span tag from the create subnav item function.

Instead, in Nouveau, use 2 filters for adding a count item.

So something like:

function masta_add_namings_count( $count, $nav_item, $displayed_nav ) {

    if ( $displayed_nav == 'groups' ) {

        if ( $nav_item->slug == 'namings' ) {

            $count = true;

        }

    }

    return $count;

}
add_filter( 'bp_nouveau_nav_has_count', 'masta_add_namings_count', 99, 3 );


function masta_add_namings_count_int( $count, $nav_item, $displayed_nav ) {

    if ( $displayed_nav == 'groups' ) {

        if ( $nav_item->slug == 'namings' ) {

            $group_id = bp_get_current_group_id();

            $count = 666; // pass the group_id to a function that returns the proper count

        }

    }

    return $count;

}
add_filter( 'bp_nouveau_get_nav_count', 'masta_add_namings_count_int', 99, 3 );

本文标签: How to add a count in a custom tab in a Buddypress group