1

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?

1 Answer 1

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 );
6
  • Thanks. This did not work. Not in my child theme, not in the 2019 theme. Here, too, the span with the count is removed.
    – MastaBaba
    Sep 2, 2019 at 19:41
  • Are you using a plugin or other code to restrict tags? codex.wordpress.org/Function_Reference/wp_kses
    – shanebp
    Sep 3, 2019 at 11:51
  • Not knowingly. I've deactivated all plugins, except Buddypress, ACF Pro and CPT UI. But, still, no number in the tab. Oddly, I also was using the Events Manager plugin, and that plugin is able to get a number in the tab.
    – MastaBaba
    Sep 3, 2019 at 16:12
  • Are you using the BP Nouveau templates? See edited answer.
    – shanebp
    Sep 3, 2019 at 18:59
  • 1
    I'm not aware of any written rationalization. The template pack choices are meant to be very different. Makes writing distributed code that much harder. Take a look at this fork of BP... Scroll down to link: buddyboss.com/pricing
    – shanebp
    Sep 4, 2019 at 11:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.