Advertisement
designbymerovingi

delete user with negative balance on login

Nov 12th, 2016
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. /**
  2. * Block Negative Balances
  3. * Delete users that try to login to an account that has a negative balance.
  4. * @version 1.0
  5. */
  6. add_filter( 'authenticate', 'mycred_delete_users_with_negative_balances', 990, 3 );
  7. function mycred_delete_users_with_negative_balances( $user, $username, $password ) {
  8.  
  9. // Make sure myCRED is installed
  10. if ( ! defined( 'myCRED_VERSION' ) ) return $user;
  11.  
  12. // The point type we want to use
  13. $type = 'mycred_default';
  14.  
  15. // Load myCRED
  16. $mycred = mycred( $type );
  17. $account = get_user_by( 'login', $username );
  18.  
  19. if ( isset( $account->ID ) && ! $mycred->exclude_user( $account->ID ) ) {
  20.  
  21. $balance = $mycred->get_users_balance( $account->ID, $type );
  22. if ( $balance < 0 ) {
  23.  
  24. // Delete user
  25. wp_delete_user( $account->ID );
  26.  
  27. return new WP_Error( 'mycred_negative', __( 'Account Closed' ) );
  28.  
  29. }
  30.  
  31. }
  32.  
  33. return $user;
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement