Action
uncanny-automator
automator_after_add_integrations
Fires after new integrations are added to the Automator core, allowing for custom post-addition actions.
add_action( 'automator_after_add_integrations', $callback, 10, 1 );
Description
Fires after all integrations have been processed and their directories are merged. Developers can use this hook to perform custom actions, manipulate the merged integration directories, or add their own integration logic before the automator is fully initialized.
Usage
add_action( 'automator_after_add_integrations', 'your_function_name', 10, 1 );
Parameters
-
$this(mixed) - This parameter represents the current instance of the Automator initialization class.
Examples
<?php
/**
* Example function to process integration data after they are added.
*
* This function demonstrates how to hook into the 'automator_after_add_integrations'
* action to perform custom logic after integrations have been loaded and potentially
* merged. It receives the '$this' object, which likely represents an instance
* of the Automator core class.
*
* @param object $automator_instance The instance of the Automator core class.
*/
function my_automator_process_integrations( $automator_instance ) {
// Check if the provided instance is of the expected type (e.g., Automator_Initialize class)
// This is a hypothetical check, adjust if you know the exact class name.
if ( ! is_a( $automator_instance, 'Automator_Initialize' ) ) {
error_log( 'my_automator_process_integrations: Invalid instance type received.' );
return;
}
// Access properties or methods of the $automator_instance if needed.
// For example, if $automator_instance has a property like 'active_directories'.
if ( property_exists( $automator_instance, 'active_directories' ) && is_array( $automator_instance->active_directories ) ) {
// Perform some custom action based on the loaded integrations.
// This could involve logging, setting up specific caches, or enabling/disabling features
// based on the available integrations.
$integration_count = count( $automator_instance->active_directories );
if ( $integration_count > 0 ) {
error_log( sprintf( 'Uncanny Automator: %d integrations are active after loading.', $integration_count ) );
// Example: If a specific integration is found, perform an action.
foreach ( $automator_instance->active_directories as $integration_slug => $integration_data ) {
if ( 'my-custom-integration' === $integration_slug ) {
error_log( 'My Custom Integration found. Performing specific setup.' );
// Call a hypothetical setup function for this integration.
// my_custom_integration_setup();
break; // Exit loop if the specific integration is found and handled.
}
}
} else {
error_log( 'Uncanny Automator: No integrations are active after loading.' );
}
} else {
error_log( 'my_automator_process_integrations: Could not access or verify active_directories property.' );
}
// No return value is needed for an action hook.
}
// Hook the custom function to the 'automator_after_add_integrations' action.
// We are passing the $this object, which is the first parameter to our function.
// Priority 20 is used to ensure it runs after core Automator functions that might
// also hook into this action. Accepted arguments: 1 (for $this).
add_action( 'automator_after_add_integrations', 'my_automator_process_integrations', 20, 1 );
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/classes/class-initialize-automator.php:162
public function automator_configuration_complete_func() {
//Let others hook in and add integrations
do_action_deprecated( 'uncanny_automator_add_integration', array(), '3.0', 'automator_add_integration' );
do_action( 'automator_add_integration' );
// Pro/addons may have hooked automator_item_map during automator_add_integration.
// Invalidate the early-cached item map so load_recipe_parts() picks up the merged map.
Recipe_Manifest::get_instance()->invalidate_item_map();
// Phase 3: Register legacy integrations.
try {
$this->initialize_add_integrations();
} catch ( Error $e ) {
throw new Automator_Error( esc_html( $e->getMessage() ) );
} catch ( Exception $e ) {
throw new Automator_Exception( esc_html( $e->getMessage() ) );
}
// Pro hooks here to merge its data into active_directories and directories_to_include.
do_action( 'automator_after_add_integrations', $this );
//Let others hook in to the directories and add their integration's actions / triggers etc
self::$auto_loaded_directories = apply_filters_deprecated( 'uncanny_automator_integration_directory', array( self::$auto_loaded_directories ), '3.0', 'automator_integration_directory' );
self::$auto_loaded_directories = apply_filters( 'automator_integration_directory', self::$auto_loaded_directories );
//Let others hook in and add integrations
do_action_deprecated( 'uncanny_automator_add_recipe_type', array(), '3.0', 'automator_add_recipe_type' );
do_action( 'automator_add_recipe_type' );
// Phase 4: Load helpers.
$this->load_helpers();
// Phase 5: Load recipe parts (triggers, actions, closures, conditions, loop-filters, tokens).
// Deferred to a later init priority for 6.7 translation fix with trigger engine.
add_action( 'init', array( $this, 'load_recipe_parts' ), AUTOMATOR_RECIPE_PARTS_PRIORITY_TRIGGER_ENGINE );
}
Internal Usage
Found in uncanny-automator-pro/src/core/includes/internal-triggers-actions.php:96:
add_action( 'automator_after_add_integrations', array( $this, 'finalize_directory_merge' ), 11 );