WC_Webhook::is_valid_resource()privateWC 3.6.0

Checks the resource for this webhook is valid e.g. valid post status.

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

Хуков нет.

Возвращает

true|false. True if validation passes.

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

// private - только в коде основоного (родительского) класса
$result = $this->is_valid_resource( $arg );
$arg(разное) (обязательный)
First hook argument.

Список изменений

С версии 3.6.0 Введена.

Код WC_Webhook::is_valid_resource() WC 8.7.0

private function is_valid_resource( $arg ) {
	$resource = $this->get_resource();

	if ( in_array( $resource, array( 'product', 'coupon' ), true ) ) {
		$status = get_post_status( absint( $arg ) );

		// Ignore auto drafts for all resources.
		if ( in_array( $status, array( 'auto-draft', 'new' ), true ) ) {
			return false;
		}
	}

	if ( 'order' === $resource ) {
		// Check registered order types for order types args.
		if ( ! OrderUtil::is_order( absint( $arg ), wc_get_order_types( 'order-webhooks' ) ) ) {
			return false;
		}

		$order = wc_get_order( absint( $arg ) );

		// Ignore standard drafts for orders.
		if ( in_array( $order->get_status(), array( 'draft', 'auto-draft', 'new' ), true ) ) {
			return false;
		}
	}
	return true;
}