WordPress как на ладони
Недорогой хостинг для сайтов на WordPress: wordpress.jino.ru Платформа для конвертации и монетизации трафика
функция не описана

WC_Webhook::log_delivery() public WC 2.2.0

Log the delivery request/response.

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

Хуков нет.

Возвращает

Null. Ничего.

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

$WC_Webhook = new WC_Webhook();
$WC_Webhook->log_delivery( $delivery_id, $request, $response, $duration );
$delivery_id(строка) (обязательный)
Previously created hash.
$request(массив) (обязательный)
Request data.
$response(массив/WP_Error) (обязательный)
Response data.
$duration(float) (обязательный)
Request duration.

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

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

Код WC_Webhook::log_delivery() WC 4.7.1

<?php
public function log_delivery( $delivery_id, $request, $response, $duration ) {
	$logger  = wc_get_logger();
	$message = array(
		'Webhook Delivery' => array(
			'Delivery ID' => $delivery_id,
			'Date'        => date_i18n( __( 'M j, Y @ G:i', 'woocommerce' ), strtotime( 'now' ), true ),
			'URL'         => $this->get_delivery_url(),
			'Duration'    => $duration,
			'Request'     => array(
				'Method'  => $request['method'],
				'Headers' => array_merge(
					array(
						'User-Agent' => $request['user-agent'],
					),
					$request['headers']
				),
			),
			'Body'        => wp_slash( $request['body'] ),
		),
	);

	// Parse response.
	if ( is_wp_error( $response ) ) {
		$response_code    = $response->get_error_code();
		$response_message = $response->get_error_message();
		$response_headers = array();
		$response_body    = '';
	} else {
		$response_code    = wp_remote_retrieve_response_code( $response );
		$response_message = wp_remote_retrieve_response_message( $response );
		$response_headers = wp_remote_retrieve_headers( $response );
		$response_body    = wp_remote_retrieve_body( $response );
	}

	$message['Webhook Delivery']['Response'] = array(
		'Code'    => $response_code,
		'Message' => $response_message,
		'Headers' => $response_headers,
		'Body'    => $response_body,
	);

	if ( ! Constants::is_true( 'WP_DEBUG' ) ) {
		$message['Webhook Delivery']['Body']             = 'Webhook body is not logged unless WP_DEBUG mode is turned on. This is to avoid the storing of personal data in the logs.';
		$message['Webhook Delivery']['Response']['Body'] = 'Webhook body is not logged unless WP_DEBUG mode is turned on. This is to avoid the storing of personal data in the logs.';
	}

	$logger->info(
		wc_print_r( $message, true ),
		array(
			'source' => 'webhooks-delivery',
		)
	);

	// Track failures.
	// Check for a success, which is a 2xx, 301 or 302 Response Code.
	if ( intval( $response_code ) >= 200 && intval( $response_code ) < 303 ) {
		$this->set_failure_count( 0 );
		$this->save();
	} else {
		$this->failed_delivery();
	}
}