Skip to content

Instantly share code, notes, and snippets.

@imath
Created December 22, 2020 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imath/f36855ca5d000206696a0204e7cbb6ea to your computer and use it in GitHub Desktop.
Save imath/f36855ca5d000206696a0204e7cbb6ea to your computer and use it in GitHub Desktop.
<?php
// Needs https://fr.wordpress.org/plugins/bp-create-group-type/ to be active.
function alersn_set_group_type_tabs( $tabs = array() ) {
$group_types = bp_groups_get_group_types( array( 'has_directory' => true ), 'objects' );
$terms_count = get_terms(
array(
'taxonomy' => bp_get_group_type_tax_name(),
'include' => wp_list_pluck( $group_types, 'db_id' ),
'hide_empty' => false,
'count' => true,
)
);
$group_types_count = wp_list_pluck( $terms_count, 'count', 'term_id' );
foreach ( $group_types as $type_id => $type ) {
$count = 0;
if ( isset( $group_types_count[ $type->db_id ] ) ) {
$count = $group_types_count[ $type->db_id ];
}
$tabs[ $type_id ] = array(
'component' => 'groups',
'slug' => esc_attr( $type->directory_slug ),
'li_class' => array( 'bpgt-type-tab' ),
'link' => bp_get_groups_directory_permalink(),
'text' => esc_attr( $type->name ),
'count' => bp_core_number_format( $count ),
);
}
return $tabs;
}
add_action( 'bp_nouveau_get_groups_directory_nav_items', 'alersn_set_group_type_tabs' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment