Filter uncanny-automator

automator_integration_icon_base_path

Filters the base path used for integration icons, allowing customization of icon locations.

add_filter( 'automator_integration_icon_base_path', $callback, 10, 4 );

Description

Filters the base path for integration icons. Developers can use this hook to modify the icon's directory or file path before it's rendered, allowing for custom icon locations or dynamic path adjustments. The hook provides the icon filename, the integration directory name, and the calculated plugin path.


Usage

add_filter( 'automator_integration_icon_base_path', 'your_function_name', 10, 4 );

Parameters

$plugin_path (mixed)
This parameter holds the path to the main plugin file.
$path (mixed)
This parameter represents the base file path of the plugin.
$icon (mixed)
This parameter is used to define the base path where the integration icons are located.
$integration_dir (mixed)
This parameter holds the name of the icon file with its extension.

Return Value

The filtered value.


Examples

/**
 * Example of filtering the automator_integration_icon_base_path hook.
 *
 * This example demonstrates how to prepend a custom directory to the base path
 * for integration icons, for example, if you're serving icons from a CDN or
 * a different subdirectory within your plugin.
 *
 * @param mixed $plugin_path      The original plugin path.
 * @param mixed $path             The relative path to the icon.
 * @param mixed $icon             The icon filename.
 * @param mixed $integration_dir The directory name of the integration.
 *
 * @return string The modified base path.
 */
add_filter( 'automator_integration_icon_base_path', function( $plugin_path, $path, $icon, $integration_dir ) {
	// Define a custom base URL or directory prefix.
	$custom_base_prefix = 'https://my-cdn.com/assets/automator-icons/';

	// Prepend the custom prefix to the original plugin path.
	// In a real-world scenario, you might construct a full URL here,
	// or just modify the path to point to a specific subdirectory.
	$modified_base_path = $custom_base_prefix . $integration_dir . '/';

	// Return the modified base path.
	return $modified_base_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/class-utilities.php:220

public static function automator_get_integration_icon( $file_name, $plugin_path = AUTOMATOR_BASE_FILE ) {
		/**
		 * Integration icons are now moved in to integrations itself
		 *
		 * @since 3.0
		 */
		if ( ! empty( $file_name ) && is_dir( dirname( $file_name ) ) ) {
			$icon            = basename( $file_name ); // icon with extension.
			$integration_dir = basename( dirname( $file_name ) ); // integration folder path.
			$path            = self::cleanup_icon_path( $plugin_path, $icon, $file_name ); // path relative to plugin.
			$path            = apply_filters( 'automator_integration_icon_path', $path . $icon, $icon, $integration_dir, $plugin_path );
			$base_path       = apply_filters( 'automator_integration_icon_base_path', $plugin_path, $path, $icon, $integration_dir );
			if ( ! empty( $path ) && ! empty( $base_path ) ) {
				return plugins_url( $path, $base_path );
			}
		}

		// fallback
		$path      = apply_filters( 'automator_integration_icon_path_legacy', 'src/recipe-ui/dist/media/integrations/' . $file_name, $file_name, $plugin_path );
		$base_path = apply_filters( 'automator_integration_icon_base_path_legacy', WP_CONTENT_DIR . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $plugin_path, $file_name );

		if ( ! empty( $path ) && ! empty( $base_path ) ) {
			return plugins_url( $path, $base_path );
		}

		return '';
	}


Scroll to Top