Action
uncanny-automator
automator_before_traits
Fires before the Traits for Automator are loaded, allowing for pre-loading customizations.
add_action( 'automator_before_traits', $callback, 10, 1 );
Description
Fires before Automator loads all traits, abstract, and helper files. Developers can use this hook to perform actions such as adding custom configurations or modifying file loading paths before the core traits are made available. No parameters are passed.
Usage
add_action( 'automator_before_traits', 'your_function_name', 10, 1 );
Examples
add_action( 'automator_before_traits', 'my_automator_custom_trait_loading_logic', 10, 0 );
/**
* Example function to demonstrate hooking into automator_before_traits.
*
* This function might be used to pre-load specific helper classes or
* modify the environment before traits are loaded by the Automator plugin.
* For instance, you could register custom post types or taxonomies that
* your custom recipe parts might rely on.
*
* @return void
*/
function my_automator_custom_trait_loading_logic() {
// Imagine you have a custom trait file that needs to be available.
// While composer handles autoloading, you might want to ensure specific
// configurations or setups are done beforehand.
// Example: Register a custom meta box for recipe parts if needed.
// This is just a placeholder for illustrative purposes.
// In a real scenario, this logic would be more complex.
if ( class_exists( 'Automator_Recipe_Builder' ) ) {
// Add a hook to register custom meta boxes for recipe settings.
// This is a hypothetical example of what might be done here.
add_action( 'automator_recipe_builder_register_meta_boxes', 'my_automator_register_custom_meta_boxes' );
// You could also define constants or global variables here if your
// custom traits depend on them.
define( 'MY_CUSTOM_AUTOMATOR_SETTING', true );
}
// Log that our custom logic has run.
error_log( 'my_automator_custom_trait_loading_logic executed.' );
}
/**
* Hypothetical function to register custom meta boxes for Automator recipe parts.
* This would be called by the `automator_recipe_builder_register_meta_boxes` action.
*/
function my_automator_register_custom_meta_boxes() {
// Add your custom meta box registration code here.
// For example:
// add_meta_box(
// 'my_custom_recipe_settings',
// __( 'Custom Recipe Settings', 'your-textdomain' ),
// 'my_automator_render_custom_meta_box',
// 'automator_recipe', // Assuming 'automator_recipe' is the post type
// 'normal',
// 'default'
// );
error_log( 'my_automator_register_custom_meta_boxes called.' );
}
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/class-automator-load.php:864
public function load_traits() {
// All trait, abstract, and helper files under src/core/lib/recipe-parts/ and
// src/core/lib/settings/ are covered by the "classmap": ["src/"] entry in
// composer.json. Composer loads each file on first use — no require_once needed.
do_action( 'automator_before_traits' );
do_action( 'automator_after_traits' );
}