Skip to content

Instantly share code, notes, and snippets.

@KaineLabs
Last active February 5, 2022 03:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KaineLabs/7f93a608d16835a63dccf5be9b7474cf to your computer and use it in GitHub Desktop.
Save KaineLabs/7f93a608d16835a63dccf5be9b7474cf to your computer and use it in GitHub Desktop.
Display Like Button Count
<?php
/**
* Display Like Button Count
*/
function yzc_display_like_button_count( $button, $link ) {
$liked_users = yz_get_who_liked_activities( bp_get_activity_id() );
if ( ! empty( $liked_users ) ) {
$count = count( $liked_users );
} else {
$count = 0;
}
if ( $count == 0 ) {
$title = 'Like';
} elseif ( $count == 1 ) {
$title = sprintf( __( '%d Like', 'youzer' ), $count );
} else {
$title = sprintf( __( '%d Likes', 'youzer' ), $count );
}
return '<a href="'. $link .'" class="button fav bp-secondary-action">' . $title . '</a>';
}
add_filter( 'yz_filter_post_like_button', 'yzc_display_like_button_count', 10, 2 );
/**
* Display Unlike Button Count
*/
function yzc_display_unlike_button_count( $button, $link ) {
$liked_users = yz_get_who_liked_activities( bp_get_activity_id() );
if ( ! empty( $liked_users ) ) {
$count = count( $liked_users );
} else {
$count = 0;
}
return '<a href="'. $link .'" class="button fav bp-secondary-action">' . sprintf( __( '%d Unlike', 'youzer' ), $count ) . '</a>';
}
add_filter( 'yz_filter_post_unlike_button', 'yzc_display_unlike_button_count', 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment