Add transient cache to webhooks Closes #7184
This commit is contained in:
parent
b289c9446c
commit
2d707689d9
|
@ -142,6 +142,8 @@ class WC_Admin_Webhooks {
|
|||
|
||||
do_action( 'woocommerce_webhook_options_save', $webhook->id );
|
||||
|
||||
delete_transient( 'woocommerce_webhook_ids' );
|
||||
|
||||
// Redirect to webhook edit page to avoid settings save actions
|
||||
wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=webhooks&edit-webhook=' . $webhook->id . '&updated=1' ) );
|
||||
exit();
|
||||
|
@ -171,6 +173,8 @@ class WC_Admin_Webhooks {
|
|||
|
||||
update_post_meta( $webhook_id, '_webhook_pending_delivery', true );
|
||||
|
||||
delete_transient( 'woocommerce_webhook_ids' );
|
||||
|
||||
// Redirect to edit page
|
||||
wp_redirect( admin_url( 'admin.php?page=wc-settings&tab=webhooks&edit-webhook=' . $webhook_id . '&created=1' ) );
|
||||
exit();
|
||||
|
@ -227,6 +231,8 @@ class WC_Admin_Webhooks {
|
|||
|
||||
$webhooks = array_map( 'absint', (array) $_GET['webhook'] );
|
||||
|
||||
delete_transient( 'woocommerce_webhook_ids' );
|
||||
|
||||
switch ( $_GET['action'] ) {
|
||||
case 'trash' :
|
||||
$this->bulk_trash( $webhooks );
|
||||
|
@ -237,7 +243,6 @@ class WC_Admin_Webhooks {
|
|||
case 'delete' :
|
||||
$this->bulk_trash( $webhooks, true );
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
@ -275,7 +280,6 @@ class WC_Admin_Webhooks {
|
|||
*/
|
||||
public function actions() {
|
||||
if ( $this->is_webhook_settings_page() ) {
|
||||
|
||||
// Save
|
||||
if ( isset( $_POST['save'] ) && isset( $_POST['webhook_id'] ) ) {
|
||||
$this->save();
|
||||
|
|
|
@ -217,6 +217,8 @@ class WC_API_Webhooks extends WC_API_Resource {
|
|||
|
||||
do_action( 'woocommerce_api_create_webhook', $webhook->id, $this );
|
||||
|
||||
delete_transient( 'woocommerce_webhook_ids' );
|
||||
|
||||
return $this->get_webhook( $webhook->id );
|
||||
|
||||
} catch ( WC_API_Exception $e ) {
|
||||
|
@ -298,6 +300,8 @@ class WC_API_Webhooks extends WC_API_Resource {
|
|||
|
||||
do_action( 'woocommerce_api_edit_webhook', $webhook->id, $this );
|
||||
|
||||
delete_transient( 'woocommerce_webhook_ids' );
|
||||
|
||||
return $this->get_webhook( $id );
|
||||
|
||||
} catch ( WC_API_Exception $e ) {
|
||||
|
@ -323,6 +327,8 @@ class WC_API_Webhooks extends WC_API_Resource {
|
|||
|
||||
do_action( 'woocommerce_api_delete_webhook', $id, $this );
|
||||
|
||||
delete_transient( 'woocommerce_webhook_ids' );
|
||||
|
||||
// no way to manage trashed webhooks at the moment, so force delete
|
||||
return $this->delete( $id, 'webhook', true );
|
||||
}
|
||||
|
|
|
@ -457,19 +457,18 @@ final class WooCommerce {
|
|||
* @since 2.2
|
||||
*/
|
||||
private function load_webhooks() {
|
||||
$args = array(
|
||||
if ( false === ( $webhooks = get_transient( 'woocommerce_webhook_ids' ) ) ) {
|
||||
$webhooks = get_posts( 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();
|
||||
'posts_per_page' => -1
|
||||
) );
|
||||
set_transient( 'woocommerce_webhook_ids', $webhooks );
|
||||
}
|
||||
foreach ( $webhooks as $webhook_id ) {
|
||||
$webhook = new WC_Webhook( $webhook_id );
|
||||
$webhook->enqueue();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue