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: /var/www/html/ielts-store/wp-content/plugins/automatewoo/includes/Workflows/Status.php
<?php

namespace AutomateWoo\Workflows;

use AutomateWoo\Exceptions\InvalidStatus;

/**
 * Class Status
 *
 * @since 5.1.0
 */
final class Status {

	const ACTIVE   = 'active';
	const DISABLED = 'disabled';

	const POST_ACTIVE   = 'publish';
	const POST_DISABLED = 'aw-disabled';

	/**
	 * The equivalent post status.
	 *
	 * @var string
	 */
	private $post_status;

	/**
	 * A Workflow status.
	 *
	 * @var string
	 */
	private $status;

	/**
	 * Status constructor.
	 *
	 * @param string $status The workflow status.
	 *
	 * @throws InvalidStatus When the status is not a known workflow status.
	 */
	public function __construct( string $status ) {
		$this->validate_status( $status );
		$this->status      = $status;
		$this->post_status = $this->get_available_statuses()[ $status ];
	}

	/**
	 * Get the post status.
	 *
	 * @return string
	 */
	public function get_post_status(): string {
		return $this->post_status;
	}

	/**
	 * Get the workflow status.
	 *
	 * @return string
	 */
	public function get_status(): string {
		return $this->status;
	}

	/**
	 * Change the workflow status.
	 *
	 * Will return a new object.
	 *
	 * @param string $new_status The new workflow status.
	 *
	 * @return Status
	 */
	public function change_status_to( string $new_status ): Status {
		return new self( $new_status );
	}

	/**
	 * Validate a workflow status.
	 *
	 * @param string $status The status to validate.
	 *
	 * @throws InvalidStatus When the status is not a known workflow status.
	 */
	private function validate_status( string $status ) {
		$available_statuses = $this->get_available_statuses();
		if ( ! array_key_exists( $status, $available_statuses ) ) {
			throw InvalidStatus::unknown_status( $status );
		}

		if ( ! is_string( $available_statuses[ $status ] ) || empty( $available_statuses[ $status ] ) ) {
			throw InvalidStatus::no_post_staus( $status );
		}
	}

	/**
	 * Get the available workflow statuses and their post status mapping.
	 *
	 * @return array
	 */
	private function get_available_statuses(): array {
		$additional_statuses = apply_filters( 'automatewoo/workflow/statuses', [] );

		return array_merge(
			$additional_statuses,
			[
				self::ACTIVE   => self::POST_ACTIVE,
				self::DISABLED => self::POST_DISABLED,
			]
		);
	}
}