Filter at end of should_deliver method

This commit is contained in:
Mike Jolley 2016-03-03 12:52:58 +00:00
parent 875cd46f45
commit a043b6d94d
1 changed files with 15 additions and 20 deletions

View File

@ -132,36 +132,28 @@ class WC_Webhook {
* @return bool true if webhook should be delivered, false otherwise * @return bool true if webhook should be delivered, false otherwise
*/ */
private function should_deliver( $arg ) { private function should_deliver( $arg ) {
$should_deliver = true;
/* $current_action = current_action();
* Let other plugins intercept deliver for some messages queue like rabbit/zeromq
*/
if ( ! apply_filters( 'woocommerce_webhook_should_deliver', true, $this, $arg )) {
return false;
}
// only active webhooks can be delivered // only active webhooks can be delivered
if ( 'active' != $this->get_status() ) { if ( 'active' != $this->get_status() ) {
return false; $should_deliver = false;
}
$current_action = current_action();
// only deliver deleted event for coupons, orders, and products // only deliver deleted event for coupons, orders, and products
if ( 'delete_post' == $current_action && ! in_array( $GLOBALS['post_type'], array( 'shop_coupon', 'shop_order', 'product' ) ) ) { } elseif ( 'delete_post' === $current_action && ! in_array( $GLOBALS['post_type'], array( 'shop_coupon', 'shop_order', 'product' ) ) ) {
return false; $should_deliver = false;
} elseif ( 'delete_user' == $current_action ) { } elseif ( 'delete_user' == $current_action ) {
$user = get_userdata( absint( $arg ) ); $user = get_userdata( absint( $arg ) );
// only deliver deleted customer event for users with customer role // only deliver deleted customer event for users with customer role
if ( ! $user || ! in_array( 'customer', (array) $user->roles ) ) { if ( ! $user || ! in_array( 'customer', (array) $user->roles ) ) {
return false; $should_deliver = false;
} }
// check if the custom order type has chosen to exclude order webhooks from triggering along with its own webhooks. // check if the custom order type has chosen to exclude order webhooks from triggering along with its own webhooks.
} elseif ( 'order' == $this->get_resource() && ! in_array( get_post_type( absint( $arg ) ), wc_get_order_types( 'order-webhooks' ) ) ) { } elseif ( 'order' == $this->get_resource() && ! in_array( get_post_type( absint( $arg ) ), wc_get_order_types( 'order-webhooks' ) ) ) {
return false; $should_deliver = false;
} elseif ( 0 === strpos( $current_action, 'woocommerce_process_shop' ) ) { } elseif ( 0 === strpos( $current_action, 'woocommerce_process_shop' ) ) {
// the `woocommerce_process_shop_*` hook fires for both updates // the `woocommerce_process_shop_*` hook fires for both updates
@ -172,13 +164,16 @@ class WC_Webhook {
$resource_created = ( ( time() - 10 ) <= strtotime( $resource->post_date_gmt ) ); $resource_created = ( ( time() - 10 ) <= strtotime( $resource->post_date_gmt ) );
if ( 'created' == $this->get_event() && ! $resource_created ) { if ( 'created' == $this->get_event() && ! $resource_created ) {
return false; $should_deliver = false;
} elseif ( 'updated' == $this->get_event() && $resource_created ) { } elseif ( 'updated' == $this->get_event() && $resource_created ) {
return false; $should_deliver = false;
} }
} }
return true; /*
* Let other plugins intercept deliver for some messages queue like rabbit/zeromq
*/
return apply_filters( 'woocommerce_webhook_should_deliver', $should_deliver, $this, $arg );
} }