Clear comment transients only on wp_update_comment_count

Does not need to be flushed when editing a product. Part of #5777
This commit is contained in:
Mike Jolley 2014-07-03 12:01:51 +01:00
parent f8db5dff93
commit d1dbe4492e
3 changed files with 7 additions and 19 deletions

View File

@ -26,8 +26,7 @@ class WC_Comments {
add_action( 'comment_post', array( __CLASS__, 'add_comment_rating' ), 1 );
// clear transients
add_action( 'wp_set_comment_status', array( __CLASS__, 'clear_transients' ) );
add_action( 'edit_comment', array( __CLASS__, 'clear_transients' ) );
add_action( 'wp_update_comment_count', array( __CLASS__, 'clear_transients' ) );
// Secure order notes
add_filter( 'comments_clauses', array( __CLASS__, 'exclude_order_comments' ), 10, 1 );
@ -121,13 +120,11 @@ class WC_Comments {
*/
public static function add_comment_rating( $comment_id ) {
if ( isset( $_POST['rating'] ) ) {
if ( ! $_POST['rating'] || $_POST['rating'] > 5 || $_POST['rating'] < 0 )
if ( ! $_POST['rating'] || $_POST['rating'] > 5 || $_POST['rating'] < 0 ) {
return;
}
add_comment_meta( $comment_id, 'rating', (int) esc_attr( $_POST['rating'] ), true );
self::clear_transients( $comment_id );
}
}
@ -136,13 +133,9 @@ class WC_Comments {
*
* @param mixed $comment_id
*/
public static function clear_transients( $comment_id ) {
$comment = get_comment( $comment_id );
if ( ! empty( $comment->comment_post_ID ) ) {
delete_transient( 'wc_average_rating_' . absint( $comment->comment_post_ID ) );
delete_transient( 'wc_rating_count_' . absint( $comment->comment_post_ID ) );
}
public static function clear_transients( $post_id ) {
delete_transient( 'wc_average_rating_' . absint( $post_id ) );
delete_transient( 'wc_rating_count_' . absint( $post_id ) );
}
}

View File

@ -108,9 +108,6 @@ class WC_Install {
$this->create_files();
$this->create_css_from_less();
// Clear transient cache
wc_delete_product_transients();
// Queue upgrades
$current_version = get_option( 'woocommerce_version', null );
$current_db_version = get_option( 'woocommerce_db_version', null );

View File

@ -92,9 +92,7 @@ function wc_delete_product_transients( $post_id = 0 ) {
// Clear product specific transients
$post_transient_names = array(
'wc_product_children_ids_',
'wc_product_total_stock_',
'wc_average_rating_',
'wc_rating_count_'
'wc_product_total_stock_'
);
if ( $post_id > 0 ) {