Filter uncanny-automator

automator_core_files

Filters the array of core files used by the automator, allowing modification before they are loaded.

add_filter( 'automator_core_files', $callback, 10, 1 );

Description

Filters the array of core Automator classes to be loaded. Developers can use this hook to add or remove classes from the core loading process, for example, to conditionally load specific functionalities or integrate custom components. Ensure the array contains valid class names that extend Automator's base classes.


Usage

add_filter( 'automator_core_files', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

/**
 * Registers additional core automator classes that are only needed on the frontend.
 *
 * This function will add a new class to the list of core automator files
 * that are loaded by the plugin. This specific class is intended for
 * frontend-only functionality.
 *
 * @param array $core_files The current array of core automator classes to load.
 * @return array The modified array of core automator classes, including the new frontend class.
 */
add_filter( 'automator_core_files', 'my_automator_frontend_classes', 10, 1 );
function my_automator_frontend_classes( $core_files ) {
    // Assume MyAutomatorFrontend is a class that extends a base Automator class or implements an interface.
    // Its file path would typically be within your plugin's structure.
    // For demonstration, let's represent it as a string. In a real scenario,
    // this might be a class name that the plugin's autoloader can find, or a file path.
    $frontend_class = 'My_PluginAutomatorFrontendFrontend_Manager';

    // Add the new class to the array.
    // In a real plugin, the 'automator_core_files' filter might expect class names
    // that the plugin's autoloader can resolve, or perhaps file paths to include.
    // We'll assume class names for this example.
    $core_files[] = $frontend_class;

    return $core_files;
}

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

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' );
	}


Internal Usage

Found in src/class-automator-load.php:84:

add_filter( 'automator_core_files', array( $this, 'global_classes' ) );

Found in src/class-automator-load.php:87:

add_filter( 'automator_core_files', array( $this, 'admin_only_classes' ) );

Found in src/class-automator-load.php:90:

add_filter( 'automator_core_files', array( $this, 'custom_post_types_classes' ) );

Found in src/class-automator-load.php:93:

add_filter( 'automator_core_files', array( $this, 'gutenberg_block_classes' ) );
Scroll to Top