LLMS_REST_Webhook::delivery_after( string $delivery_id, array $req_args, array $res, float $duration )
Fires after delivery
Description Description
Logs data when loggind enabled and updates state data.
Parameters Parameters
- $delivery_id
-
(string) (Required) Webhook delivery id (for logging).
- $req_args
-
(array) (Required) HTTP Request Arguments used to deliver the webhook.
- $res
-
(array) (Required) Results from
wp_safe_remote_request()
. - $duration
-
(float) (Required) Time (in microseconds) it took to generate and deliver the webhook.
Return Return
(void)
Source Source
File: libraries/lifterlms-rest/includes/models/class-llms-rest-webhook.php
protected function delivery_after( $delivery_id, $req_args, $res, $duration ) { // Parse response. if ( is_wp_error( $res ) ) { $res_code = $res->get_error_code(); $res_message = $res->get_error_message(); $res_headers = array(); $res_body = ''; } else { $res_code = wp_remote_retrieve_response_code( $res ); $res_message = wp_remote_retrieve_response_message( $res ); $res_headers = wp_remote_retrieve_headers( $res ); $res_body = wp_remote_retrieve_body( $res ); } if ( defined( 'LLMS_REST_WEBHOOK_DELIVERY_LOGGING' ) && LLMS_REST_WEBHOOK_DELIVERY_LOGGING ) { $message = array( 'Delivery ID' => $delivery_id, 'Date' => date_i18n( __( 'M j, Y @ H:i', 'lifterlms' ), strtotime( 'now' ), true ), 'URL' => $this->get( 'delivery_url' ), 'Duration' => $duration, 'Request' => array( 'Method' => $req_args['method'], 'Headers' => array_merge( array( 'User-Agent' => $req_args['user-agent'], ), $req_args['headers'] ), ), 'Body' => wp_slash( $req_args['body'] ), 'Response' => array( 'Code' => $res_code, 'Message' => $res_message, 'Headers' => $res_headers, 'Body' => $res_body, ), ); if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ) { $message['Webhook Delivery']['Body'] = 'Webhook body is not logged unless WP_DEBUG mode is turned on.'; $message['Webhook Delivery']['Response']['Body'] = 'Webhook body is not logged unless WP_DEBUG mode is turned on.'; } llms_log( $message, sprintf( 'webhook-%d', $this->get( 'id' ) ) ); } // Check for a success, which is a 2xx, 301 or 302 Response Code. if ( absint( $res_code ) >= 200 && absint( $res_code ) <= 302 ) { $this->set( 'failure_count', 0 ); } else { $this->set_delivery_failure(); } }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
1.0.0-beta.17 | Stop setting the webhook's property pending_delivery to 0. We now rely on the method is_already_processed() to determine whether the webhook delivering should be avoided. |
1.0.0-beta.1 | Introduced. |