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
protected function is_valid_resource( $args ) { $resource = $this->get_resource(); if ( in_array( $resource, LLMS_REST_API()->webhooks()->get_post_type_resources(), true ) ) { $post_resource = get_post( absint( $args[0] ) ); // Ignore auto-drafts. if ( in_array( get_post_status( $post_resource ), array( 'new', 'auto-draft' ), true ) ) { return false; } if ( false !== strpos( current_action(), 'save_post' ) || false !== strpos( current_action(), 'edit_post' ) ) { // Ignore autosaves and revisions. if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post_resource ) ) || is_int( wp_is_post_autosave( $resource ) ) ) { return false; } // 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; }
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. |