Add restored webhook

This commit is contained in:
claudiulodro 2017-04-27 11:44:57 -07:00
parent ddcf561b70
commit 027e7b1f94
4 changed files with 33 additions and 18 deletions

View File

@ -55,15 +55,18 @@ if ( ! defined( 'ABSPATH' ) ) {
'coupon.created' => __( 'Coupon created', 'woocommerce' ),
'coupon.updated' => __( 'Coupon updated', 'woocommerce' ),
'coupon.deleted' => __( 'Coupon deleted', 'woocommerce' ),
'coupon.restored' => __( 'Coupon restored', 'woocommerce' ),
'customer.created' => __( 'Customer created', 'woocommerce' ),
'customer.updated' => __( 'Customer updated', 'woocommerce' ),
'customer.deleted' => __( 'Customer deleted', 'woocommerce' ),
'order.created' => __( 'Order created', 'woocommerce' ),
'order.updated' => __( 'Order updated', 'woocommerce' ),
'order.deleted' => __( 'Order deleted', 'woocommerce' ),
'order.restored' => __( 'Order restored', 'woocommerce' ),
'product.created' => __( 'Product created', 'woocommerce' ),
'product.updated' => __( 'Product updated', 'woocommerce' ),
'product.deleted' => __( 'Product deleted', 'woocommerce' ),
'product.restored' => __( 'Product restored', 'woocommerce' ),
'action' => __( 'Action', 'woocommerce' ),
'custom' => __( 'Custom', 'woocommerce' ),
) );

View File

@ -137,8 +137,8 @@ class WC_Webhook {
// only active webhooks can be delivered
if ( 'active' != $this->get_status() ) {
$should_deliver = false;
} elseif ( in_array( $current_action, array( 'delete_post', 'wp_trash_post' ), true ) ) {
// Only deliver deleted event for coupons, orders, and products.
} elseif ( in_array( $current_action, array( 'delete_post', 'wp_trash_post', 'untrashed_post' ), true ) ) {
// Only deliver deleted/restored event for coupons, orders, and products.
if ( isset( $GLOBALS['post_type'] ) && ! in_array( $GLOBALS['post_type'], array( 'shop_coupon', 'shop_order', 'product' ) ) ) {
$should_deliver = false;
}
@ -619,6 +619,9 @@ class WC_Webhook {
'coupon.deleted' => array(
'wp_trash_post',
),
'coupon.restored' => array(
'untrashed_post',
),
'customer.created' => array(
'user_register',
'woocommerce_created_customer',
@ -646,6 +649,9 @@ class WC_Webhook {
'order.deleted' => array(
'wp_trash_post',
),
'order.restored' => array(
'untrashed_post',
),
'product.created' => array(
'woocommerce_process_product_meta',
'woocommerce_api_create_product',
@ -659,6 +665,9 @@ class WC_Webhook {
'product.deleted' => array(
'wp_trash_post',
),
'product.restored' => array(
'untrashed_post',
),
);
$topic_hooks = apply_filters( 'woocommerce_webhook_topic_hooks', $topic_hooks, $this );

View File

@ -351,7 +351,7 @@ function wc_is_webhook_valid_topic( $topic ) {
}
$valid_resources = apply_filters( 'woocommerce_valid_webhook_resources', array( 'coupon', 'customer', 'order', 'product' ) );
$valid_events = apply_filters( 'woocommerce_valid_webhook_events', array( 'created', 'updated', 'deleted' ) );
$valid_events = apply_filters( 'woocommerce_valid_webhook_events', array( 'created', 'updated', 'deleted', 'restored' ) );
if ( in_array( $resource, $valid_resources ) && in_array( $event, $valid_events ) ) {
return true;

View File

@ -49,15 +49,18 @@ class WC_Tests_Conditional_Functions extends WC_Unit_Test_Case {
array( true, wc_is_webhook_valid_topic( 'product.created' ) ),
array( true, wc_is_webhook_valid_topic( 'product.updated' ) ),
array( true, wc_is_webhook_valid_topic( 'product.deleted' ) ),
array( true, wc_is_webhook_valid_topic( 'product.restored' ) ),
array( true, wc_is_webhook_valid_topic( 'order.created' ) ),
array( true, wc_is_webhook_valid_topic( 'order.updated' ) ),
array( true, wc_is_webhook_valid_topic( 'order.deleted' ) ),
array( true, wc_is_webhook_valid_topic( 'order.restored' ) ),
array( true, wc_is_webhook_valid_topic( 'customer.created' ) ),
array( true, wc_is_webhook_valid_topic( 'customer.updated' ) ),
array( true, wc_is_webhook_valid_topic( 'customer.deleted' ) ),
array( true, wc_is_webhook_valid_topic( 'coupon.created' ) ),
array( true, wc_is_webhook_valid_topic( 'coupon.updated' ) ),
array( true, wc_is_webhook_valid_topic( 'coupon.deleted' ) ),
array( true, wc_is_webhook_valid_topic( 'coupon.restored' ) ),
array( false, wc_is_webhook_valid_topic( 'coupon.upgraded' ) ),
array( false, wc_is_webhook_valid_topic( 'wc.product.updated' ) ),
array( false, wc_is_webhook_valid_topic( 'missingdot' ) ),