LLMS_REST_Webhook::schedule( array $args )

Schedule the webhook for async delivery


Parameters Parameters

$args

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


Top ↑

Return Return

(bool)


Top ↑

Source Source

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

	protected function schedule( $args ) {

		// Remove object & array arguments before scheduling to avoid hitting column index size issues imposed by the ActionScheduler lib.
		foreach ( $args as $index => &$arg ) {
			if ( is_array( $arg ) || is_object( $arg ) ) {
				$arg = null;
			}
		}

		$schedule_args = array(
			'webhook_id' => $this->get( 'id' ),
			'args'       => $args,
		);

		$next = as_next_scheduled_action( 'lifterlms_rest_deliver_webhook_async', $schedule_args, 'llms-webhooks' );

		/**
		 * Determines the time period required to wait between delivery of the webhook
		 *
		 * If the webhook has already been scheduled within this time period it will not be sent again
		 * until the period expires. For example, the default time period is 300 seconds (5 minutes).
		 * If the webhook is triggered at 12:00pm it will be scheduled. If it is triggered again at 12:03pm the
		 * second occurrence will not be scheduled. If it is triggerd again at 12:06pm this third occurrence will
		 * again be scheduled.
		 *
		 * @since 1.0.0-beta.1
		 *
		 * @param int               $delay Time (in seconds).
		 * @param array             $args  Numeric array of arguments from the originating hook.
		 * @param LLMS_REST_Webhook $this  Webhook object.
		 */
		$delay = apply_filters( 'llms_rest_webhook_repeat_delay', 300, $args, $this );

		if ( ! $next || $next >= ( $delay + gmdate( 'U' ) ) ) {

			return as_schedule_single_action( time(), 'lifterlms_rest_deliver_webhook_async', $schedule_args, 'llms-webhooks' ) ? true : false;

		}

		return false;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
1.0.0-beta.17 Stop setting the webhook's property pending_delivery to 1 when scheduling the delivery. We now rely on the method is_already_processed() to determine whether the webhook scheduling should be avoided.
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.