Action uncanny-automator

automator_after_init

Fires after the Automator core initialization is complete, allowing for post-initialization custom actions.

add_action( 'automator_after_init', $callback, 10, 1 );

Description

Fires after the core Automator classes have been initialized and instantiated. Developers can use this hook to perform actions that depend on the availability of all core Automator functionalities, such as setting up custom integrations or performing initial data configurations.


Usage

add_action( 'automator_after_init', 'your_function_name', 10, 1 );

Examples

add_action( 'automator_after_init', 'my_automator_custom_logic', 10, 0 );

/**
 * Example function to hook into automator_after_init.
 * This function will run after the core Automator classes have been initialized.
 * It could be used to perform custom configurations, register custom actions/triggers,
 * or perform any other setup that depends on Automator's core being ready.
 */
function my_automator_custom_logic() {
	// Example: Check if a specific Automator feature is enabled and if so,
	// load additional resources or modify its behavior.
	if ( class_exists( 'Automator_Modules_Manager' ) ) {
		$modules_manager = Automator()->get_module_manager();

		// Hypothetical: If a 'custom_reporting' module is enabled,
		// perform some setup.
		if ( $modules_manager->is_module_active( 'custom_reporting' ) ) {
			// Enqueue a custom JavaScript file for the reporting interface.
			wp_enqueue_script(
				'my-automator-reporting-script',
				plugins_url( 'assets/js/reporting-customizations.js', __FILE__ ),
				array( 'jquery', 'automator-admin-js' ), // Dependencies
				filemtime( plugin_dir_path( __FILE__ ) . 'assets/js/reporting-customizations.js' ),
				true // Load in footer
			);

			// Add a custom filter to modify the data before it's displayed in a report.
			// Note: This assumes there's a filter hook available within the custom reporting module,
			// which would need to be defined by the Automator plugin itself.
			// For demonstration purposes, we'll use a placeholder filter name.
			add_filter( 'automator_custom_reporting_data', 'my_modify_reporting_data_filter', 10, 1 );
		}
	}

	// Example: Register a custom automation trigger if a specific plugin is active.
	if ( class_exists( 'My_Custom_Plugin' ) && class_exists( 'Automator_Triggers_Registry' ) ) {
		Automator()->get_triggers_registry()->register_trigger( 'my_custom_plugin_event_trigger' );
	}
}

/**
 * Placeholder function for a hypothetical filter.
 * This would be used to modify data returned by a custom reporting module.
 *
 * @param array $data The data to be filtered.
 * @return array The modified data.
 */
function my_modify_reporting_data_filter( $data ) {
	// Example: Add a new key-value pair to the data array.
	$data['processed_timestamp'] = current_time( 'mysql' );

	// Example: Modify an existing value.
	if ( isset( $data['user_count'] ) ) {
		$data['user_count'] = (int) $data['user_count'] + 100; // Add 100 to the user count
	}

	return $data;
}

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:589

public function initialize_core_automator() {
		do_action( 'automator_before_init' );

		$classes = apply_filters( 'automator_core_files', array() );

		if ( empty( $classes ) ) {
			return;
		}

		// only load if it's admin
		$this->load_traits();

		foreach ( $classes as $class_name => $file ) {
			if ( ! is_file( $file ) ) {
				continue;
			}
			require_once $file;
			$class                                 = __NAMESPACE__ . '\' . $class_name;
			self::$core_class_inits[ $class_name ] = new $class();
		}

		do_action( 'automator_after_init' );
	}


Scroll to Top