Action uncanny-automator

automator_before_classes_init

Classes. Fires just before the main Automator classes are initialized, allowing modifications before core functionality is loaded.

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

Description

Fires just before core Automator classes are initialized and loaded. Developers can use this action to add, remove, or modify class paths in the `$classes` array before they are instantiated, allowing for custom class loading or integration.


Usage

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

Examples

/**
 * Example of using the 'automator_before_classes_init' action hook.
 * This function will be executed just before the core Automator classes are initialized.
 * We can use this hook to register additional custom classes that should be loaded
 * by the Automator plugin, or to conditionally modify the list of classes to be loaded.
 */
add_action( 'automator_before_classes_init', 'my_custom_automator_classes', 10, 0 );

/**
 * Registers a custom class to be loaded by the Automator plugin.
 *
 * This example demonstrates how to add a new class definition to the $classes array
 * which is expected by the Automator plugin to load its core components.
 *
 * Note: This function assumes the $classes global variable is accessible or passed implicitly.
 * In a real-world scenario, if $classes isn't directly available, you might need to
 * interact with the Automator plugin's class in a different way, perhaps by accessing
 * a property of its instance if it's stored globally or passed via another hook.
 * For this example, we'll simulate accessing and modifying it as if it were globally
 * available or passed in a context where it can be manipulated.
 *
 * The Automator plugin's internal structure might evolve, so it's crucial to
 * consult its documentation or source code for the most accurate way to hook into
 * class initialization. This example is based on the provided context.
 */
function my_custom_automator_classes() {
	// In a real scenario, you'd check if the $classes variable is available.
	// For demonstration purposes, we'll assume it's accessible for modification.
	// If Automator provides a way to get and set the class definitions, use that.
	// Since the hook is 'before_classes_init', it's likely the $classes array
	// is still being prepared.

	// For demonstration, let's assume $classes is accessible.
	// In a live plugin, you might do something like this if the plugin
	// made its class loading array available in some way.
	// A more robust approach would be to see if Automator offers its own
	// filter hook to add classes *before* they are processed.

	// Let's simulate modifying a global variable for the sake of this example.
	// In a real situation, this would depend heavily on how Automator handles
	// class loading registration.
	global $automator_classes_to_load;

	if ( ! isset( $automator_classes_to_load ) ) {
		// If the global isn't set, perhaps it's passed through another mechanism
		// or we should try to get it from the Automator main instance if accessible.
		// For now, we'll create it if it doesn't exist to show adding a class.
		$automator_classes_to_load = array();
	}

	// Define the path to your custom Automator class.
	// Ensure this path is correct relative to your plugin's or theme's directory.
	// Replace 'my-custom-automator-class.php' with your actual file name.
	// Replace 'path/to/your/classes/' with the correct subdirectory structure.
	$my_custom_class_path = plugin_dir_path( __FILE__ ) . 'includes/automator/class-my-custom-automator-class.php';

	// Add your custom class to the array.
	// The key is the class name, and the value is the file path.
	// This assumes your custom class is named 'My_Custom_Automator_Class'.
	$automator_classes_to_load['My_Custom_Automator_Class'] = $my_custom_class_path;

	// You could also conditionally add classes based on certain criteria.
	// For example, if a specific feature is enabled:
	if ( defined( 'MY_AUTOMATOR_FEATURE_ENABLED' ) && MY_AUTOMATOR_FEATURE_ENABLED ) {
		$another_custom_class_path = plugin_dir_path( __FILE__ ) . 'includes/automator/class-another-custom-class.php';
		$automator_classes_to_load['Another_Custom_Automator_Class'] = $another_custom_class_path;
	}

	// Log a message to confirm the hook has fired and the class has been registered (for debugging).
	// In a production environment, you'd likely remove or disable such logs.
	error_log( 'automator_before_classes_init hook fired. Custom Automator classes registered.' );
}

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

public function admin_only_classes( $classes = array() ) {
		/**
		 * Admin.
		 */
		if ( ! self::$is_admin_sect && ! Automator()->helpers->recipe->is_automator_ajax() ) {
			return $classes;
		}

		do_action( 'automator_before_admin_init' );

		$classes['Admin_Menu']                     = UA_ABSPATH . 'src/core/admin/class-admin-menu.php';
		$classes['Prune_Logs']                     = UA_ABSPATH . 'src/core/admin/class-prune-logs.php';
		$classes['Admin_Logs']                     = UA_ABSPATH . 'src/core/admin/admin-logs/admin-logs.php';
		$classes['Admin_Tools']                    = UA_ABSPATH . 'src/core/admin/admin-tools/admin-tools.php';
		$classes['Admin_Settings']                 = UA_ABSPATH . 'src/core/admin/admin-settings/admin-settings.php';
		$classes['Pro_Upsell']                     = UA_ABSPATH . 'src/core/admin/pro-upgrade/class-pro-upsell.php';
		$classes['Addons']                         = UA_ABSPATH . 'src/core/admin/addons/class-addons.php';
		$classes['Automator_Review']               = UA_ABSPATH . 'src/core/admin/class-automator-review.php';
		$classes['Automator_Notifications']        = UA_ABSPATH . 'src/core/admin/notifications/notifications.php';
		$classes['Automator_Tooltip_Notification'] = UA_ABSPATH . 'src/core/admin/tooltip-notification/class-tooltip-notification.php';
		$classes['Automator_Tooltip_48hr']         = UA_ABSPATH . 'src/core/admin/tooltip-notification/tooltips/class-create-recipe-reminder.php';
		$classes['Admin_Template_Library']         = UA_ABSPATH . 'src/core/admin/class-admin-template-library.php';

		$classes['Api_Log'] = UA_ABSPATH . 'src/core/admin/api-log/class-api-log.php';

		$classes['Add_User_Recipe_Type'] = UA_ABSPATH . 'src/core/classes/class-add-user-recipe-type.php';
		if ( ! defined( 'AUTOMATOR_PRO_FILE' ) ) {
			$classes['Add_Anon_Recipe_Type'] = UA_ABSPATH . 'src/core/anon/class-add-anon-recipe-type.php';
		}
		do_action( 'automator_after_admin_init' );

		/**
		 * Automator Custom Post Types.
		 */
		//$classes = $this->custom_post_types_classes( $classes );

		/**
		 * Activity Stream / Logs.
		 */
		$classes = $this->activity_stream_classes( $classes );

		/**
		 * Classes.
		 */
		do_action( 'automator_before_classes_init' );

		$classes['Populate_From_Query'] = UA_ABSPATH . 'src/core/classes/class-populate-from-query.php';

		do_action( 'automator_after_classes_init' );

		return $classes;
	}


Scroll to Top