Filter uncanny-automator

automator_integrations_class_name

Filters the class name for core integrations, allowing modification before it's used.

add_filter( 'automator_integrations_class_name', $callback, 10, 2 );

Description

Allows modification of the integration class name before it's loaded. This filter receives the generated class name, the integration's main file path, and the integration's directory name. Developers can alter the class name for custom integration loading or naming conventions.


Usage

add_filter( 'automator_integrations_class_name', 'your_function_name', 10, 2 );

Parameters

$this (mixed)
This parameter represents the instance of the `Set_Up_Automator` class that is currently processing the integration.
$file (mixed)
This parameter represents the current instance of the `Set_Up_Automator` class.

Return Value

The filtered value.


Examples

/**
 * Example of how to filter the integration class name.
 *
 * This callback demonstrates how to potentially modify the class name
 * for an integration. In this specific example, we'll add a prefix
 * to the class name if it's for a specific integration type.
 *
 * @param string $class_name The original class name generated by the plugin.
 * @param string $file         The path to the main integration file.
 *
 * @return string The modified or original class name.
 */
add_filter( 'automator_integrations_class_name', function( $class_name, $file ) {

	// Check if the file path indicates a specific integration type, e.g., 'my-custom-integration'.
	// This is a hypothetical check. In a real scenario, you'd likely have a more robust way
	// to identify the integration, perhaps by looking for a specific marker in the $file path
	// or by having access to the $dir_name from the outer scope if this callback were within a class.
	if ( strpos( $file, 'my-custom-integration' ) !== false ) {
		// Prepend a custom prefix to the class name for this specific integration.
		return 'MyCustomPrefix_' . $class_name;
	}

	// If it's not the specific integration we want to modify, return the original class name.
	return $class_name;

}, 10, 2 );

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/classes/class-set-up-automator.php:201
src/core/integration-loader/class-integration-registrar.php:84

$file = self::$all_integrations[ $dir_name ]['main'];

			if ( is_array( $file ) || ! file_exists( $file ) ) {
				continue;
			}

			$class = apply_filters( 'automator_integrations_class_name', $this->get_class_name( $file, false, $dir_name ), $file );

			// Use Utilities tracker, not class_exists — validate_namespace() may have
			// triggered the autoloader (via ReflectionClass), defining the class
			// without instantiating it.
			if ( false !== Utilities::get_class_instance( $class ) ) {
				continue;
			}


Scroll to Top