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

Validate (int) values trigger v/s (int) trigger[‘meta’].


Description Description

If matched add value to trigger log table


Top ↑

Parameters Parameters

$args

(array) (Optional)

Default value: array()

$trigger

(null) (Optional)

Default value: null

$recipe_id

(null) (Optional)

Default value: null

$recipe_log_id

(null) (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( $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'];
		$post_id             = $args['post_id'];
		$user_id             = $args['user_id'];
		$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' ),
			];
		}

		// 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 ( $check_trigger_code !== $trigger_code ) {
			return [
				'result' => false,
				'error'  => __( 'Trigger isn\'t matched.', 'uncanny-automator' ),
			];
		}

		// The post ID the current user needs to visit
		if ( key_exists( $trigger_meta, $trigger['meta'] ) ) {
			$trigger_post_id = intval( $trigger['meta'][ $trigger_meta ] );
		} else {
			$trigger_post_id = 0;
		}

		if ( intval( '-1' ) !== intval( $trigger_post_id ) ) {
			if ( is_numeric( $trigger_post_id ) && is_numeric( $post_id ) && absint( $trigger_post_id ) !== absint( $post_id ) ) {
				return [
					'result' => false,
					'error'  => __( 'Trigger not matched.', 'uncanny-automator' ),
				];
			} elseif ( (string) $trigger_post_id != (string) $post_id ) {
				return [
					'result' => false,
					'error'  => __( 'Trigger not matched.', 'uncanny-automator' ),
				];
			}
		}

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