本文整理汇总了PHP中WC_Webhook::get_delivery_logs方法的典型用法代码示例。如果您正苦于以下问题:PHP WC_Webhook::get_delivery_logs方法的具体用法?PHP WC_Webhook::get_delivery_logs怎么用?PHP WC_Webhook::get_delivery_logs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WC_Webhook
的用法示例。
在下文中一共展示了WC_Webhook::get_delivery_logs方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_items
/**
* Get all webhook deliveries.
*
* @param WP_REST_Request $request
* @return array
*/
public function get_items($request)
{
$webhook = new WC_Webhook((int) $request['webhook_id']);
if (empty($webhook->post_data->post_type) || 'shop_webhook' !== $webhook->post_data->post_type) {
return new WP_Error('woocommerce_rest_webhook_invalid_id', __('Invalid webhook id.', 'woocommerce'), array('status' => 404));
}
$logs = $webhook->get_delivery_logs();
$data = array();
foreach ($logs as $log) {
$delivery = $this->prepare_item_for_response((object) $log, $request);
$delivery = $this->prepare_response_for_collection($delivery);
$data[] = $delivery;
}
return rest_ensure_response($data);
}
示例2: get_webhook_deliveries
/**
* Get deliveries for a webhook
*
* @since 2.2
* @param string $webhook_id webhook ID
* @param string|null $fields fields to include in response
* @return array
*/
public function get_webhook_deliveries($webhook_id, $fields = null)
{
// Ensure ID is valid webhook ID
$webhook_id = $this->validate_request($webhook_id, 'shop_webhook', 'read');
if (is_wp_error($webhook_id)) {
return $webhook_id;
}
$webhook = new WC_Webhook($webhook_id);
$logs = $webhook->get_delivery_logs();
$delivery_logs = array();
foreach ($logs as $log) {
// Add timestamp
$log['created_at'] = $this->server->format_datetime($log['comment']->comment_date_gmt);
// Remove comment object
unset($log['comment']);
$delivery_logs[] = $log;
}
return array('webhook_deliveries' => $delivery_logs);
}