Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Created April 14, 2023 17:59
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 KaineLabs/2bea9f5355a0dfe35f3f66aee86e9671 to your computer and use it in GitHub Desktop.
Save KaineLabs/2bea9f5355a0dfe35f3f66aee86e9671 to your computer and use it in GitHub Desktop.
Youzify - BuddyPress Add Groups Directory Statistics
<?php
/**
* Add Groups Directory Statistics Old Style.
*/
function yzc_add_groups_directory_statistics() {
if ( ! bp_is_groups_directory() ) {
return;
}
$group_id = bp_get_group_id();
// Get Data.
$members_number = bp_get_group_total_members();
$posts_number = youzify_get_group_total_posts_count( $group_id );
?>
<div class="yz-custom-statistics">
<div class="yz-custom-stat-item" style="display: inline-block;padding: 0 12px;">
<div class="yzc-stat-nbr" style="color: #898989; font-size: 18px; margin-bottom: 5px;"><?php echo yzc_get_group_sstatistic_number( $members_number ); ?></div>
<span class="yzc-stat-title" style="color: #9e9e9e; font-weight: 600; font-size: 13px;margin-top: 5px;"><?php echo __( 'Members', 'youzify' ); ?></span>
</div>
<div class="yz-custom-stat-item" style="display: inline-block;padding: 0 12px;">
<div class="yzc-stat-nbr" style="color: #898989; font-size: 18px; margin-bottom: 5px;"><?php echo yzc_get_group_sstatistic_number( $posts_number ); ?></div>
<span class="yzc-stat-title" style="color: #9e9e9e; font-weight: 600; font-size: 13px;margin-top: 5px;"><?php echo __( 'Posts', 'youzify' ); ?></span>
</div>
</div>
<?php
}
add_action( 'bp_directory_groups_item', 'yzc_add_groups_directory_statistics', 9999 );
/**
* Convert Statistics Number
*/
function yzc_get_group_sstatistic_number( $number ) {
// if Number equal 0 return it.
if ( 0 == $number ) {
return 0;
}
// Define Number Letters.
$abbrevs = array(
12 => __( 'T', 'youzer' ),
9 => __( 'B', 'youzer' ),
6 => __( 'M', 'youzer' ),
3 => __( 'K', 'youzer' ),
0 => ''
);
// Get Number Letter
foreach( $abbrevs as $exponent => $abbrev ) {
if( $number >= pow( 10, $exponent ) ) {
$display_num = $number / pow( 10, $exponent );
$decimals = ( $exponent >= 3 && round( $display_num ) < 100 ) ? 1 : 0;
$number_format = number_format( $display_num, $decimals );
return $number_format . $abbrev;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment