Created
February 14, 2014 12:40
-
-
Save gabrielmerovingi/9000345 to your computer and use it in GitHub Desktop.
A short example of how to enforce a maximum number of times a user can receive points for making a comment. Note that we count the number of times points have been awarded and not the amount of points user have received!
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
add_filter( 'mycred_add', 'mycred_absolute_limit_for_comments', 20, 3 ); | |
function mycred_absolute_limit_for_comments( $reply, $request, $mycred ) { | |
// Ignore declined instances or instances that are not comment related | |
if ( $reply === false || $request['ref'] != 'approved_comment' ) return $reply; | |
// The user ID | |
$user_id = absint( $request['user_id'] ); | |
// Count the number of times this user has received points for comments. | |
$total = mycred_count_ref_instances( 'approved_comment', $user_id ); | |
// Maximum number of times a user can get points for comments | |
$max = 100; | |
// We have not yet reched the max = approve | |
if ( $total < $max ) return true; | |
// All else we decline | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment