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/woocommerce-zapier/src/Plugin/Subscriptions/Plugin.php
<?php

namespace OM4\WooCommerceZapier\Plugin\Subscriptions;

use OM4\WooCommerceZapier\API\API;
use OM4\WooCommerceZapier\Helper\FeatureChecker;
use OM4\WooCommerceZapier\Logger;
use OM4\WooCommerceZapier\Plugin\Base;
use OM4\WooCommerceZapier\Plugin\Subscriptions\SubscriptionResource;
use WC_Subscription;
use WC_Subscriptions;

defined( 'ABSPATH' ) || exit;

/**
 * Functionality that is enabled when the WooCommerce Subscriptions plugin is active.
 *
 * @since 2.0.0
 */
class Plugin extends Base {

	/**
	 * FeatureChecker instance.
	 *
	 * @var FeatureChecker
	 */
	protected $checker;

	/**
	 * Logger instance.
	 *
	 * @var Logger
	 */
	protected $logger;

	/**
	 * Definition instance.
	 *
	 * @var SubscriptionResource
	 */
	protected $resource_definition;

	/**
	 * Name of the third party plugin.
	 */
	const PLUGIN_NAME = 'WooCommerce Subscriptions';

	/**
	 * The minimum WooCommerce Subscriptions version that this plugin supports.
	 */
	const MINIMUM_SUPPORTED_VERSION = '2.4.3';

	/**
	 * Constructor.
	 *
	 * @param FeatureChecker       $checker FeatureChecker instance.
	 * @param Logger               $logger Logger instance.
	 * @param SubscriptionResource $resource_definition Subscriptions Resource Definition.
	 */
	public function __construct( FeatureChecker $checker, Logger $logger, SubscriptionResource $resource_definition ) {
		$this->checker             = $checker;
		$this->logger              = $logger;
		$this->resource_definition = $resource_definition;
		$this->resource            = SubscriptionResource::class;
	}

	/**
	 * Instructs the Subscriptions functionality to initialise itself.
	 *
	 * @return bool
	 */
	public function initialise() {
		if ( ! parent::initialise() ) {
			return false;
		}

		foreach ( $this->resource_definition->get_webhook_triggers() as $trigger ) {
			foreach ( $trigger->get_actions() as $action ) {
				if ( 0 === strpos( $action, 'wc_zapier_' ) ) {
					$action = str_replace( 'wc_zapier_', '', $action );
					add_action( $action, array( $this, 'convert_arg_to_subscription_id_then_execute' ) );
				}
			}
		}
		return true;
	}

	/**
	 * Get the WooCommerce Subscriptions version number.
	 *
	 * @var string
	 */
	public function get_plugin_version() {
		return WC_Subscriptions::$version;
	}

	/**
	 * Whenever a relevant WooCommerce Subscriptions built-in action/event occurs,
	 * convert the args WC_Subscription object into a numerical subscription ID,
	 * and then trigger our own built-in action which then queues the webhook for delivery.
	 *
	 * @param WC_Subscription $arg Subscription object.
	 *
	 * @return void
	 */
	public function convert_arg_to_subscription_id_then_execute( $arg ) {
		if ( ! is_a( $arg, WC_Subscription::class ) ) {
			return;
		}
		$arg = $arg->get_id();
		/**
		 * Execute the WooCommerce Zapier handler for this hook/action.
		 *
		 * @internal
		 * @since 2.0.4
		 *
		 * @param int $arg Subscription ID.
		 */
		do_action( 'wc_zapier_' . current_action(), $arg );
	}

	/**
	 * Remove Subscriptions endpoints that are not required by WooCommerce Zapier, including:
	 *
	 * - /wc-zapier/v1/subscriptions/(?P<id>[\d]+)/orders
	 * - /wc-zapier/v1/subscriptions/statuses
	 *
	 * @param array $endpoints Registered WP REST API endpoints.
	 *
	 * @return array
	 */
	public function filter_rest_endpoints( $endpoints ) {
		foreach ( $endpoints as $route => $endpoint ) {
			if ( 0 === strpos( $route, sprintf( '/%s/subscriptions/', API::REST_NAMESPACE ) ) ) {
				if (
					false !== strpos( $route, '/(?P<id>[\d]+)/orders' ) ||
					false !== strpos( $route, '/statuses' )
				) {
					unset( $endpoints[ $route ] );
				}
			}
		}
		return $endpoints;
	}

	/**
	 * Whether not not the user has the WooCommerce Subscriptions plugin active.
	 *
	 * @return bool
	 */
	protected function is_active() {
		return $this->checker->class_exists( '\WC_Subscriptions' );
	}

}