Filter
uncanny-automator-pro
automator_pro_generate_random_string_numbers
Filters the characters used to generate random strings, allowing customization of the allowed digits.
add_filter( 'automator_pro_generate_random_string_numbers', $callback, 10, 1 );
Description
Filters the string of allowed numeric characters for the Generate Random String action. Developers can modify this string to include or exclude specific numbers or custom numeric sequences when generating random strings.
Usage
add_filter( 'automator_pro_generate_random_string_numbers', 'your_function_name', 10, 1 );
Return Value
The filtered value.
Examples
/**
* Example of how to filter the allowed characters for the "Generate random string" action.
* This example will prepend a custom character to the default set of numbers.
*/
add_filter(
'automator_pro_generate_random_string_numbers',
function ( $default_numbers ) {
// Let's say we want to ensure the character '9' is always followed by a hyphen.
// In a real-world scenario, you might add a specific character, remove one,
// or rearrange the order for some specific requirement.
return $default_numbers . '-';
},
10, // Priority
1 // Accepted arguments
);
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
uncanny-automator-pro/src/integrations/generator/actions/uoa-generate-random-string.php:198
public function generate_random_string( $length = 16, $nums = 'false', $lower_abc = 'false', $upper_abc = 'false', $special_chars = 'false' ) {
if (
'false' === $nums &&
'false' === $lower_abc &&
'false' === $upper_abc &&
'false' === $special_chars
) {
$nums = 'true';
$lower_abc = 'true';
$upper_abc = 'true';
$special_chars = 'true';
}
$allowed_chars = '';
if ( 'false' !== $nums ) {
$allowed_chars .= apply_filters( 'automator_pro_generate_random_string_numbers', '0123456789' );
}
if ( 'false' !== $lower_abc ) {
$allowed_chars .= apply_filters( 'automator_pro_generate_random_string_lower_alphabets', 'abcdefghijklmnopqrstuvwxyz' );
}
if ( 'false' !== $upper_abc ) {
$allowed_chars .= apply_filters( 'automator_pro_generate_random_string_upper_alphabets', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' );
}
if ( 'false' !== $special_chars ) {
$allowed_chars .= apply_filters( 'automator_pro_generate_random_string_special_chars', '!#$%&()*+,-./:;<=>?@[]^_`{|}~' );
}
$allowed_chars = apply_filters( 'automator_pro_generate_random_string_allowed_characters', $allowed_chars );
return substr( str_shuffle( str_repeat( $allowed_chars, ceil( $length / strlen( $allowed_chars ) ) ) ), 1, $length );
}