Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Block Negative Balances
- * Delete users that try to login to an account that has a negative balance.
- * @version 1.0
- */
- add_filter( 'authenticate', 'mycred_delete_users_with_negative_balances', 990, 3 );
- function mycred_delete_users_with_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 ) && ! $mycred->exclude_user( $account->ID ) ) {
- $balance = $mycred->get_users_balance( $account->ID, $type );
- if ( $balance < 0 ) {
- // Delete user
- wp_delete_user( $account->ID );
- return new WP_Error( 'mycred_negative', __( 'Account Closed' ) );
- }
- }
- return $user;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement