Automator_Get_Data::recipes_from_trigger_code( $check_trigger_code = null, null $recipe_id = null )


Parameters Parameters

$check_trigger_code

(Optional)

Default value: null

$recipe_id

(null) (Optional)

Default value: null


Top ↑

Return Return

(array)


Source Source

File: src/core/lib/utilities/class-automator-get-data.php

	public function recipes_from_trigger_code( $check_trigger_code = null, $recipe_id = null ) {
		if ( null === $check_trigger_code ) {
			return array();
		}

		$return = array();
		// Get recipes that are in the memory right now.
		$recipes = Automator()->get_recipes_data( false, $recipe_id );

		if ( empty( $recipes ) ) {
			return array();
		}

		foreach ( $recipes as $recipe ) {

			if ( 'publish' !== (string) $recipe['post_status'] ) {
				continue;
			}

			foreach ( $recipe['triggers'] as $trigger ) {

				$trigger_code = $trigger['meta']['code'];

				// Skip if the executed trigger doesn't match
				if ( (string) $check_trigger_code !== (string) $trigger_code ) {
					continue;
				}

				$recipe_id            = absint( $recipe['ID'] );
				$return[ $recipe_id ] = $recipe;
			}
		}

		return $return;
	}