• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Easy Digital Downloads a2z

Easy Digital Downloads a2z

Easy Digital Downloads a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / edd_remove_payment_notes_in_comment_counts() – Remove EDD Comments from the wp_count_comments function

You appear to be a bot. Output may be restricted

Description

Remove EDD Comments from the wp_count_comments function

Usage

$array = edd_remove_payment_notes_in_comment_counts( $stats, $post_id );

Parameters

$stats
( array ) required – (empty from core filter)
$post_id
( int ) required – Post ID

Returns

array Array of comment counts

Source

File name: easy-digital-downloads/includes/payments/functions.php
Lines:

1 to 46 of 46
function edd_remove_payment_notes_in_comment_counts( $stats, $post_id ) {
  global $wpdb, $pagenow;

  $array_excluded_pages = array( 'index.php', 'edit-comments.php' );
  if( ! in_array( $pagenow, $array_excluded_pages )  ) {
    return $stats;
  }

  $post_id = (int) $post_id;

  if ( apply_filters( 'edd_count_payment_notes_in_comments', false ) )
    return $stats;

  $stats = wp_cache_get( "comments-{$post_id}", 'counts' );

  if ( false !== $stats )
    return $stats;

  $where = 'WHERE comment_type != "edd_payment_note"';

  if ( $post_id > 0 )
    $where .= $wpdb->prepare( " AND comment_post_ID = %d", $post_id );

  $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} {$where} 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-{$post_id}", $stats, 'counts' );

  return $stats;
}
 

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 23rd February 2021

Primary Sidebar

Information

Function name: edd_remove_payment_notes_in_comment_counts
Plugin ref: Easy Digital Downloads
Version: 2.11.6
Sourcefile: includes/payments/functions.php
File ref: includes/payments/functions.php
Deprecated?: No
API Letters: E,I,N,P,R

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 5.9.3
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  edd.wp-a2z.org
© Copyright Easy Digital Downloads a2z 2014-2022. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites