Filter
uncanny-automator
automator_recipes_class_name
Filters the class name used for Automator recipes before it's determined, allowing customization of recipe classes.
add_filter( 'automator_recipes_class_name', $callback, 10, 3 );
Description
Filters the resolved class name for external integration classes. Developers can modify this to use custom class names or namespaces when Automator loads integration code, ensuring proper class resolution.
Usage
add_filter( 'automator_recipes_class_name', 'your_function_name', 10, 3 );
Parameters
-
$class_name(mixed) - This parameter holds the dynamically generated class name for an integration.
-
$file(mixed) - This parameter contains the resolved class name, which can be modified by the filter.
-
$file_name(mixed) - This parameter contains the full path to the file being processed by the integration loader.
Return Value
The filtered value.
Examples
// Filter the fully qualified class name for an Automator recipe.
// This allows developers to modify the class name or add custom logic before it's used.
add_filter( 'automator_recipes_class_name', function( $class_name, $file, $file_name ) {
// Example: If the class name is 'My_Custom_Recipe' and it's from a specific file,
// prepend a custom namespace.
if ( 'my-custom-plugin/recipes/my-custom-recipe.php' === $file_name && 'My_Custom_Recipe' === $class_name ) {
return 'MyPluginAutomatorRecipes\' . $class_name;
}
// Example: If we want to rename a specific recipe class, we can do that here.
if ( 'Another_Recipe_To_Rename' === $class_name ) {
return 'Renamed_Automator_Recipe';
}
// Always return the potentially modified $class_name.
return $class_name;
}, 10, 3 );
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:83
src/core/integration-loader/class-class-resolver.php:87
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 );
}