Filter uncanny-automator

automator_integration_icon_path_legacy

Filters the legacy file path for integration icons.

add_filter( 'automator_integration_icon_path_legacy', $callback, 10, 3 );

Description

Allows modification of the legacy icon path for integrations. Developers can alter the default path to integration icons, useful for custom integration structures or for providing alternative icon locations. Use with caution as it affects how integration icons are loaded.


Usage

add_filter( 'automator_integration_icon_path_legacy', 'your_function_name', 10, 3 );

Parameters

$file_name (mixed)
This parameter represents the name of the icon file, potentially including its path.
$file_name (mixed)
This parameter is expected to be the name of the icon file for an integration, including its extension.
$plugin_path (mixed)
This parameter is the name of the icon file that needs to be retrieved.

Return Value

The filtered value.


Examples

/**
 * Example of how to filter the legacy icon path for an integration.
 *
 * This example demonstrates how to intercept the default icon path and
 * provide a custom path, perhaps pointing to an icon within a different
 * directory structure or a CDN.
 *
 * @param string $file_name The original file name of the integration icon.
 * @param string $original_file_name The original file name of the integration icon (passed again).
 * @param string $plugin_path The path to the plugin directory.
 *
 * @return string The modified or custom path to the integration icon.
 */
add_filter( 'automator_integration_icon_path_legacy', function( $file_name, $original_file_name, $plugin_path ) {
	// In this example, we'll assume a specific integration named 'my-custom-integration'
	// needs its icon served from a different directory.
	if ( strpos( $original_file_name, 'my-custom-integration' ) !== false ) {
		// Prepend a custom directory to the default path.
		// This could be useful if your integration's assets are organized differently.
		return 'assets/icons/integrations/' . $original_file_name;
	}

	// If it's not our custom integration, return the original file name
	// which will be used to construct the default path by the core function.
	return $original_file_name;
}, 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/class-utilities.php:227

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