Skip to content

Instantly share code, notes, and snippets.

@gabrielmerovingi
Created December 1, 2015 00:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielmerovingi/f16f1f982150eb02d795 to your computer and use it in GitHub Desktop.
Save gabrielmerovingi/f16f1f982150eb02d795 to your computer and use it in GitHub Desktop.
/**
* 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