ulgm_password_extra_special_chars
Filters the string of extra special characters used in password generation, allowing modification before they are applied.
add_filter( 'ulgm_password_extra_special_chars', $callback, 10, 1 );
Description
Filters the string of characters considered "extra special" when generating a password. Use this hook to add or remove characters from the default set, allowing for more complex password requirements beyond standard special characters. This hook fires during password generation.
Usage
add_filter( 'ulgm_password_extra_special_chars', 'your_function_name', 10, 1 );
Parameters
-
$extra_special_chars(mixed) - This parameter allows you to include additional special characters in the generated password beyond the default set.
Return Value
The filtered value.
Examples
/**
* Filter to add specific extra special characters to the password generation.
*
* This example adds the '#' and '$' characters to the set of allowed extra
* special characters for password generation.
*
* @param mixed $extra_special_chars The current set of extra special characters.
* @return string|bool The modified set of extra special characters, or false to disable.
*/
add_filter( 'ulgm_password_extra_special_chars', function( $extra_special_chars ) {
// Check if we are currently adding extra special characters.
// If $extra_special_chars is false, it means we are not supposed to add them,
// so we return false to maintain that behavior.
if ( false === $extra_special_chars ) {
return false;
}
// If $extra_special_chars is already a string (meaning other filters might have
// added characters), append our new characters to it.
if ( is_string( $extra_special_chars ) ) {
$extra_special_chars .= '#$';
} else {
// If $extra_special_chars is not a string, it's likely the default boolean 'false'
// or an empty string. In this case, we set it to our desired string.
// We are assuming that if this filter is fired, we *do* want extra special chars.
$extra_special_chars = '#$';
}
return $extra_special_chars;
}, 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:962
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 );
}