Automattic\WooCommerce\Internal\Utilities

WebhookUtil::get_legacy_webhooks_count()publicWC 1.0

Gets the count of webhooks that are configured to use the Legacy REST API to compose their payloads.

Метод класса: WebhookUtil{}

Хуков нет.

Возвращает

int.

Использование

$WebhookUtil = new WebhookUtil();
$WebhookUtil->get_legacy_webhooks_count( $clear_cache ): int;
$clear_cache(true|false)
If true, the previously cached value of the count will be discarded if it exists.
По умолчанию: false

Код WebhookUtil::get_legacy_webhooks_count() WC 9.7.1

public function get_legacy_webhooks_count( bool $clear_cache = false ): int {
	global $wpdb;

	$cache_key = WC_Cache_Helper::get_cache_prefix( 'webhooks' ) . 'legacy_count';
	if ( $clear_cache ) {
		wp_cache_delete( $cache_key, 'webhooks' );
	}

	$count = wp_cache_get( $cache_key, 'webhooks' );

	if ( false === $count ) {
		$count = absint( $wpdb->get_var( "SELECT count( webhook_id ) FROM {$wpdb->prefix}wc_webhooks WHERE `api_version` < 1;" ) );
		wp_cache_add( $cache_key, $count, 'webhooks' );
	}

	return $count;
}