ulgm_password_special_chars
Filters the allowed special characters for password strength validation when a user registers or resets their password.
add_filter( 'ulgm_password_special_chars', $callback, 10, 1 );
Description
Filter the characters considered "special" when generating a password. Use this hook to customize the allowed special characters for improved password strength or specific requirements before a password is generated.
Usage
add_filter( 'ulgm_password_special_chars', 'your_function_name', 10, 1 );
Parameters
-
$special_chars(mixed) - This filter allows you to modify the boolean value determining whether special characters are included in the generated password.
Return Value
The filtered value.
Examples
/**
* Example of how to filter the special characters used in password generation.
* This example adds a few more special characters to the default set.
*
* @param mixed $special_chars The current special characters allowed for password generation.
* @return mixed The modified set of special characters.
*/
add_filter( 'ulgm_password_special_chars', function( $special_chars ) {
// If the default is true, we want to add to the default set.
if ( $special_chars === true ) {
// WordPress's default special characters are: !@#$%&*()_+-=[]{}|;:,.<>?
// Let's add some more common ones.
$additional_special_chars = '^`~';
return '!@#$%&*()_+-=[]{}|;:,.<>?' . $additional_special_chars;
}
// If $special_chars is already a string (meaning it was previously filtered
// or set to a custom string), we can append to it.
if ( is_string( $special_chars ) ) {
$additional_special_chars = '^`~';
return $special_chars . $additional_special_chars;
}
// If $special_chars is false, we don't want to add any special characters,
// so we return false.
return false;
}, 10, 1 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/helpers/shared-functions.php:961
public static function wp_generate_password( $length = 18, $special_chars = true, $extra_special_chars = false ) {
$length = apply_filters( 'ulgm_password_length', $length );
$special_chars = apply_filters( 'ulgm_password_special_chars', $special_chars );
$extra_special_chars = apply_filters( 'ulgm_password_extra_special_chars', $extra_special_chars );
return wp_generate_password( $length, $special_chars, $extra_special_chars );
}