Created
August 15, 2016 18:38
-
-
Save gabrielmerovingi/8c03987b961d85c1ddbee8654b520ed0 to your computer and use it in GitHub Desktop.
Prevent users from reaching a negative myCRED point balance. Will decline all point transactions that will result in a users balance going minus.
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
/** | |
* Prevent Negative Balances | |
* Make sure users can never get a negative balance. Will allow users | |
* to gain a zero balance. | |
* @since 1.0 | |
* @version 1.0 | |
*/ | |
add_filter( 'mycred_add', 'mycred_pro_no_negative_balance', 999, 2 ); | |
function mycred_pro_no_negative_balance( $reply, $request ) { | |
// Ignore if allready declined | |
if ( $reply === false ) return $reply; | |
extract( $request ); | |
// Ignore point gains | |
if ( $amount > 0 ) return $reply; | |
// Get uses balance | |
$balance = $mycred->get_users_balance( $user_id, $type ); | |
// Prevent negative balances | |
if ( $balance <= 0 || ( $balance - $amount ) < 0 ) return false; | |
// all else return default | |
return $reply; | |
} |
im guessing this goes in the the themes functions?
Where do I add the code to prevent users from getting to a negative balance without earning or buying more points?
This would be exactly what I'm looking for as well as it still allows for users to complete the action.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where do I add the code to prevent users from getting to a negative balance without earning or buying more points?