WC_Webhook::is_valid_processing_action
Validates WC processing actions.
Method of the class: WC_Webhook{}
No Hooks.
Returns
true|false. True if validation passes.
Usage
// private - for code of main (parent) class only $result = $this->is_valid_processing_action( $arg );
- $arg(mixed) (required)
- First hook argument.
Changelog
| Since 3.6.0 | Introduced. |
WC_Webhook::is_valid_processing_action() WC Webhook::is valid processing action code WC 10.5.0
private function is_valid_processing_action( $arg ) {
// The `woocommerce_process_shop_*` and `woocommerce_process_product_*` hooks
// fire for create and update of products and orders, so check the post
// creation date to determine the actual event.
$resource = get_post( absint( $arg ) );
// Drafts don't have post_date_gmt so calculate it here.
$gmt_date = get_gmt_from_date( $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 ) );
if ( 'created' === $this->get_event() && ! $resource_created ) {
return false;
} elseif ( 'updated' === $this->get_event() && $resource_created ) {
return false;
}
return true;
}