LLMS_REST_Webhook::is_valid_resource( array $args )
Determine if the the resource is valid for the webhook
Parameters Parameters
- $args
-
(array) (Required) Numeric array of arguments from the originating hook.
Return Return
(bool)
Source Source
File: libraries/lifterlms-rest/includes/models/class-llms-rest-webhook.php
// Drafts don't have post_date_gmt so calculate it here.
$gmt_date = get_gmt_from_date( $post_resource->post_date );
// A resource is considered created when the hook is executed within 10 seconds of the post creation date.
$resource_created = ( ( time() - 10 ) <= strtotime( $gmt_date ) );
$event = $this->get_event();
if ( ( 'created' === $event && false !== strpos( current_action(), 'save_post' ) ) && ! $resource_created ) {
return false;
} elseif ( ( 'updated' === $event && false !== strpos( current_action(), 'edit_post' ) ) && $resource_created ) {
return false;
}
}
}
return true;
}
/**
* Determine if the current user-related action is valid for the webhook
*
* @since 1.0.0-beta.1
*
* @param int $user_id WP User ID.
* @return bool
*/
protected function is_valid_user_action( $user_id ) {
$user = get_userdata( $user_id );
if ( ! $user ) {
return false;
}
$resource = $this->get_resource();
if ( 'student' === $resource && ! in_array( 'student', (array) $user->roles, true ) ) {
return false;
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 1.0.0-beta.11 | Skipped autosaves and revisions. Implemented a new way to consider a resource as just created. Thanks WooCoommerce. |
| 1.0.0-beta.1 | Introduced. |