Abstracted transient helper to class #3282
This commit is contained in:
parent
973e6d94b8
commit
64c75547f3
|
@ -759,7 +759,7 @@ function woocommerce_admin_product_quick_edit_save( $post_id, $post ) {
|
|||
}
|
||||
|
||||
// Clear transient
|
||||
$woocommerce->clear_product_transients( $post_id );
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $post_id );
|
||||
}
|
||||
|
||||
add_action( 'save_post', 'woocommerce_admin_product_quick_edit_save', 10, 2 );
|
||||
|
@ -1156,7 +1156,7 @@ function woocommerce_admin_product_bulk_edit_save( $post_id, $post ) {
|
|||
do_action( 'woocommerce_product_bulk_edit_save', $product );
|
||||
|
||||
// Clear transient
|
||||
$woocommerce->clear_product_transients( $post_id );
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $post_id );
|
||||
}
|
||||
|
||||
add_action( 'save_post', 'woocommerce_admin_product_bulk_edit_save', 10, 2 );
|
||||
|
|
|
@ -890,7 +890,7 @@ function woocommerce_process_product_meta( $post_id, $post ) {
|
|||
}
|
||||
|
||||
// Clear cache/transients
|
||||
$woocommerce->clear_product_transients( $clear_id );
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $clear_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1021,7 +1021,7 @@ function woocommerce_process_product_meta( $post_id, $post ) {
|
|||
do_action( 'woocommerce_process_product_meta_' . $product_type, $post_id );
|
||||
|
||||
// Clear cache/transients
|
||||
$woocommerce->clear_product_transients( $post_id );
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $post_id );
|
||||
}
|
||||
|
||||
add_action('woocommerce_process_product_meta', 'woocommerce_process_product_meta', 1, 2);
|
||||
|
|
|
@ -105,12 +105,12 @@ function woocommerce_delete_post( $id ) {
|
|||
wp_update_post( $child_post );
|
||||
}
|
||||
|
||||
$woocommerce->clear_product_transients();
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients();
|
||||
|
||||
break;
|
||||
case 'product_variation' :
|
||||
|
||||
$woocommerce->clear_product_transients();
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients();
|
||||
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -87,7 +87,7 @@ function do_install_woocommerce() {
|
|||
}
|
||||
|
||||
// Clear transient cache
|
||||
$woocommerce->clear_product_transients();
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients();
|
||||
|
||||
// Recompile LESS styles if they are custom
|
||||
if ( get_option( 'woocommerce_frontend_css' ) == 'yes' ) {
|
||||
|
|
|
@ -134,7 +134,7 @@ if ( ! function_exists( 'woocommerce_settings' ) ) {
|
|||
}
|
||||
|
||||
// Clear any unwanted data
|
||||
$woocommerce->clear_product_transients();
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients();
|
||||
|
||||
delete_transient( 'woocommerce_cache_excluded_uris' );
|
||||
|
||||
|
|
|
@ -586,7 +586,7 @@ function woocommerce_status_tools() {
|
|||
|
||||
switch ( $_GET['action'] ) {
|
||||
case "clear_transients" :
|
||||
$woocommerce->clear_product_transients();
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients();
|
||||
|
||||
echo '<div class="updated"><p>' . __( 'Product Transients Cleared', 'woocommerce' ) . '</p></div>';
|
||||
break;
|
||||
|
|
|
@ -168,7 +168,7 @@ class WC_Product {
|
|||
elseif ( $this->backorders_allowed() || $this->get_total_stock() > 0 )
|
||||
$this->set_stock_status( 'instock' );
|
||||
|
||||
$woocommerce->clear_product_transients( $this->id ); // Clear transient
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
|
||||
|
||||
return $this->get_stock_quantity();
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ class WC_Product {
|
|||
if ( ! $this->backorders_allowed() && $this->get_total_stock() <= 0 )
|
||||
$this->set_stock_status( 'outofstock' );
|
||||
|
||||
$woocommerce->clear_product_transients( $this->id ); // Clear transient
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
|
||||
|
||||
return $this->get_stock_quantity();
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ class WC_Product {
|
|||
if ( $this->backorders_allowed() || $this->get_total_stock() > 0 )
|
||||
$this->set_stock_status( 'instock' );
|
||||
|
||||
$woocommerce->clear_product_transients( $this->id ); // Clear transient
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
|
||||
|
||||
return $this->get_stock_quantity();
|
||||
}
|
||||
|
|
|
@ -70,6 +70,6 @@ class WC_Product_Simple extends WC_Product {
|
|||
}
|
||||
}
|
||||
|
||||
$woocommerce->clear_product_transients( $this->id );
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id );
|
||||
}
|
||||
}
|
|
@ -87,7 +87,7 @@ class WC_Product_Variable extends WC_Product {
|
|||
elseif ( $this->backorders_allowed() || $this->get_total_stock() > 0 )
|
||||
$this->set_stock_status( 'instock' );
|
||||
|
||||
$woocommerce->clear_product_transients( $this->id ); // Clear transient
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
|
||||
|
||||
return apply_filters( 'woocommerce_stock_amount', $this->stock );
|
||||
}
|
||||
|
@ -112,7 +112,7 @@ class WC_Product_Variable extends WC_Product {
|
|||
if ( ! $this->backorders_allowed() && $this->get_total_stock() <= 0 )
|
||||
$this->set_stock_status( 'outofstock' );
|
||||
|
||||
$woocommerce->clear_product_transients( $this->id ); // Clear transient
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
|
||||
|
||||
return apply_filters( 'woocommerce_stock_amount', $this->stock );
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ class WC_Product_Variable extends WC_Product {
|
|||
if ( $this->backorders_allowed() || $this->get_total_stock() > 0 )
|
||||
$this->set_stock_status( 'instock' );
|
||||
|
||||
$woocommerce->clear_product_transients( $this->id ); // Clear transient
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
|
||||
|
||||
return apply_filters( 'woocommerce_stock_amount', $this->stock );
|
||||
endif;
|
||||
|
@ -506,7 +506,7 @@ class WC_Product_Variable extends WC_Product {
|
|||
update_post_meta( $this->id, '_min_variation_sale_price', $this->min_variation_sale_price );
|
||||
update_post_meta( $this->id, '_max_variation_sale_price', $this->max_variation_sale_price );
|
||||
|
||||
$woocommerce->clear_product_transients( $this->id );
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id );
|
||||
}
|
||||
}
|
||||
}
|
|
@ -297,7 +297,7 @@ class WC_Product_Variation extends WC_Product {
|
|||
$this->stock = intval( $amount );
|
||||
$this->total_stock = intval( $amount );
|
||||
update_post_meta( $this->variation_id, '_stock', $this->stock );
|
||||
$woocommerce->clear_product_transients( $this->id ); // Clear transient
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
|
||||
|
||||
// Check parents out of stock attribute
|
||||
if ( ! $this->is_in_stock() ) {
|
||||
|
@ -337,7 +337,7 @@ class WC_Product_Variation extends WC_Product {
|
|||
$this->stock = $this->stock - $by;
|
||||
$this->total_stock = $this->total_stock - $by;
|
||||
update_post_meta( $this->variation_id, '_stock', $this->stock );
|
||||
$woocommerce->clear_product_transients( $this->id ); // Clear transient
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
|
||||
|
||||
// Check parents out of stock attribute
|
||||
if ( ! $this->is_in_stock() ) {
|
||||
|
@ -375,7 +375,7 @@ class WC_Product_Variation extends WC_Product {
|
|||
$this->stock = $this->stock + $by;
|
||||
$this->total_stock = $this->total_stock + $by;
|
||||
update_post_meta( $this->variation_id, '_stock', $this->stock );
|
||||
$woocommerce->clear_product_transients( $this->id ); // Clear transient
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $this->id ); // Clear transient
|
||||
|
||||
// Parents out of stock attribute
|
||||
if ( $this->is_in_stock() )
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
<?php
|
||||
|
||||
return new WC_Transient_Helper();
|
||||
|
||||
class WC_Transient_Helper extends WC_Helper {
|
||||
/**
|
||||
* Clear all transients cache for product data.
|
||||
*
|
||||
* @access public
|
||||
* @param int $post_id (default: 0)
|
||||
* @return void
|
||||
*/
|
||||
public function clear_product_transients( $post_id = 0 ) {
|
||||
global $wpdb;
|
||||
|
||||
$post_id = absint( $post_id );
|
||||
|
||||
$wpdb->show_errors();
|
||||
|
||||
// Clear core transients
|
||||
$transients_to_clear = array(
|
||||
'wc_products_onsale',
|
||||
'wc_hidden_product_ids',
|
||||
'wc_hidden_product_ids_search',
|
||||
'wc_attribute_taxonomies',
|
||||
'wc_term_counts'
|
||||
);
|
||||
|
||||
foreach( $transients_to_clear as $transient ) {
|
||||
delete_transient( $transient );
|
||||
}
|
||||
|
||||
// Clear transients for which we don't have the name
|
||||
$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_%')" );
|
||||
|
||||
// Clear product specific transients
|
||||
$post_transients_to_clear = array(
|
||||
'wc_product_children_ids_',
|
||||
'wc_product_total_stock_',
|
||||
'wc_average_rating_',
|
||||
'wc_rating_count_',
|
||||
'woocommerce_product_type_', // No longer used
|
||||
'wc_product_type_', // No longer used
|
||||
);
|
||||
|
||||
if ( $post_id > 0 ) {
|
||||
|
||||
foreach( $post_transients_to_clear as $transient ) {
|
||||
delete_transient( $transient . $post_id );
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->options` WHERE `option_name` = %s OR `option_name` = %s", '_transient_' . $transient . $post_id, '_transient_timeout_' . $transient . $post_id ) );
|
||||
}
|
||||
|
||||
clean_post_cache( $post_id );
|
||||
|
||||
} else {
|
||||
|
||||
foreach( $post_transients_to_clear 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 . '%' ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
|
@ -744,7 +744,7 @@ function woocommerce_link_all_variations() {
|
|||
break;
|
||||
}
|
||||
|
||||
$woocommerce->clear_product_transients( $post_id );
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $post_id );
|
||||
|
||||
echo $added;
|
||||
|
||||
|
|
|
@ -2412,7 +2412,7 @@ function woocommerce_scheduled_sales() {
|
|||
update_post_meta( $product_id, '_sale_price_dates_to', '' );
|
||||
}
|
||||
|
||||
$woocommerce->clear_product_transients( $product_id );
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $product_id );
|
||||
|
||||
$parent = wp_get_post_parent_id( $product_id );
|
||||
|
||||
|
@ -2426,7 +2426,7 @@ function woocommerce_scheduled_sales() {
|
|||
if ( $this_product->is_type( 'simple' ) )
|
||||
$this_product->grouped_product_sync();
|
||||
|
||||
$woocommerce->clear_product_transients( $parent );
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $parent );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2453,7 +2453,7 @@ function woocommerce_scheduled_sales() {
|
|||
update_post_meta( $product_id, '_sale_price_dates_from', '' );
|
||||
update_post_meta( $product_id, '_sale_price_dates_to', '' );
|
||||
|
||||
$woocommerce->clear_product_transients( $product_id );
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $product_id );
|
||||
|
||||
$parent = wp_get_post_parent_id( $product_id );
|
||||
|
||||
|
@ -2467,7 +2467,7 @@ function woocommerce_scheduled_sales() {
|
|||
if ( $this_product->is_type( 'simple' ) )
|
||||
$this_product->grouped_product_sync();
|
||||
|
||||
$woocommerce->clear_product_transients( $parent );
|
||||
$woocommerce->get_helper( 'transient' )->clear_product_transients( $parent );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1430,68 +1430,6 @@ class Woocommerce {
|
|||
return ob_get_clean();
|
||||
}
|
||||
|
||||
/** Transients ************************************************************/
|
||||
|
||||
/**
|
||||
* Clear all transients cache for product data.
|
||||
*
|
||||
* @access public
|
||||
* @param int $post_id (default: 0)
|
||||
* @return void
|
||||
*/
|
||||
public function clear_product_transients( $post_id = 0 ) {
|
||||
global $wpdb;
|
||||
|
||||
$post_id = absint( $post_id );
|
||||
|
||||
$wpdb->show_errors();
|
||||
|
||||
// Clear core transients
|
||||
$transients_to_clear = array(
|
||||
'wc_products_onsale',
|
||||
'wc_hidden_product_ids',
|
||||
'wc_hidden_product_ids_search',
|
||||
'wc_attribute_taxonomies',
|
||||
'wc_term_counts'
|
||||
);
|
||||
|
||||
foreach( $transients_to_clear as $transient ) {
|
||||
delete_transient( $transient );
|
||||
}
|
||||
|
||||
// Clear transients for which we don't have the name
|
||||
$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_%')" );
|
||||
|
||||
// Clear product specific transients
|
||||
$post_transients_to_clear = array(
|
||||
'wc_product_children_ids_',
|
||||
'wc_product_total_stock_',
|
||||
'wc_average_rating_',
|
||||
'wc_rating_count_',
|
||||
'woocommerce_product_type_', // No longer used
|
||||
'wc_product_type_', // No longer used
|
||||
);
|
||||
|
||||
if ( $post_id > 0 ) {
|
||||
|
||||
foreach( $post_transients_to_clear as $transient ) {
|
||||
delete_transient( $transient . $post_id );
|
||||
$wpdb->query( $wpdb->prepare( "DELETE FROM `$wpdb->options` WHERE `option_name` = %s OR `option_name` = %s", '_transient_' . $transient . $post_id, '_transient_timeout_' . $transient . $post_id ) );
|
||||
}
|
||||
|
||||
clean_post_cache( $post_id );
|
||||
|
||||
} else {
|
||||
|
||||
foreach( $post_transients_to_clear 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 . '%' ) );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/** Body Classes **********************************************************/
|
||||
|
||||
/**
|
||||
|
@ -1628,6 +1566,20 @@ class Woocommerce {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear all transients cache for product data.
|
||||
*
|
||||
* @deprecated 2.1.0 Access via the helpers
|
||||
* @access public
|
||||
* @param int $post_id (default: 0)
|
||||
* @return void
|
||||
*/
|
||||
public function clear_product_transients( $post_id = 0 ) {
|
||||
_deprecated_function( 'Woocommerce->clear_product_transients', '2.1', 'WC_Transient_Helper->clear_product_transients' );
|
||||
$helper = $this->get_helper( 'transient' );
|
||||
$helper->clear_product_transients( $post_id );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue