LLMS_REST_Webhook_Data::get_payload( array $args )
Retrieve a payload for webhook delivery.
Parameters Parameters
- $args
-
(array) (Required) Numeric array of arguments from the originating hook.
Return Return
(array)
Source Source
File: libraries/lifterlms-rest/includes/abstracts/class-llms-rest-webhook-data.php
protected function get_payload( $args ) {
// Switch current user to the user who created the webhook.
$current_user = get_current_user_id();
wp_set_current_user( $this->get( 'user_id' ) );
$resource = $this->get_resource();
$event = $this->get_event();
$payload = array();
if ( 'deleted' === $event ) {
if ( in_array( $this->get_resource(), array( 'enrollment', 'progress' ), true ) ) {
$payload['student_id'] = $args[0];
$payload['post_id'] = $args[1];
} else {
$payload['id'] = $args[0];
}
} elseif ( 'action' === $resource ) {
$payload['action'] = current( $this->get_hooks() );
$payload['args'] = $args;
} else {
if ( 'enrollment' === $resource ) {
$endpoint = sprintf( '/llms/v1/students/%1$d/enrollments/%2$d', $args[0], $args[1] );
} elseif ( 'progress' === $resource ) {
$endpoint = sprintf( '/llms/v1/students/%1$d/progress/%2$d', $args[0], $args[1] );
} else {
$endpoint = sprintf( '/llms/v1/%1$ss/%2$d', $resource, $args[0] );
}
$payload = llms_rest_get_api_endpoint_data( $endpoint );
}
// Restore the current user.
wp_set_current_user( $current_user );
/**
* Filter the webhook payload prior to delivery
*
* @since 1.0.0-beta.1
*
* @param array $payload Webhook payload.
* @param string $resource Webhook resource.
* @param string $event Webhook event.
* @param array $args Numeric array of arguments from the originating hook.
* @param LLMS_REST_Webhook $this Webhook object.
*/
return apply_filters( 'llms_rest_webhook_get_payload', $payload, $resource, $event, $args, $this );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 1.0.0-beta.6 | Retrieve proper payload for enrollment and progress resources. |
| 1.0.0-beta.1 | Introduced. |