Filter
uncanny-automator-pro
automator_pro_recipes_class_name
Filters the class name used for Automator recipes before they are loaded, allowing for custom modifications.
add_filter( 'automator_pro_recipes_class_name', $callback, 10, 3 );
Description
Filters the fully qualified class name used for Automator Pro recipes. Developers can modify the class name before it's used to load recipe components, allowing for custom class naming conventions or alternative loading strategies. The original file and file name are provided for context.
Usage
add_filter( 'automator_pro_recipes_class_name', 'your_function_name', 10, 3 );
Parameters
-
$class(mixed) - This parameter represents the calculated class name derived from the file name.
-
$file(mixed) - This parameter contains the fully qualified class name that will be used for the automator recipe item.
-
$file_name(mixed) - This parameter contains the file path for the recipe.
Return Value
The filtered value.
Examples
/**
* Modify the Automator Pro recipe class name.
*
* This example demonstrates how to prepend a custom prefix to the generated
* Automator Pro recipe class name. This could be useful for organizing custom
* recipe classes within your own plugin or theme.
*
* @param string $class The original class name, including the namespace.
* @param string $file The full path to the file containing the recipe.
* @param string $file_name The filename without the extension.
* @return string The modified class name.
*/
add_filter( 'automator_pro_recipes_class_name', function( $class, $file, $file_name ) {
// Define your custom prefix.
$custom_prefix = 'MyCustomPlugin_';
// Get the base class name without the namespace.
$base_class_name = substr( $class, strrpos( $class, '\' ) + 1 );
// Prepend the custom prefix to the base class name.
$modified_base_class_name = $custom_prefix . $base_class_name;
// Reconstruct the full class name with the namespace.
$modified_class = substr( $class, 0, strrpos( $class, '\' ) + 1 ) . $modified_base_class_name;
// You could also perform conditional logic based on $file or $file_name.
// For example:
// if ( str_contains( $file_name, 'my_specific_recipe' ) ) {
// return __NAMESPACE__ . '\' . $custom_prefix . $base_class_name;
// }
return $modified_class;
}, 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
uncanny-automator-pro/src/core/includes/internal-triggers-actions.php:357
public function get_class_name( $file, $uppercase = false ) {
// Remove file extension my-class-name.php to my-class-name
$file_name = basename( $file, '.php' );
// Implode array into class name - eg. array( 'My', 'Class', 'Name') to My_Class_Name
$class_name = Set_Up_Automator::file_name_to_class( $file_name );
if ( $uppercase ) {
$class_name = strtoupper( $class_name );
}
$class = __NAMESPACE__ . '\' . $class_name;
return apply_filters( 'automator_pro_recipes_class_name', $class, $file, $file_name );
}