moved exclude order notes from wp_count_comments to class-wc-comments.php

This commit is contained in:
claudiosmweb 2014-08-12 12:13:29 -03:00
parent eb8d99f4ea
commit 6e21079d76
2 changed files with 52 additions and 51 deletions

View File

@ -33,10 +33,13 @@ class WC_Comments {
add_action( 'comment_feed_join', array( __CLASS__, 'exclude_order_comments_from_feed_join' ) );
add_action( 'comment_feed_where', array( __CLASS__, 'exclude_order_comments_from_feed_where' ) );
// secure webhook comments
// Secure webhook comments
add_filter( 'comments_clauses', array( __CLASS__, 'exclude_webhook_comments' ), 10, 1 );
add_action( 'comment_feed_join', array( __CLASS__, 'exclude_webhook_comments_from_feed_join' ) );
add_action( 'comment_feed_where', array( __CLASS__, 'exclude_webhook_comments_from_feed_where' ) );
// Count comments
add_filter( 'wp_count_comments', array( __CLASS__, 'wp_count_comments' ), 10, 2 );
}
/**
@ -211,6 +214,53 @@ class WC_Comments {
delete_transient( 'wc_average_rating_' . absint( $post_id ) );
delete_transient( 'wc_rating_count_' . absint( $post_id ) );
}
/**
* Remove order notes from wp_count_comments()
*
* @since 2.2
* @param object $stats
* @param int $post_id
* @return object
*/
public static function wp_count_comments( $stats, $post_id ) {
global $wpdb;
if ( 0 === $post_id ) {
$count = wp_cache_get( 'comments-0', 'counts' );
if ( false !== $count ) {
return $count;
}
$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type != 'order_note' GROUP BY comment_approved", ARRAY_A );
$total = 0;
$approved = array( '0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed' );
foreach ( (array) $count as $row ) {
// Don't count post-trashed toward totals
if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) {
$total += $row['num_comments'];
}
if ( isset( $approved[ $row['comment_approved'] ] ) ) {
$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
}
}
$stats['total_comments'] = $total;
foreach ( $approved as $key ) {
if ( empty( $stats[ $key ] ) ) {
$stats[ $key ] = 0;
}
}
$stats = (object) $stats;
wp_cache_set( 'comments-0', $stats, 'counts' );
}
return $stats;
}
}
WC_Comments::init();

View File

@ -540,7 +540,7 @@ add_filter( 'rewrite_rules_array', 'wc_fix_rewrite_rules' );
/**
* Prevent product attachment links from breaking when using complex rewrite structures.
*
*
* @param string $link
* @param id $post_id
* @return string
@ -582,55 +582,6 @@ function wc_ms_protect_download_rewite_rules( $rewrite ) {
}
add_filter( 'mod_rewrite_rules', 'wc_ms_protect_download_rewite_rules' );
/**
* Remove order notes from wp_count_comments()
*
* @since 2.2
* @param object $stats
* @param int $post_id
* @return object
*/
function wc_remove_order_notes_from_wp_count_comments( $stats, $post_id ) {
global $wpdb;
if ( 0 === $post_id ) {
$count = wp_cache_get( 'comments-0', 'counts' );
if ( false !== $count ) {
return $count;
}
$count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type != 'order_note' GROUP BY comment_approved", ARRAY_A );
$total = 0;
$approved = array( '0' => 'moderated', '1' => 'approved', 'spam' => 'spam', 'trash' => 'trash', 'post-trashed' => 'post-trashed' );
foreach ( (array) $count as $row ) {
// Don't count post-trashed toward totals
if ( 'post-trashed' != $row['comment_approved'] && 'trash' != $row['comment_approved'] ) {
$total += $row['num_comments'];
}
if ( isset( $approved[ $row['comment_approved'] ] ) ) {
$stats[ $approved[ $row['comment_approved'] ] ] = $row['num_comments'];
}
}
$stats['total_comments'] = $total;
foreach ( $approved as $key ) {
if ( empty( $stats[ $key ] ) ) {
$stats[ $key ] = 0;
}
}
$stats = (object) $stats;
wp_cache_set( 'comments-0', $stats, 'counts' );
}
return $stats;
}
add_filter( 'wp_count_comments', 'wc_remove_order_notes_from_wp_count_comments', 10, 2 );
/**
* WooCommerce Core Supported Themes
*