Created
December 1, 2015 00:05
-
-
Save gabrielmerovingi/f16f1f982150eb02d795 to your computer and use it in GitHub Desktop.
Final code for myCRED Tutorial - http://mycred.me/tutorial/block-users-with-negative-balances/
This file contains hidden or 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
/** | |
* 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