Automator_Recipe_Process_Complete::complete_actions( null $recipe_id = null, null $user_id = null, null $recipe_log_id = null, array $args = array() )

Complete all actions in recipe


Parameters Parameters

$recipe_id

(null) (Optional)

Default value: null

$user_id

(null) (Optional)

Default value: null

$recipe_log_id

(null) (Optional)

Default value: null

$args

(array) (Optional)

Default value: array()


Top ↑

Return Return

(bool)


Source Source

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

	public function complete_actions( $recipe_id = null, $user_id = null, $recipe_log_id = null, $args = array() ) {
		$recipe_action_data = Automator()->get_recipe_data( 'uo-action', $recipe_id );

		foreach ( $recipe_action_data as $action_data ) {

			$action_code                  = $action_data['meta']['code'];
			$action_status                = $action_data['post_status'];
			$action_data['recipe_log_id'] = $recipe_log_id;
			$action_integration           = Automator()->get->action_integration_from_action_code( $action_code );

			if ( 1 === Automator()->plugin_status->get( $action_integration ) && 'publish' === $action_status ) {
				// The plugin for this action is active .. execute
				$action_execution_function = Automator()->get->action_execution_function_from_action_code( $action_code );

				$valid_function = true;
				if ( null === $action_execution_function ) {
					$valid_function = false;
				} elseif ( is_array( $action_execution_function ) && ! method_exists( $action_execution_function[0], $action_execution_function[1] ) ) {
					$valid_function = false;
				} elseif ( is_string( $action_execution_function ) && ! function_exists( $action_execution_function ) ) {
					$valid_function = false;
				}

				if ( ! $valid_function ) {
					$error_message                       = Automator()->error_message->get( 'action-function-not-exist' );
					$action_data['complete_with_errors'] = true;
					$this->action( $user_id, $action_data, $recipe_id, $error_message, $recipe_log_id, $args );
				} else {

					//fallback...
					$action_data['args'] = $args;

					/*
					 * See function notes
					 *
					 * @since 2.8
					 */
					$action_data = $this->parse_custom_value( $action_data, $user_id, $recipe_id, $args );

					$action = array(
						'user_id'     => $user_id,
						'action_data' => $action_data,
						'recipe_id'   => $recipe_id,
						'args'        => $args,
					);

					$action = apply_filters( 'automator_before_action_executed', $action );

					if ( isset( $action['process_further'] ) && $action['process_further'] === false ) {
						Utilities::log( 'Action was skipped by uap_before_action_executed filter.' );
						continue;
					}

					call_user_func_array( $action_execution_function, $action );
				}
			} elseif ( 0 === Automator()->plugin_status->get( $action_integration ) ) {
				$error_message                       = Automator()->error_message->get( 'action-not-active' );
				$action_data['complete_with_errors'] = true;
				$this->action( $user_id, $action_data, $recipe_id, $error_message, $recipe_log_id, $args );
			} elseif ( 0 === Automator()->plugin_status->get( $action_integration ) ) {
				$error_message                       = Automator()->error_message->get( 'plugin-not-active' );
				$action_data['complete_with_errors'] = true;
				$this->action( $user_id, $action_data, $recipe_id, $error_message, $recipe_log_id, $args );
			} elseif ( 1 === Automator()->plugin_status->get( $action_integration ) && 'draft' === $action_status ) {
				continue;
			} else {
				$error_message                       = esc_attr__( 'Unknown error occurred.', 'uncanny-automator' );
				$action_data['complete_with_errors'] = true;
				Automator()->error->add_error( 'complete_action', $error_message, array( $action_data, $this ) );
				$this->action( $user_id, $action_data, $recipe_id, $error_message, $recipe_log_id, $args );
			}
		}

		$this->closures( $recipe_id, $user_id, $recipe_log_id, $args );

		return true;
	}