bp_core_boot_spammer( WP_User|WP_Error $user )

Prevent spammers from logging in.

Description Description

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.

Top ↑

Parameters Parameters


(WP_User|WP_Error) (Required) Either the WP_User object or the WP_Error object, as passed to the 'authenticate' filter.

Top ↑

Return Return

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

Source Source

File: bp-members/bp-members-functions.php

function bp_core_boot_spammer( $user ) {

	// Check to see if the $user has already failed logging in, if so return $user as-is.
	if ( is_wp_error( $user ) || empty( $user ) ) {
		return $user;

	// The user exists; now do a check to see if the user is a spammer
	// if the user is a spammer, stop them in their tracks!
	if ( is_a( $user, 'WP_User' ) && ( ( is_multisite() && (int) $user->spam ) || 1 == $user->user_status ) ) {
		return new WP_Error( 'invalid_username', __( '<strong>Error</strong>: Your account has been marked as a spammer.', 'buddypress' ) );

	// User is good to go!
	return $user;

Top ↑

Changelog Changelog

Version Description
1.1.2 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.