Last active
April 8, 2023 14:47
-
-
Save KaineLabs/ba68c8d6439507d306b7268a2c8edd70 to your computer and use it in GitHub Desktop.
Add Members Directory Statistics Old Style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Add Members Directory Statistics Old Style. | |
*/ | |
function yzc_add_members_directory_statistics() { | |
if ( ! bp_is_members_directory() ) { | |
return; | |
} | |
$user_id = bp_get_member_user_id(); | |
$statistics = array( | |
'followers' => __( 'Followers','youzer' ), | |
'posts' => __( 'Posts','youzer' ), | |
'views' => __( 'Views','youzer' ), | |
); | |
?> | |
<div class="yz-custom-statistics"> | |
<?php foreach ( $statistics as $name => $title ) { ?> | |
<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_statistic_number( youzify_get_user_statistic_number( $user_id, $name ) ); ?></div> | |
<span class="yzc-stat-title" style="color: #9e9e9e; font-weight: 600; font-size: 13px;margin-top: 5px;"><?php echo $title; ?></span> | |
</div> | |
<?php } ?> | |
</div> | |
<?php | |
} | |
add_action( 'bp_directory_members_item', 'yzc_add_members_directory_statistics', 9999 ); | |
/** | |
* Convert Statistics Number | |
*/ | |
function yzc_get_statistic_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