Filter uncanny-automator-pro

automator_pro_generate_random_string_lower_alphabets

Filters the generated random string to include only lowercase alphabets when creating content.

add_filter( 'automator_pro_generate_random_string_lower_alphabets', $callback, 10, 1 );

Description

Filters the lowercase alphabet characters used for generating random strings. Developers can modify this filter to include or exclude specific lowercase letters from the generated output, allowing for custom character sets.


Usage

add_filter( 'automator_pro_generate_random_string_lower_alphabets', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

/**
 * Example of modifying the allowed lowercase alphabets for the random string generator.
 *
 * This filter allows you to add or remove characters from the default set of lowercase
 * alphabets used when generating a random string.
 *
 * @param string $allowed_characters The default string of lowercase alphabets ('abcdefghijklmnopqrstuvwxyz').
 * @return string The modified string of allowed lowercase alphabets.
 */
add_filter( 'automator_pro_generate_random_string_lower_alphabets', 'my_custom_automator_random_string_lower_alphabets', 10, 1 );

function my_custom_automator_random_string_lower_alphabets( $allowed_characters ) {
	// Example: Remove the letters 'a', 'e', 'i', 'o', 'u' (vowels) from the allowed characters.
	$vowels_to_remove = array( 'a', 'e', 'i', 'o', 'u' );
	$allowed_characters = str_replace( $vowels_to_remove, '', $allowed_characters );

	// You could also add characters, for example:
	// $allowed_characters .= 'áéíóúàèìòù';

	return $allowed_characters;
}

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:202

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 );
	}


Scroll to Top