Filter uncanny-automator-pro

automator_pro_generate_random_string_special_chars

Filters the set of special characters used to generate random strings, allowing customization of character sets.

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

Description

This filter hook allows developers to modify the set of special characters used when generating a random string. It's applied after the default special characters are defined, enabling customization of the character pool.


Usage

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

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to filter the special characters allowed in a generated random string.
 * This function will remove the '@' and ']' characters from the default set.
 *
 * @param string $special_chars The default string of special characters.
 * @return string The modified string of special characters.
 */
add_filter( 'automator_pro_generate_random_string_special_chars', 'my_custom_automator_special_chars', 10, 1 );

function my_custom_automator_special_chars( $special_chars ) {
    // Remove '@' and ']' from the allowed special characters.
    $special_chars = str_replace( [ '@', ']' ], '', $special_chars );
    return $special_chars;
}

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

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