bp_core_boot_spammer

Prevent spammers from logging in.

Description

(WP_User|WP_Error) bp_core_boot_spammer( (WP_User|WP_Error) $user ); 

When a user logs in, check if they have been marked as a spammer. If yes then simply redirect them to the home page and stop them from logging in.

Returns (WP_User|WP_Error)

If the user is not a spammer, return the WP_User object. Otherwise a new WP_Error object.

Parameters (1)

0. $user (WP_User|WP_Error)
Either the WP_User object or the WP_Error object, as passed to the authenticate filter.

Usage

  1. if ( !function_exists( 'bp_core_boot_spammer' ) ) { 
  2. require_once '/bp-members/bp-members-functions.php'; 
  3.  
  4. // Either the WP_User object or the WP_Error 
  5. // object, as passed to the 'authenticate' filter. 
  6. $user = null; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = bp_core_boot_spammer($user); 
  10.  

Defined (1)

The function is defined in the following location(s).

/bp-members/bp-members-functions.php  
  1. function bp_core_boot_spammer( $user ) { 
  2.  
  3. // Check to see if the $user has already failed logging in, if so return $user as-is. 
  4. if ( is_wp_error( $user ) || empty( $user ) ) { 
  5. return $user; 
  6.  
  7. // The user exists; now do a check to see if the user is a spammer 
  8. // if the user is a spammer, stop them in their tracks! 
  9. if ( is_a( $user, 'WP_User' ) && ( ( is_multisite() && (int) $user->spam ) || 1 == $user->user_status ) ) { 
  10. return new WP_Error( 'invalid_username', __( '<strong>ERROR</strong>: Your account has been marked as a spammer.', 'buddypress' ) ); 
  11.  
  12. // User is good to go! 
  13. return $user;