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/Webhook/DataStore.php
<?php

namespace OM4\WooCommerceZapier\Webhook;

use OM4\WooCommerceZapier\Webhook\ZapierWebhook;
use WC_Webhook_Data_Store;

defined( 'ABSPATH' ) || exit;

/**
 * Retrieval of existing Zapier Webhooks.
 *
 * @since 2.0.0
 */
class DataStore {

	/**
	 * WC_Webhook_Data_Store instance.
	 *
	 * @var WC_Webhook_Data_Store
	 */
	protected $webhook_data_store;

	/**
	 * Webhook DataStore constructor.
	 *
	 * @param WC_Webhook_Data_Store $webhook_data_store WC_Webhook_Data_Store instance.
	 */
	public function __construct( WC_Webhook_Data_Store $webhook_data_store ) {
		$this->webhook_data_store = $webhook_data_store;
	}

	/**
	 * Get all existing Zapier Webhooks (any status, not just active).
	 *
	 * @return ZapierWebhook[]
	 */
	public function get_zapier_webhooks() {
		$webhook_ids = $this->webhook_data_store->search_webhooks(
			array(
				'search' => 'Zapier #',
			)
		);
		return $this->collect_webhooks_for_output( $webhook_ids );
	}

	/**
	 * Get every active Zapier Webhooks.
	 *
	 * @return ZapierWebhook[]|array
	 */
	public function get_active_zapier_webhooks() {
		$webhook_ids = $this->webhook_data_store->search_webhooks(
			array(
				'search' => 'Zapier #',
				'status' => 'active',
				'limit'  => -1,
			)
		);
		return $this->collect_webhooks_for_output( $webhook_ids );
	}

	/**
	 * Get every paused Zapier Webhooks.
	 *
	 * @return ZapierWebhook[]|array
	 */
	public function get_paused_zapier_webhooks() {
		$webhook_ids = $this->webhook_data_store->search_webhooks(
			array(
				'search' => 'Zapier #',
				'status' => 'paused',
				'limit'  => -1,
			)
		);
		return $this->collect_webhooks_for_output( $webhook_ids );
	}

	/**
	 * Get the number of active Zapier Webhooks.
	 *
	 * @return int
	 */
	public function get_number_of_active_zapier_webhooks() {
		return count( $this->get_active_zapier_webhooks() );
	}

	/**
	 * Collect Webhooks for output
	 *
	 * @param array|object $webhook_ids List of Webhook IDs.
	 *
	 * @return ZapierWebhook[]|array
	 */
	protected function collect_webhooks_for_output( $webhook_ids ) {
		if ( ! is_array( $webhook_ids ) ) {
			return array();
		}

		$webhooks = array();
		foreach ( $webhook_ids as $webhook_id ) {
			$webhook = new ZapierWebhook( $webhook_id );
			if ( 0 !== $webhook->get_id() && $webhook->is_zapier_webhook() ) {
				$webhooks[] = $webhook;
			}
		}
		return $webhooks;
	}
}