Triggers::process_trigger( $args )

Everything has been sorted. Let’s go ahead and execute trigger.


Parameters Parameters

$args

(Required)


Source Source

File: src/core/lib/recipe-parts/triggers/trait-triggers.php

	protected function process_trigger( $args ) {
		/**
		 * Allow developers to manipulate $pass_args with custom arguments. For example, ignore_post_id.
		 */
		$pass_args = $this->prepare_entry_args( $args );

		/**
		 * Should the trigger be autocompleted and continue running trigger?
		 */
		$complete_trigger = apply_filters( 'automator_auto_complete_trigger', $this->do_trigger_autocomplete(), $pass_args, $args );

		/**
		 * Attempt to add trigger entry and autocomplete it if autocomplete is set to true.
		 */
		do_action( 'automator_before_trigger_run', $args, $pass_args );
		if ( true === $this->do_trigger_autocomplete() ) {
			Automator()->process->user->maybe_add_trigger_entry( $pass_args, $complete_trigger );
		} else {
			$entry_args = Automator()->process->user->maybe_add_trigger_entry( $pass_args, $complete_trigger );
			/**
			 * If trigger is not autocompleted, an array is returned which should be handled manually.
			 */
			if ( empty( $entry_args ) ) {
				return;
			}

			foreach ( $entry_args as $result ) {
				if ( true === $result['result'] ) {
					$result_args = $result['args'];
					/**
					 * @var array $args | All the arguments passed to this function
					 * @var array $pass_args | All the arguments passed to run mark a trigger complete
					 * @var array $result_args | All the arguments returned after marking trigger complete
					 */
					$do_action = array(
						'trigger_entry' => $result_args,
						'entry_args'    => $pass_args,
						'trigger_args'  => $args,
					);
					do_action( 'automator_before_trigger_completed', $do_action, $this );

					Automator()->process->user->maybe_trigger_complete( $result_args );

					do_action( 'automator_after_trigger_completed', $do_action, $this );
				}
			}
		}
		do_action( 'automator_after_trigger_run', $args, $pass_args );
	}