id) && in_array( $screen->id, array( 'property', 'contact', 'enquiry', 'viewing', 'offer', 'sale' ) ) ) { return $clauses; // Don't hide when viewing Property Hive record } } $clauses['where'] .= ' AND comment_type != "propertyhive_note"'; return $clauses; } /** * Delete comments count cache whenever there is * new comment or the status of a comment changes. Cache * will be regenerated next time PH_Comments::wp_count_comments() * is called. * * @return void */ public static function delete_comments_count_cache() { delete_transient( 'ph_count_comments' ); } /** * Remove propertyhive notes from wp_count_comments(). * @since 1.0.0 * @param object $stats * @param int $post_id * @return object */ public static function wp_count_comments( $stats, $post_id ) { global $wpdb; if ( 0 === $post_id ) { $stats = get_transient( 'ph_count_comments' ); if ( ! $stats ) { $stats = array(); $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type != 'propertyhive_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; $stats['all'] = $total; foreach ( $approved as $key ) { if ( empty( $stats[ $key ] ) ) { $stats[ $key ] = 0; } } $stats = (object) $stats; set_transient( 'ph_count_comments', $stats ); } } return $stats; } } PH_Comments::init();