Action
uncanny-automator
automator_after_autoloader
Fires after the autoloader has been initialized, allowing for modifications or actions to be taken.
add_action( 'automator_after_autoloader', $callback, 10, 1 );
Description
Fires after Automator's autoloader has finished loading all necessary classes. Use this hook to perform actions that depend on Automator's core classes being available, such as registering custom post types or modifying plugin settings after initialization. It's crucial to note that this hook fires after initial class loading but before recipes are necessarily fully processed.
Usage
add_action( 'automator_after_autoloader', 'your_function_name', 10, 1 );
Examples
add_action( 'automator_after_autoloader', 'my_automator_post_autoloader_tasks', 10, 0 );
/**
* Example function to run tasks after the Automator autoloader has finished.
* This could be useful for registering custom post types, taxonomies, or
* performing other setup that relies on Automator's core classes being loaded.
*
* @since 1.0.0
*/
function my_automator_post_autoloader_tasks() {
// Example: Check if a specific Automator feature is enabled and perform an action.
// Replace 'automator_is_feature_enabled' with an actual function if available,
// or simulate a check based on your application's logic.
if ( function_exists( 'automator_is_feature_enabled' ) && automator_is_feature_enabled( 'advanced_logging' ) ) {
// Register a custom post type if advanced logging is enabled.
// This is a hypothetical example. In a real scenario, you'd have
// your CPT registration logic here.
if ( ! post_type_exists( 'automator_log_entry' ) ) {
register_post_type( 'automator_log_entry', array(
'labels' => array(
'name' => __( 'Automator Log Entries', 'your-text-domain' ),
'singular_name' => __( 'Automator Log Entry', 'your-text-domain' ),
),
'public' => false,
'show_ui' => true,
'supports' => array( 'title', 'editor', 'author', 'custom-fields' ),
'rewrite' => false,
) );
// You might also want to flush rewrite rules here if necessary,
// but be cautious about doing this on every load.
// flush_rewrite_rules();
}
}
// Example: Log a message to the WordPress debug log for verification.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
error_log( 'Automator autoloader has completed. Running custom post-autoloader tasks.' );
}
}
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:772
public function global_classes( $classes = array() ) {
/**
* Class autoloader.
*/
do_action( 'automator_before_autoloader' );
// Webhooks
$classes['Automator_Send_Webhook_Ajax_Handler'] = UA_ABSPATH . 'src/core/lib/webhooks/class-automator-send-webhook-ajax-handler.php';
$classes['Recipe_Post_Rest_Api'] = UA_ABSPATH . 'src/core/automator-post-types/uo-recipe/class-recipe-post-rest-api.php';
$classes['Background_Actions'] = UA_ABSPATH . 'src/core/classes/class-background-actions.php';
$classes['Calculation_Token'] = UA_ABSPATH . 'src/core/classes/class-calculation-token.php';
$classes['Copy_Recipe_Parts'] = UA_ABSPATH . 'src/core/admin/class-copy-recipe-parts.php';
$classes['Export_Recipe'] = UA_ABSPATH . 'src/core/admin/class-export-recipe.php';
$classes['Import_Recipe'] = UA_ABSPATH . 'src/core/admin/class-import-recipe.php';
$classes['Pricing_Plan_Resolver'] = UA_ABSPATH . 'src/core/admin/class-pricing-plan-resolver.php';
// Load migrations
$this->load_migrations();
// Load migrations that uses hooks.
$this->load_migrations_hooks();
// Only initialize classes if there're any active recipes OR if user is editing recipe
$classes = $this->maybe_initialize_automator( $classes );
do_action( 'automator_after_autoloader' );
return $classes;
}