Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
Created August 22, 2014 14:59
Show Gist options
  • Save gabrielmerovingi/963e1f62c1855aed7830 to your computer and use it in GitHub Desktop.
Save gabrielmerovingi/963e1f62c1855aed7830 to your computer and use it in GitHub Desktop.
Awards the content author the same amount of points as the user who shares their content using the ShareThis plugin with myCRED.
add_filter( 'mycred_add', 'mycred_award_post_author_for_share', 90, 3 );
function mycred_award_post_author_for_share( $reply, $request, $mycred ) {
// Only applicable if points are being awarded for sharing
if ( $reply === false || $request['ref'] != 'share' ) return $reply;
// Prep
$user_id = absint( $request['user_id'] );
$post_id = absint( $request['ref_id'] );
$post = get_post( $post_id );
if ( ! isset( $post->post_author ) ) return $reply;
// Make sure this is not the post author sharing or that the post author is excluded from using myCRED
if ( $user_id == $post->post_author || $mycred->exclude_user( $post->post_author ) ) return $reply;
// Award the same amount of points as the user who is sharing
$mycred->update_users_balance( $post->post_author, $request['amount'], $request['type'] );
// Add to the log
$mycred->add_to_log(
$request['ref'],
$post->post_author,
$request['amount'],
'%plural% for getting your content shared',
$post_id,
array( 'ref_type' => 'post' ),
$request['type']
);
return $replay;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment