Filter
uncanny-automator
automator_integration_folder_paths
Filters the folder paths used by Automator integrations, allowing customization of integration directory locations.
add_filter( 'automator_integration_folder_paths', $callback, 10, 4 );
Description
Allows developers to modify the discovered integration folder paths. This filter is applied for each integration found, providing the current path, integration details, base directory, and integration key. Developers can use this to alter default paths or add custom locations for integration files.
Usage
add_filter( 'automator_integration_folder_paths', 'your_function_name', 10, 4 );
Parameters
-
$path(mixed) - This parameter contains the path to the main file of the integration, which is used to determine the integration's folder.
-
$integration(mixed) - This parameter holds the calculated file path for an integration, derived from the integration's main file or the base directory.
-
$directory(mixed) - This parameter contains information about the specific integration being processed in the current loop.
-
$f(mixed) - This parameter represents the root directory where the integration is being searched for.
Return Value
The filtered value.
Examples
/**
* Example: Exclude a specific integration folder from being loaded.
*
* This filter allows developers to programmatically exclude certain integration
* folders from being discovered and loaded by the Automator plugin.
*
* @param string $path The current integration folder path.
* @param array $integration An array containing integration details.
* @param string $directory The base directory for integrations.
* @param string $f The integration key or slug.
*
* @return string The modified integration folder path.
*/
add_filter( 'automator_integration_folder_paths', function( $path, $integration, $directory, $f ) {
// Example: Prevent loading of an integration with the key 'my-excluded-integration'.
if ( 'my-excluded-integration' === $f ) {
// By returning an empty string or null, the integration will effectively be skipped.
// Returning an empty string is often safer as it won't cause errors if
// the subsequent code expects a string.
return '';
}
// If not the excluded integration, return the original path.
return $path;
}, 10, 4 );
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:221
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 );
}