Action uncanny-automator

automator_before_admin_init

Fires after core initialization but before the WordPress admin interface is fully set up.

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

Description

Fires before the Uncanny Automator admin area is initialized. Developers can use this hook to enqueue scripts, add admin notices, or perform other setup tasks before the core admin classes are loaded. This hook is ideal for customizations that need to run early in the admin loading process.


Usage

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

Examples

add_action( 'automator_before_admin_init', 'my_automator_admin_setup', 10 );

/**
 * My custom logic to run before WordPress Automator initializes its admin area.
 * This could be used for setting up custom admin pages, enqueueing scripts,
 * or modifying admin behavior based on specific conditions.
 *
 * @param array $classes An array of classes that will be loaded by Automator for the admin area.
 */
function my_automator_admin_setup( $classes ) {
    // Example: Conditionally enqueue a custom admin script only if a specific post type is being edited.
    if ( isset( $_GET['post_type'] ) && 'my_custom_post_type' === $_GET['post_type'] ) {
        wp_enqueue_script(
            'my-automator-custom-admin-script',
            plugins_url( 'assets/js/my-custom-admin.js', __FILE__ ),
            array( 'jquery', 'automator-admin-scripts' ), // Depend on Automator's admin scripts
            filemtime( plugin_dir_path( __FILE__ ) . 'assets/js/my-custom-admin.js' )
        );
    }

    // Example: Add a custom class to the admin menu for further styling or manipulation.
    // Note: This hook doesn't directly provide the menu object, so this is a hypothetical example
    // of what you *might* do if the hook passed relevant data or if you accessed global objects.
    // In a real scenario, you'd likely use other hooks like 'admin_menu'.
    // For demonstration, let's pretend we're adding a custom menu item.
    // This part might be more suited for the 'admin_menu' hook.
    // However, if 'automator_before_admin_init' has access to the $classes array and we
    // want to modify what Automator loads, we can.

    // Example: Prevent a specific Automator admin screen from loading under certain conditions.
    if ( defined( 'AUTOMATOR_IS_DEBUG_MODE' ) && AUTOMATOR_IS_DEBUG_MODE && isset( $classes['Admin_Logs'] ) ) {
        unset( $classes['Admin_Logs'] ); // Don't load the Admin_Logs class if debug mode is on and logs are not needed.
    }

    // If this were a filter hook, you would return the modified $classes array.
    // For an action hook, we modify directly or trigger other actions.
    // Since automator_before_admin_init is an action hook, we don't 'return' $classes
    // in the same way a filter would. The source code shows it's modifying $classes
    // and then 'do_action' is called. If this were a filter hook, it would expect
    // a return value.
}

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

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