Actionify_Triggers::actionify_triggers( $force = false )

Load up our activity triggers so we can add actions to them


Return Return

(void)


Source Source

File: src/core/classes/class-actionify-triggers.php

	public function actionify_triggers() {
		// Get all published recipes
		$recipes = Automator()->get_recipes_data( true );
		if ( empty( $recipes ) ) {
			return;
		}

		foreach ( $recipes as $recipe ) {

			// Only actionify published recipes
			if ( 'publish' !== $recipe['post_status'] ) {
				continue;
			}

			// Only actionify uncompleted recipes
			if ( true === $recipe['completed_by_current_user'] ) {
				continue;
			}

			// Collect all trigger codes that have been actionified so we don't double register
			$actionified_triggers = array();

			// Loop through each trigger and add our trigger event to the hook
			foreach ( $recipe['triggers'] as $trigger ) {

				// Map action to specific recipeID/TriggerID combination
				if ( ! array_key_exists( 'code', $trigger['meta'] ) ) {
					continue;
				}

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

				// We only want to add one action for each trigger
				if ( in_array( $trigger_code, $actionified_triggers, true ) ) {
					continue;
				}

				// The trigger may exist in the DB but the plugin integration may not be active, if it is not
				$trigger_actions             = Automator()->get->trigger_actions_from_trigger_code( $trigger_code );
				$trigger_validation_function = Automator()->get->trigger_validation_function_from_trigger_code( $trigger_code );
				$trigger_priority            = Automator()->get->trigger_priority_from_trigger_code( $trigger_code );
				$trigger_accepted_args       = Automator()->get->trigger_accepted_args_from_trigger_code( $trigger_code );

				// Initialize trigger
				if ( empty( $trigger_validation_function ) ) {
					continue;
				}

				if ( is_array( $trigger_actions ) ) {
					foreach ( $trigger_actions as $trigger_action ) {
						add_action( $trigger_action, $trigger_validation_function, $trigger_priority, $trigger_accepted_args );
					}
				} else {
					add_action( $trigger_actions, $trigger_validation_function, $trigger_priority, $trigger_accepted_args );
				}

				$actionified_triggers[] = $trigger_code;
			}
		}
	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0 Introduced.