shake_error_codesfilter-hookWP 3.0.0

Allows you to change the set of errors that cause the registration/login form to shake.

The error code is specified as the first argument of the WP_Error::add() method:

$error = new WP_Error;
$error->add( 'invalid_email', 'Invalid email' );

The filter receives an array containing codes for such errors. For example, it may contain these error codes:

Array (
	[0] => empty_password
	[1] => empty_email
	[2] => invalid_email
	[3] => invalidcombo
	[4] => empty_username
	[5] => invalid_username
	[6] => incorrect_password
)

Usage

add_filter( 'shake_error_codes', 'wp_kama_shake_error_codes_filter' );

/**
 * Function for `shake_error_codes` filter-hook.
 * 
 * @param string[] $shake_error_codes Error codes that shake the login form.
 *
 * @return string[]
 */
function wp_kama_shake_error_codes_filter( $shake_error_codes ){

	// filter...
	return $shake_error_codes;
}
$shake_error_codes(array)
Set of errors.

Examples

#1 Shake the form when a custom field is not completed

Use the example that creates a simple registration spam check, and add a shake effect when the "I am human" checkbox has not been selected.

add_filter( 'registration_errors', 'add_registration_errors' );
add_action( 'register_form', 'register_form_add_field' );
add_filter( 'shake_error_codes', 'add_shake_error_code' );

/**
 * Adds an error when the registration checkbox was not selected.
 *
 * @param WP_Error $errors
 *
 * @return mixed
 */
function add_registration_errors( $errors ) {
	if ( filter_input( INPUT_POST, 'i-not-robot' ) !== 'yes' ) {
		$errors->add( 'robot_detected', '<strong>ERROR</strong>: Robots are not welcome here!' );
	}

	return $errors;
}

/**
 * Displays a checkbox in the default registration form.
 *
 * @return void
 */
function register_form_add_field() {
	?>
	<p>
		<label>
			<input type="checkbox" name="i-not-robot" value="yes"> I am human!
		</label>
	</p>
	<br>
	<?php
}

/**
 * Adds an error code to the set that causes the form to shake.
 *
 * @param array $shake_error_codes
 *
 * @return array
 */
function add_shake_error_code( $shake_error_codes ) {
	return array_merge( $shake_error_codes, [ 'robot_detected' ] );
}

Changelog

Since 3.0.0 Introduced.

Where the hook is called

login_header()
shake_error_codes
wp-login.php 67
$shake_error_codes = apply_filters( 'shake_error_codes', $shake_error_codes );

Where the hook is used in WordPress

Usage not found.