Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
Created March 30, 2014 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielmerovingi/9871948 to your computer and use it in GitHub Desktop.
Save gabrielmerovingi/9871948 to your computer and use it in GitHub Desktop.
add_filter( 'mycred_add', 'enforce_mycred_form_limit', 10, 3 );
function enforce_mycred_form_limit( $reply, $request, $mycred ) {
// First we only want to target form submissions
if ( $request['ref'] != 'contact_form_submission' ) )
return $reply;
// If already declined by someone, horour it
if ( $reply !== true ) return $reply;
// Limit
$limit = 1;
// Get how many points a user has received today for form submissions
$count = mycred_get_total_by_time( 'today', 'now', 'contact_form_submission', $request['user_id'] );
// Assuming 1 point is awarded for each form submission
$can_max_earn = $limit * 1;
// Check if we reached the limit
if ( $count >= $can_max_earn ) return false;
return true;
}
@kompenso
Copy link

Thanks a lot for helping out. Even though I cannot get this to work by copy/pasting your code to functions.php (I am a functions.php editing novice) I just realized that the code does not really accomplish what I intend to do. You code limits the amount of points per day. I need something that can limit the amount of points per form_id.

I have 10 different forms which each awards the user 1000 points for a submission. But the user is only allowed to submit each once.

I hope you have time to point me in the right direction.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment