Merge pull request #17975 from woocommerce/refactor/12439-trigger-webhook

Trigger webhook when delivery URL is changed
This commit is contained in:
Claudiu Lodromanean 2017-11-30 11:12:51 -08:00 committed by GitHub
commit 4e2e64ad2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -536,7 +536,8 @@ class WC_Webhook extends WC_Legacy_Webhook {
return new WP_Error( 'error', sprintf( __( 'Error: Delivery URL returned response code: %s', 'woocommerce' ), absint( $response_code ) ) );
}
delete_post_meta( $this->get_id(), '_webhook_pending_delivery' );
$this->set_pending_delivery( false );
$this->save();
return true;
}
@ -771,7 +772,6 @@ class WC_Webhook extends WC_Legacy_Webhook {
/**
* Set the delivery URL.
*
* @todo trigger webhook when set new delivery URL.
* @since 2.2.0
* @param string $url Delivery URL.
*/

View File

@ -112,6 +112,8 @@ class WC_Webhook_Data_Store implements WC_Webhook_Data_Store_Interface {
global $wpdb;
$changes = $webhook->get_changes();
$trigger = isset( $changes['delivery_url'] );
if ( isset( $changes['date_modified'] ) ) {
$date_modified = $webhook->get_date_modified()->date( 'Y-m-d H:i:s' );
$date_modified_gmt = gmdate( 'Y-m-d H:i:s', $webhook->get_date_modified()->getTimestamp() );
@ -147,6 +149,11 @@ class WC_Webhook_Data_Store implements WC_Webhook_Data_Store_Interface {
wp_cache_delete( $webhook->get_id(), 'webhooks' );
WC_Cache_Helper::incr_cache_prefix( 'webhooks' );
if ( $trigger || $webhook->get_pending_delivery() ) {
$webhook->deliver_ping();
}
do_action( 'woocommerce_webhook_updated', $webhook->get_id() );
}