Skip to content

Commit

Permalink
Clear comment transients only on wp_update_comment_count
Browse files Browse the repository at this point in the history
Does not need to be flushed when editing a product. Part of woocommerce#5777
  • Loading branch information
mikejolley committed Jul 3, 2014
1 parent f8db5df commit d1dbe44
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 19 deletions.
19 changes: 6 additions & 13 deletions includes/class-wc-comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public static function init() {
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 );
Expand Down Expand Up @@ -121,13 +120,11 @@ public static function check_comment_rating( $comment_data ) {
*/
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 );
}
}

Expand All @@ -136,13 +133,9 @@ public static function add_comment_rating( $comment_id ) {
*
* @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 ) );
}
}

Expand Down
3 changes: 0 additions & 3 deletions includes/class-wc-install.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ public function 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 );
Expand Down
4 changes: 1 addition & 3 deletions includes/wc-product-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down

0 comments on commit d1dbe44

Please sign in to comment.