From 2b5351ae95ec1cae0799cb12704dd6f125cadf52 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Thu, 20 Mar 2014 11:20:54 +0000 Subject: [PATCH] Related to #5041, there is not a way to retrieve these dynamic transient names and use delete_transient, so if using object caching we must flush --- includes/wc-product-functions.php | 47 ++++++++----------------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/includes/wc-product-functions.php b/includes/wc-product-functions.php index 956ba02d22f..cf7a90f5d23 100644 --- a/includes/wc-product-functions.php +++ b/includes/wc-product-functions.php @@ -79,6 +79,11 @@ function wc_product_dimensions_enabled() { function wc_delete_product_transients( $post_id = 0 ) { global $wpdb; + if ( wp_using_ext_object_cache() ) { + wp_cache_flush(); // There isn't a reliable method of looking up the names, so flush the cache. + return; + } + $post_id = absint( $post_id ); // Clear core transients @@ -91,23 +96,10 @@ function wc_delete_product_transients( $post_id = 0 ) { ); // Clear transients for which we don't have the name - if ( wp_using_ext_object_cache() ) { - global $wp_object_cache; - - if ( isset( $wp_object_cache->cache['transient'] ) ) { - $keys = array_keys( $wp_object_cache->cache['transient'] ); - foreach ( $keys as $key ) { - if ( strpos( $key, 'wc_uf_pid_' ) === 0 || strpos( $key, 'wc_ship_' ) === 0 || strpos( $key, 'wc_products_will_display_' ) === 0 || strpos( $key, 'wc_ln_count_' ) === 0 ) { - $transients_to_clear[] = $key; - } - } - } - } else { - $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_uf_pid_%') OR `option_name` LIKE ('_transient_timeout_wc_uf_pid_%')" ); - $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_ln_count_%') OR `option_name` LIKE ('_transient_timeout_wc_ln_count_%')" ); - $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_ship_%') OR `option_name` LIKE ('_transient_timeout_wc_ship_%')" ); - $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_products_will_display_%') OR `option_name` LIKE ('_transient_timeout_wc_products_will_display_%')" ); - } + $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_uf_pid_%') OR `option_name` LIKE ('_transient_timeout_wc_uf_pid_%')" ); + $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_ln_count_%') OR `option_name` LIKE ('_transient_timeout_wc_ln_count_%')" ); + $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_ship_%') OR `option_name` LIKE ('_transient_timeout_wc_ship_%')" ); + $wpdb->query( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE ('_transient_wc_products_will_display_%') OR `option_name` LIKE ('_transient_timeout_wc_products_will_display_%')" ); // Clear product specific transients $post_transient_names = array( @@ -122,27 +114,12 @@ function wc_delete_product_transients( $post_id = 0 ) { $transients_to_clear[] = $transient . $post_id; } } else { - if ( wp_using_ext_object_cache() ) { - global $wp_object_cache; - - if ( isset( $wp_object_cache->cache['transient'] ) ) { - $keys = array_keys( $wp_object_cache->cache['transient'] ); - foreach( $post_transient_names as $transient ) { - foreach ( $keys as $key ) { - if ( strpos( $key, $transient ) === 0 ) { - $transients_to_clear[] = $key; - } - } - } - } - } else { - foreach( $post_transient_names as $transient ) { - $wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE %s OR `option_name` LIKE %s", '_transient_' . $transient . '%', '_transient_timeout_' . $transient . '%' ) ); - } + foreach( $post_transient_names as $transient ) { + $wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->options` WHERE `option_name` LIKE %s OR `option_name` LIKE %s", '_transient_' . $transient . '%', '_transient_timeout_' . $transient . '%' ) ); } } - // Clear transients where we have names + // Delete transients foreach( $transients_to_clear as $transient ) { delete_transient( $transient ); }