Action
uncanny-automator
automator_before_automator_post_types_init
Fires just before Automator custom post types are initialized, allowing for modifications.
add_action( 'automator_before_automator_post_types_init', $callback, 10, 1 );
Description
Fires before Automator's core post types are initialized. Developers can use this hook to add or modify post type registrations, potentially influencing how recipes and other Automator content are handled before they are fully set up.
Usage
add_action( 'automator_before_automator_post_types_init', 'your_function_name', 10, 1 );
Examples
// Example of hooking into 'automator_before_automator_post_types_init' to conditionally load a custom post type.
// This hook fires before the core Automator post types are initialized, allowing us to modify the list of classes to be loaded.
add_action( 'automator_before_automator_post_types_init', 'my_custom_automator_post_types', 10, 1 );
/**
* Adds a custom post type class to the Automator post types array if a specific condition is met.
*
* @param array $classes An array of post type classes to be loaded by Automator.
* @return array The modified array of post type classes.
*/
function my_custom_automator_post_types( $classes ) {
// Let's imagine we only want to load our custom 'External_Integration_Post_Type'
// if a specific plugin is active.
if ( defined( 'MY_EXTERNAL_PLUGIN_ACTIVE' ) && MY_EXTERNAL_PLUGIN_ACTIVE ) {
// Ensure the path to our custom post type class is correctly defined.
// Replace 'path/to/your/custom/post-type/class-external-integration-post-type.php'
// with the actual path relative to your plugin's root directory or theme's root directory.
$custom_post_type_path = plugin_dir_path( __FILE__ ) . 'custom-automator-post-types/class-external-integration-post-type.php';
// Add our custom post type class to the array.
// The key is the class name, and the value is the file path.
$classes['External_Integration_Post_Type'] = $custom_post_type_path;
}
// Always return the potentially modified array of classes.
return $classes;
}
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:694
public function custom_post_types_classes( $classes = array() ) {
do_action( 'automator_before_automator_post_types_init' );
$classes['Recipe_Post_Type'] = UA_ABSPATH . 'src/core/automator-post-types/uo-recipe/class-recipe-post-type.php';
$classes['Recipe_Post_Metabox'] = UA_ABSPATH . 'src/core/automator-post-types/uo-recipe/class-recipe-post-metabox.php';
$classes['Recipe_Post_Utilities'] = UA_ABSPATH . 'src/core/automator-post-types/uo-recipe/class-recipe-post-utilities.php';
$classes['Triggers_Post_Type'] = UA_ABSPATH . 'src/core/automator-post-types/uo-trigger/class-triggers-post-type.php';
$classes['Actions_Post_Type'] = UA_ABSPATH . 'src/core/automator-post-types/uo-action/class-actions-post-type.php';
$classes['Closures_Post_Type'] = UA_ABSPATH . 'src/core/automator-post-types/uo-closure/class-closures-post-type.php';
$classes['Automator_Taxonomies'] = UA_ABSPATH . 'src/core/automator-post-types/uo-taxonomies/class-automator-taxonomies.php';
do_action( 'automator_after_automator_post_types_init' );
return $classes;
}