Filter uncanny-automator

automator_esc_with_slash_characters

Filters the characters allowed for escaping in automator strings, controlling special character handling.

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

Description

Filters the characters considered "escaped" within file paths for internal Automator class resolution. Developers can use this to add or remove characters that `addcslashes` should treat as special, affecting how file paths are sanitized for internal class name generation.


Usage

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

Return Value

The filtered value.


Examples

add_filter( 'automator_esc_with_slash_characters', 'my_custom_automator_esc_chars', 10, 1 );

/**
 * Custom function to modify the characters escaped for the Automator class resolver.
 * This example adds a few more characters to be escaped.
 *
 * @param string $default_esc_characters The default string of characters to be escaped.
 * @return string The modified string of characters to be escaped.
 */
function my_custom_automator_esc_chars( $default_esc_characters ) {
	// Add a few more characters to be escaped, for example, question mark and asterisk.
	$additional_chars = '?*';

	// Combine default and additional characters, ensuring no duplicates if necessary (though addcslashes handles this well).
	$modified_esc_characters = $default_esc_characters . $additional_chars;

	// You could also implement more complex logic here, like checking conditions
	// or dynamically determining characters based on other factors.

	return $modified_esc_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

src/core/integration-loader/class-class-resolver.php:70

public function resolve( $file, $uppercase = false, $integration_name = '' ) {

		$file_name  = basename( $file, '.php' );
		$class_name = self::file_name_to_class( $file_name );

		if ( $uppercase ) {
			$class_name = strtoupper( $class_name );
		}

		// Check if it's an internal Automator file.
		$esc_characters = apply_filters( 'automator_esc_with_slash_characters', '/-:\()_,.' );
		$pattern        = '/(' . addcslashes( $this->integrations_directory_path, $esc_characters ) . ')/';

		if ( preg_match( $pattern, $file ) ) {
			$class_name = 'Uncanny_Automator\' . $class_name;
		} else {
			$custom_namespace = isset( Set_Up_Automator::$external_integrations_namespace[ $integration_name ] )
				? Set_Up_Automator::$external_integrations_namespace[ $integration_name ]
				: '';
			$custom_namespace = apply_filters( 'automator_external_class_namespace', $custom_namespace, $class_name, $file_name, $file );
			$class_name       = apply_filters( 'automator_external_class_with_namespace', $custom_namespace . '\' . $class_name, $class_name, $file_name, $file );

			if ( self::validate_namespace( $class_name, $file_name, $file, $integration_name ) ) {
				return apply_filters( 'automator_recipes_class_name', $class_name, $file, $file_name );
			}
		}

		return apply_filters( 'automator_recipes_class_name', $class_name, $file, $file_name );
	}


Scroll to Top