Filter uncanny-automator

automator_register_action

Filters the registered action before it is added, allowing for modification or conditional exclusion.

add_filter( 'automator_register_action', $callback, 10, 1 );

Description

Fires after an action's default parameters are prepared. Developers can modify the action's data, such as adding manifest information or customizing its default settings before it's registered with the Automator. This hook is crucial for extending or altering how actions behave by default.


Usage

add_filter( 'automator_register_action', 'your_function_name', 10, 1 );

Parameters

$action (mixed)
This parameter contains an array of data representing the action being registered.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to hook into 'automator_register_action' to modify an action's settings before registration.
 *
 * This example checks if the action has a 'settings' key and if it's an array.
 * If so, it adds a new default setting called 'user_role_restriction' and sets its value to 'subscriber'.
 * This could be useful for limiting which user roles can use a specific automation action.
 *
 * @param array $action The action data array being registered.
 * @return array The modified action data array.
 */
add_filter( 'automator_register_action', 'my_automator_modify_action_settings', 10, 1 );

function my_automator_modify_action_settings( $action ) {
	// Ensure $action is an array and has a 'settings' key that is also an array.
	if ( is_array( $action ) && isset( $action['settings'] ) && is_array( $action['settings'] ) ) {
		// Add a new setting to restrict actions to specific user roles.
		// This is just an example; the actual setting key and value would depend on your needs.
		$action['settings']['user_role_restriction'] = 'subscriber';
	}

	// Always return the action array, whether modified or not.
	return $action;
}
?>

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/lib/recipe-parts/actions/trait-action-setup.php:524
src/core/lib/recipe-parts/actions/abstract-action.php:237
src/core/lib/utilities/class-automator-registration.php:338

protected function register_action() {

		$action = array(
			'author'                        => $this->get_author(),
			'support_link'                  => $this->get_support_link(),
			'integration'                   => $this->get_integration(),
			'is_pro'                        => $this->is_is_pro(),
			'is_elite'                      => $this->is_is_elite(),
			'is_deprecated'                 => $this->is_is_deprecated(),
			'requires_user'                 => $this->get_requires_user(),
			'code'                          => $this->get_action_code(),
			'meta_code'                     => $this->get_action_meta(),
			'sentence'                      => $this->get_sentence(),
			'select_option_name'            => $this->get_readable_sentence(),
			'execution_function'            => array( $this, 'do_action' ),
			'background_processing'         => $this->get_background_processing(),
			'should_apply_extra_formatting' => $this->get_should_apply_extra_formatting(),
			'loopable_tokens'               => $this->get_loopable_tokens(),
		);

		$agent = $this->get_agent_class( $this->get_action_code() );

		if ( ! is_null( $agent ) ) {
			$action['agent_class'] = $agent;
		}

		if ( ! empty( $this->get_options() ) ) {
			$action['options'] = $this->get_options();
		}

		if ( ! empty( $this->get_options_group() ) ) {
			$action['options_group'] = $this->get_options_group();
		}

		if ( ! empty( $this->get_options_callback() ) ) {
			$action['options_callback'] = $this->get_options_callback();
		}

		if ( ! empty( $this->get_buttons() ) ) {
			$action['buttons'] = $this->get_buttons();
		}

		// Extract manifest data if trait is used
		if ( $this->uses_item_manifest_trait() && is_callable( array( $this, 'extract_item_manifest_data' ) ) ) {
			$manifest = call_user_func( array( $this, 'extract_item_manifest_data' ) );
			if ( ! empty( $manifest ) ) {
				$action['manifest'] = $manifest;
			}
		}

		$action = apply_filters( 'automator_register_action', $action );

		Automator()->register->action( $action );
	}


Scroll to Top