Automator_Recipe_Process_User::maybe_validate_trigger_without_postid( array $args = array(), null $trigger = null, null $recipe_id = null, null $recipe_log_id = null )

Validate recipe post ID when ignore post id is passed.


Description Description

This is mostly going to be used when user/dev done validation in trigger and passes recipe IDs for this to be validated and added to trigger log DB.


Top ↑

Parameters Parameters

$args

(Optional)

Default value: array()

$trigger

(Optional)

Default value: null

$recipe_id

(Optional)

Default value: null

$recipe_log_id

(Optional)

Default value: null


Top ↑

Return Return

(array)


Source Source

File: src/core/lib/process/class-automator-recipe-process-user.php

	public function maybe_validate_trigger_without_postid( $args = array(), $trigger = null, $recipe_id = null, $recipe_log_id = null ) {

		if ( empty( $args ) || null === $trigger || null === $recipe_id ) {
			return [
				'result' => false,
				'error'  => __( 'One of the required field is missing.', 'uncanny-automator' ),
			];
		}


		$check_trigger_code  = $args['code'];
		$trigger_meta        = $args['meta'];
		$user_id             = $args['user_id'];
		$matched_recipe_id   = $args['recipe_to_match'];
		$matched_trigger_id  = $args['trigger_to_match'];
		$trigger_id          = is_numeric( $matched_trigger_id ) ? (int) $matched_trigger_id : $trigger['ID'];
		$trigger_code        = $trigger['meta']['code'];
		$trigger_integration = $trigger['meta']['integration'];

		// Skip completion if the plugin is not active
		if ( 0 === Automator()->plugin_status->get( $trigger_integration ) ) {
			// The plugin for this trigger is NOT active
			Automator()->error->add_error( 'uap_do_trigger_log', 'ERROR: You are trying to complete ' . $trigger['meta']['code'] . ' and the plugin ' . $trigger_integration . ' is not active. ', $this );

			return [
				'result' => false,
				'error'  => __( 'Plugin is not active.', 'uncanny-automator' ),
			];
		}

		/*if ( is_null( $recipe_log_id ) || ! is_numeric( $recipe_log_id ) ) {
			$recipe_log_id = $this->maybe_create_recipe_log_entry( $recipe_id, $user_id, true );
		}*/

		// Stop here if the trigger was already completed
		$is_trigger_completed = $this->is_trigger_completed( $user_id, $trigger_id, $recipe_id, $recipe_log_id, $args );

		if ( $is_trigger_completed ) {
			return [
				'result' => false,
				'error'  => __( 'Trigger is completed.', 'uncanny-automator' ),
			];
		}
		// Skip if the executed trigger doesn't match
		if ( (string) $check_trigger_code !== (string) $trigger_code ) {
			return [
				'result' => false,
				'error'  => sprintf( '%s AND %s triggers not matched.', $check_trigger_code, $trigger_code ),
			];
		}

		if ( 0 !== (int) $matched_recipe_id && (int) $recipe_id !== (int) $matched_recipe_id ) {
			return [
				'result' => false,
				'error'  => __( 'Recipe not matched.', 'uncanny-automator' ),
			];
		} elseif ( (int) $recipe_id === (int) $matched_recipe_id ) {
			/**
			 * Added second part of code to check for MAGICBUTTON
			 * since trigger meta of MAGICBUTTON is saved by
			 * `code` instead of `meta`
			 *
			 * @version 2.1.6
			 * @author  Saad
			 */
			if ( ! isset( $trigger['meta'][ $trigger_meta ] ) && ! isset( $trigger['meta'][ $args['code'] ] ) ) {
				return [
					'result' => false,
					'error'  => __( 'Trigger meta not found.', 'uncanny-automator' ),
				];
			}
		}

		return $this->maybe_get_trigger_id( $user_id, $trigger_id, $recipe_id, $recipe_log_id );
	}