HEX
Server: Apache/2.4.65 (Ubuntu)
System: Linux ielts-store-v2 6.8.0-1036-gcp #38~22.04.1-Ubuntu SMP Thu Aug 14 01:19:18 UTC 2025 x86_64
User: root (0)
PHP: 7.2.34-54+ubuntu20.04.1+deb.sury.org+1
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,
Upload Files
File: //proc/self/cwd/wp-content/plugins/automatewoo/includes/Triggers/Workflow_Times_Run_Reaches.php
<?php
// phpcs:ignoreFile

namespace AutomateWoo;

if ( ! defined( 'ABSPATH' ) ) exit;

/**
 * @class Trigger_Workflow_Times_Run_Reaches
 */
class Trigger_Workflow_Times_Run_Reaches extends Trigger {

	public $supplied_data_items = [ 'workflow' ];


	function load_admin_details() {
		$this->title = __('Workflow Times Run Reaches', 'automatewoo');
		$this->group = __('Workflows', 'automatewoo');
	}


	/**
	 * Add options to the trigger
	 */
	function load_fields() {
		$workflow_field = new Fields\Workflow();

		$times_run = new Fields\Number();
		$times_run->set_name('times_run');
		$times_run->set_title(__('Times run', 'automatewoo') );

		$this->add_field( $workflow_field );
		$this->add_field( $times_run );
	}



	/**
	 * When could this trigger run?
	 */
	function register_hooks() {
		add_action( 'automatewoo_after_workflow_run', [ $this, 'catch_hooks' ] );
	}


	/**
	 * Route hooks through here
	 *
	 * @param $workflow Workflow
	 */
	function catch_hooks( $workflow ) {
		$this->maybe_run([
			'workflow' => $workflow,
			'post' => $workflow->post
		]);
	}


	/**
	 * @param Workflow $workflow
	 * @return bool
	 */
	function validate_workflow( $workflow ) {

		$workflow_data_item = $workflow->data_layer()->get_workflow();

		$selected_workflow_id = $workflow->get_trigger_option( 'workflow' );
		$times_run = (int) $workflow->get_trigger_option('times_run');

		if ( ! $workflow_data_item )
			return false;

		// match running workflow to selected workflow
		if ( $workflow_data_item->get_id() != $selected_workflow_id )
			return false;

		if ( $workflow_data_item->get_times_run() !== $times_run )
			return false;

		return true;
	}

}