jaredatch / Shared-Counts

WordPress plugin that leverages SharedCount.com API to quickly retrieve, cache, and display various social sharing counts.
GNU General Public License v2.0
49 stars 16 forks source link

Add ability to filter count by service type #52

Closed billerickson closed 6 years ago

billerickson commented 6 years ago

The shared_counts_single filter lets you customize the share count for a service not built into the plugin (see here). But there's no way to target it by service type, or access the post ID.

If you add an additional button, you can't currently set the count for that button using this filter - it's too generic. We need to include the $id and $type.

Here's a real world example. I'm extending Shared Counts to include a site-specific liking button (BE Like Content).

screenshot

After adding the $id and $type to the filter above, I'm able to set the button's count using this code:

/**
 * Add Heart Count to Shared Counts
 *
 */
function ea_shared_counts_heart_count( $count, $counts, $id, $type ) {
    if( 'heart' == $type )
        $count = intval( get_post_meta( $id, '_be_like_content', true ) );
    return $count;
}
add_filter( 'shared_counts_single', 'ea_shared_counts_heart_count', 10, 4 );

Once this has been merged into core, we should update the wiki to provide this example.