Automator_Tokens::trigger_tokens( null $triggers_meta = null, null $recipe_id = null )

Get token data for recipe triggers


Parameters Parameters

$triggers_meta

(null) (Optional)

Default value: null

$recipe_id

(null) (Optional)

Default value: null


Top ↑

Return Return

(null|array)


Source Source

File: src/core/lib/recipe-parts/tokens/class-automator-tokens.php

	public function trigger_tokens( $triggers_meta = null, $recipe_id = null ) {
		if ( is_null( $triggers_meta ) && is_null( $recipe_id ) ) {
			return null;
		}

		$tokens = apply_filters( 'automator_maybe_trigger_pre_tokens', array(), $triggers_meta, $recipe_id );
		//Only load these when on edit recipe page or is automator ajax is happening!
		if ( ! Automator()->helpers->recipe->is_edit_page() && ! Automator()->helpers->recipe->is_rest() && ! Automator()->helpers->recipe->is_ajax() ) {
			return $tokens;
		}
		if ( empty( $triggers_meta ) ) {
			return $tokens;
		}

		//Add custom tokens regardless of integration / trigger code
		$filters             = array();
		$trigger_integration = '';
		$trigger_meta        = '';
		$trigger_value       = '';
		foreach ( $triggers_meta as $meta_key => $meta_value ) {
			if ( empty( $meta_value ) ) {
				continue;
			}

			if ( 'INTEGRATION_NAME' === (string) strtoupper( $meta_key ) ) {
				continue;
			}

			if ( 'NUMBERCOND' === (string) strtoupper( $meta_key ) ) {
				continue;
			}

			if ( 'uap_trigger_version' === (string) $meta_key ) {
				continue;
			}

			if ( 'sentence' === (string) $meta_key ) {
				continue;
			}

			if ( 'sentence_human_readable' === (string) $meta_key ) {
				continue;
			}

			if ( strpos( $meta_key, 'readable' ) ) {
				continue;
			}

			if ( 'integration' === (string) $meta_key ) {
				$trigger_integration = strtolower( $meta_value );
			}

			//Ignore NUMTIMES and trigger_integration/trigger_code metas
			if ( 'NUMTIMES' !== (string) strtoupper( $meta_key ) && 'integration' !== (string) strtolower( $meta_key ) ) {
				$trigger_meta  = strtolower( $meta_key );
				$trigger_value = $meta_value;
			}

			//Deal with trigger_meta special cases
			if ( 'trigger_meta' === $meta_key ) {
				$trigger_meta  = strtolower( $meta_value );
				$trigger_value = $meta_value;
			}

			//Deal with trigger_meta special cases
			if ( 'code' === (string) $meta_key ) {
				$trigger_meta  = strtolower( $meta_value );
				$trigger_value = $meta_value;
			}

			//Add general Integration based filter, like automator_maybe_trigger_gf_tokens
			if ( ! empty( $trigger_integration ) ) {

				$filter = 'automator_maybe_trigger_' . $trigger_integration . '_tokens';
				$filter = str_replace( '__', '_', $filter );

				$filters[ $filter ] = array(
					'integration'   => strtoupper( $trigger_integration ),
					'meta'          => strtoupper( $trigger_meta ),
					'triggers_meta' => $triggers_meta,
					'recipe_id'     => $recipe_id,
				);

			}

			//Add trigger code specific filter, like automator_maybe_trigger_gf_gfforms_tokens
			if ( ! empty( $trigger_integration ) && ! empty( $triggers_meta ) ) {
				$filter = 'automator_maybe_trigger_' . $trigger_integration . '_' . $trigger_meta . '_tokens';
				$filter = str_replace( '__', '_', $filter );

				$filters[ $filter ] = array(
					'value'         => $trigger_value,
					'integration'   => strtoupper( $trigger_integration ),
					'meta'          => strtoupper( $trigger_meta ),
					'recipe_id'     => $recipe_id,
					'triggers_meta' => $triggers_meta,
				);
			}
		}

		/* Filter to add/remove custom filter */
		/** @var  $filters */
		$filters = apply_filters_deprecated(
			'automator_trigger_filters',
			array(
				$filters,
				$triggers_meta,
			),
			'3.0',
			'automator_trigger_token_filters'
		);
		$filters = apply_filters( 'automator_trigger_token_filters', $filters, $triggers_meta );

		if ( $filters ) {
			foreach ( $filters as $filter => $args ) {
				$tokens = apply_filters( $filter, $tokens, $args );
			}
		}

		if ( isset( $triggers_meta['code'] ) ) {
			$tokens = Automator()->get->trigger_tokens_from_trigger_code( $triggers_meta['code'] ) + $tokens;
		}
		// Adds the opportunity to modify final tokens list
		// (i.e., remove middle name from GF tokens list)
		//$tokens = $this->remove_duplicate_token_ids( $tokens );

		return apply_filters( 'automator_maybe_trigger_tokens', $tokens, $recipe_id );
	}