Filter uncanny-automator

automator_integration_files

Filters the list of files used by the core integration, allowing modification of gated files and directory names.

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

Description

Filters the list of files recognized as integration files for a specific directory name. Developers can use this to add or remove files from the integration list, allowing for custom integration file detection.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Example of how to filter the 'automator_integration_files' hook.
 *
 * This function demonstrates how to add, remove, or modify the list of integration files
 * that the Automator plugin scans. In this example, we'll add a custom file type
 * and remove another based on specific conditions.
 *
 * @param array  $gated_files An array of integration file paths or identifiers.
 * @param string $dir_name    The directory name where integration files are being searched.
 *
 * @return array The modified array of integration files.
 */
add_filter(
	'automator_integration_files',
	function ( $gated_files, $dir_name ) {
		// Assume we are looking for files in a specific integration directory.
		// For demonstration, let's say the $dir_name is 'my-custom-integration'.
		if ( 'my-custom-integration' === $dir_name ) {

			// Add a new custom integration file.
			// This could be a path to a file or a unique identifier for an integration.
			$gated_files[] = 'my-custom-integration/includes/new-feature-integration.php';

			// Remove a specific integration file if it exists.
			// For instance, we might want to disable an older integration temporarily.
			$key_to_remove = array_search( 'my-custom-integration/includes/legacy-feature.php', $gated_files );
			if ( false !== $key_to_remove ) {
				unset( $gated_files[ $key_to_remove ] );
			}

			// Re-index the array after unsetting to avoid issues with subsequent loops.
			$gated_files = array_values( $gated_files );
		}

		// Always return the modified (or original) array of gated files.
		return $gated_files;
	},
	10, // Priority: The order in which this filter runs. Lower numbers run earlier.
	2   // Accepted args: The number of arguments this filter callback accepts.
);

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/integration-loader/class-recipe-part-loader.php:228

private function load_gated_files( $dir_name, $object, $directories_to_include, $manifest, $load_all ) {

		// Gated types exclude helpers/tokens — those always load for active integrations.
		// To add a new gated type, update automator_get_gated_directory_types() in global-functions.php.
		$gated_types = automator_get_gated_directory_types();
		$gated_files = array();

		foreach ( $gated_types as $type ) {
			$gated_files = array_merge( $gated_files, $this->get_files_for_type( $dir_name, $type, $directories_to_include ) );
		}

		$gated_files = apply_filters( 'automator_integration_files', $gated_files, $dir_name );

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

		$integration_code = self::get_integration_code( $object );

		foreach ( $gated_files as $file ) {
			$this->load_single_gated_file( $file, $dir_name, $integration_code, $manifest, $load_all );
		}
	}

Scroll to Top