From 51f71cfadee0b771545e84577910134378de16c5 Mon Sep 17 00:00:00 2001 From: Max Rice Date: Wed, 30 Jul 2014 16:27:50 -0400 Subject: [PATCH] Load webhooks on each page load Part of #5564 --- woocommerce.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/woocommerce.php b/woocommerce.php index 1982f27b22d..6fa3af9ba62 100644 --- a/woocommerce.php +++ b/woocommerce.php @@ -402,6 +402,9 @@ final class WooCommerce { add_action( $action, array( $this, 'send_transactional_email' ), 10, 10 ); } + // webhooks + $this->load_webhooks(); + // Init action do_action( 'woocommerce_init' ); } @@ -439,7 +442,7 @@ final class WooCommerce { // Post thumbnail support if ( ! current_theme_supports( 'post-thumbnails' ) ) { - add_theme_support( 'post-thumbnails' ); + add_theme_support( 'post-thumbnails' ); } add_post_type_support( 'product', 'thumbnail' ); @@ -547,6 +550,30 @@ final class WooCommerce { do_action_ref_array( current_filter() . '_notification', $args ); } + /** + * Load & enqueue active webhooks + * + * @since 2.2 + */ + public function load_webhooks() { + + $args = array( + 'fields' => 'ids', + 'post_type' => 'shop_webhook', + 'post_status' => 'publish', + ); + + $query = new WP_Query( $args ); + + if ( ! empty( $query->posts ) ) { + + foreach ( $query->posts as $id ) { + $webhook = new WC_Webhook( $id ); + $webhook->enqueue(); + } + } + } + /** Load Instances on demand **********************************************/ /**