Filter
uncanny-automator
automator_integration_folders
Filters the list of integration folders available for Automator, allowing modification before they are loaded.
add_filter( 'automator_integration_folders', $callback, 10, 3 );
Description
Filters the list of integration folder paths before they are returned. Developers can use this to dynamically add, remove, or modify integration folder locations. This hook fires after initial integration discovery, allowing for custom path manipulation.
Usage
add_filter( 'automator_integration_folders', 'your_function_name', 10, 3 );
Parameters
-
$folders(mixed) - This parameter is an array that will hold the discovered integration folder paths.
-
$integrations(mixed) - This parameter contains an array of integration folders that will be returned.
-
$directory(mixed) - This parameter contains an array of integration definitions, used to determine which integrations are being loaded and how they are structured.
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the 'automator_integration_folders' filter hook.
* This example demonstrates how to add a custom folder to be scanned for integrations,
* ensuring it's a valid directory and doesn't already exist in the list.
*
* @param array $folders The array of integration folder paths.
* @param array $integrations An array of integration data.
* @param string $directory The base directory for integrations.
*
* @return array The modified array of integration folder paths.
*/
function my_custom_automator_integration_folders( $folders, $integrations, $directory ) {
// Define a custom integration folder path.
$custom_folder_path = WP_PLUGIN_DIR . '/my-custom-automator-integrations';
// Check if the custom folder exists and is a directory.
if ( is_dir( $custom_folder_path ) ) {
// Check if this custom folder is already in the list to avoid duplicates.
if ( ! in_array( $custom_folder_path, $folders ) ) {
$folders[] = $custom_folder_path;
}
}
// You could also filter the existing folders if needed.
// For example, to remove a specific folder:
// $folders = array_filter( $folders, function( $folder ) {
// return $folder !== '/path/to/exclude';
// } );
return $folders;
}
add_filter( 'automator_integration_folders', 'my_custom_automator_integration_folders', 10, 3 );
?>
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-integration-discovery.php:225
public static function extract_integration_folders( $integrations, $directory ) {
$folders = array();
if ( empty( $integrations ) ) {
return $folders;
}
foreach ( $integrations as $f => $integration ) {
$path = isset( $integration['main'] ) ? dirname( $integration['main'] ) : $directory . DIRECTORY_SEPARATOR . $f;
$path = apply_filters( 'automator_integration_folder_paths', $path, $integration, $directory, $f );
$folders[] = $path;
}
return apply_filters( 'automator_integration_folders', $folders, $integrations, $directory );
}