WC_Webhook::deliver_ping()publicWC 2.2.0

Send a test ping to the delivery URL, sent when the webhook is first created.

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

Хуков нет.

Возвращает

true|false|WP_Error.

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

$WC_Webhook = new WC_Webhook();
$WC_Webhook->deliver_ping();

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

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

Код WC_Webhook::deliver_ping() WC 9.3.3

public function deliver_ping() {
	$args = array(
		'user-agent' => sprintf( 'WooCommerce/%s Hookshot (WordPress/%s)', Constants::get_constant( 'WC_VERSION' ), $GLOBALS['wp_version'] ),
		'body'       => 'webhook_id=' . $this->get_id(),
	);

	$test          = wp_safe_remote_post( $this->get_delivery_url(), $args );
	$response_code = wp_remote_retrieve_response_code( $test );

	if ( is_wp_error( $test ) ) {
		/* translators: error message */
		return new WP_Error( 'error', sprintf( __( 'Error: Delivery URL cannot be reached: %s', 'woocommerce' ), $test->get_error_message() ) );
	}

	if ( 200 !== $response_code ) {
		/* translators: error message */
		return new WP_Error( 'error', sprintf( __( 'Error: Delivery URL returned response code: %s', 'woocommerce' ), absint( $response_code ) ) );
	}

	$this->set_pending_delivery( false );
	$this->save();

	return true;
}