Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Block Negative Balances
* Stop users from logging into your website if they have a negative
* myCRED balance.
* @version 1.0
*/
add_filter( 'authenticate', 'mycred_block_negative_balances', 990, 3 );
function mycred_block_negative_balances( $user, $username, $password ) {
// Make sure myCRED is installed
if ( ! defined( 'myCRED_VERSION' ) ) return $user;
// The point type we want to use
$type = 'mycred_default';
// Load myCRED
$mycred = mycred( $type );
$account = get_user_by( 'login', $username );
if ( isset( $account->ID ) ) {
if ( ! $mycred->exclude_user( $account->ID ) ) {
if ( $mycred->get_users_balance( $account->ID, $type ) < 0 )
return new WP_Error( 'mycred_negative', __( 'Account Closed' ) );
}
}
return $user;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.