Filter uncanny-automator

automator_item_requirement_meta

Filters the requirement met status and triggers for an automator item before it is saved.

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

Description

Filters the meta data used to determine if a trigger's requirements are met. Developers can modify the `$requirement_met` data to customize trigger logic or add custom requirement checks. This filter fires after the initial requirement check but before the trigger is registered.


Usage

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

Parameters

$requirement_met (mixed)
This parameter indicates whether the trigger's requirements have been met.
$triggers (mixed)
This parameter indicates whether the trigger's requirements have been met.

Return Value

The filtered value.


Examples

/**
 * Example of how to modify the requirement met status for a trigger.
 *
 * In this example, we'll check if the `$triggers` array contains a specific
 * trigger slug, and if so, we'll artificially set `$requirement_met` to false,
 * preventing that trigger from being registered.
 */
add_filter( 'automator_item_requirement_meta', function( $requirement_met, $triggers ) {

	// Ensure $triggers is an array before proceeding.
	if ( ! is_array( $triggers ) ) {
		return $requirement_met;
	}

	// Iterate through the registered triggers to find a specific one.
	foreach ( $triggers as $trigger_slug => $trigger_data ) {
		// Let's say we want to prevent a trigger with the slug 'my_custom_trigger'
		// from being registered if it meets its requirements.
		if ( 'my_custom_trigger' === $trigger_slug ) {
			// For demonstration, we'll force this trigger to not meet requirements.
			// In a real-world scenario, you might have more complex logic here
			// based on the trigger data itself or other global conditions.
			return false;
		}
	}

	// If we haven't returned false yet, it means our specific trigger
	// wasn't found, or we don't need to modify the requirement status,
	// so we return the original value.
	return $requirement_met;

}, 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/lib/recipe-parts/triggers/abstract-trigger.php:226

public function register_trigger( $triggers ) {

		$requirement_met = $this->requirements_met();
		$requirement_met = apply_filters( 'automator_item_requirement_meta', $requirement_met, $triggers );
		if ( ! $requirement_met ) {
			return $triggers;
		}

		$trigger = array(
			'author'              => $this->get_author(), // author of the trigger.
			'support_link'        => $this->get_support_link(), // hyperlink to support page.
			'type'                => $this->get_trigger_type(), // user|anonymous. user by default.
			'is_pro'              => $this->get_is_pro(), // free or pro trigger.
			'is_elite'            => $this->get_is_elite(), // elite trigger.
			'is_deprecated'       => $this->get_is_deprecated(), // whether trigger is deprecated.
			'integration'         => $this->get_integration(), // trigger the integration belongs to.
			'code'                => $this->get_code(), // unique trigger code.
			'meta_code'           => $this->get_trigger_meta(), // primary meta field code.
			'sentence'            => $this->get_sentence(), // sentence to show in active state.
			'select_option_name'  => $this->get_readable_sentence(), // sentence to show in non-active state.
			'action'              => $this->get_action(), //  trigger fire at this do_action().
			'priority'            => $this->get_action_priority(), // priority of the add_action().
			'accepted_args'       => $this->get_action_args_count(), // accepted args by the add_action().
			'token_parser'        => $this->get_token_parser(), // v3.0, Pass a function to parse tokens.
			'validation_function' => array( $this, 'validate_hook' ), // function to call for add_action().
			'uses_api'            => $this->get_uses_api(),
			'options_callback'    => array( $this, 'load_options' ),
			'loopable_tokens'     => $this->get_loopable_tokens(), //@since 5.10
		);

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

		if ( ! empty( $this->get_inline_css() ) ) {
			$trigger['inline_css'] = $this->get_inline_css();
		}

		if ( null !== $this->get_can_log_in_new_user() ) {
			$trigger['can_log_in_new_user'] = $this->get_can_log_in_new_user();
		}

		// 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 ) ) {
				$trigger['manifest'] = $manifest;
			}
		}

		$trigger = apply_filters( 'automator_register_trigger', $trigger );

		$triggers[ $this->get_code() ] = $trigger;

		return $triggers;
	}

Scroll to Top