LLMS_REST_Webhook::deliver( array $args )

Delivers the webhook


Parameters Parameters

$args

(array) (Required) Numeric array of arguments from the originating hook.


Top ↑

Return Return

(void)


Top ↑

Source Source

File: libraries/lifterlms-rest/includes/models/class-llms-rest-webhook.php

	public function deliver( $args ) {

		$start   = microtime( true );
		$payload = $this->get_payload( $args );

		$http_args = array(
			'method'      => 'POST',
			'timeout'     => 60,
			'redirection' => 0,
			'user-agent'  => $this->get_user_agent(),
			'body'        => trim( wp_json_encode( $payload ) ),
			'headers'     => array(
				'Content-Type' => 'application/json',
			),
		);

		/**
		 * Modify HTTP args used to deliver the webhook
		 *
		 * @since 1.0.0-beta.1
		 *
		 * @param array             $http_args HTTP request args suitable for `wp_remote_request()`.
		 * @param LLMS_REST_Webhook $this      Webhook object.
		 * @param mixed             $args      First argument passed to the action triggering the webhook.
		 */
		$http_args = apply_filters( 'llms_rest_webhook_delivery_args', $http_args, $this, $args );

		$delivery_id = wp_hash( $this->get( 'id' ) . strtotime( 'now' ) );

		$http_args['headers'] = array_merge(
			$http_args['headers'],
			array(
				'X-LLMS-Webhook-Source'    => home_url( '/' ),
				'X-LLMS-Webhook-Topic'     => $this->get( 'topic' ),
				'X-LLMS-Webhook-Resource'  => $this->get_resource(),
				'X-LLMS-Webhook-Event'     => $this->get_event(),
				'X-LLMS-Webhook-Signature' => $this->get_delivery_signature( $http_args['body'] ),
				'X-LLMS-Webhook-ID'        => $this->get( 'id' ),
				'X-LLMS-Delivery-ID'       => $delivery_id,
			)
		);

		$res = wp_safe_remote_request( $this->get( 'delivery_url' ), $http_args );

		$duration = round( microtime( true ) - $start, 5 );

		$this->delivery_after( $delivery_id, $http_args, $res, $duration );

		/**
		 * Fires after a webhook is delivered
		 *
		 * @since 1.0.0-beta.1
		 *
		 * @param array             $http_args HTTP request args.
		 * @param WP_Error|array    $res       Remote response.
		 * @param int               $duration  Executing time.
		 * @param array             $args      Numeric array of arguments from the originating hook.
		 * @param LLMS_REST_Webhook $this      Webhook object.
		 */
		do_action( 'llms_rest_webhook_delivery', $http_args, $res, $duration, $args, $this );

	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.1 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.