• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
WooCommerce a2z

WooCommerce a2z

WooCommerce

  • Home
  • Plugins
  • Blocks
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / ActionScheduler_wpCommentLogger::get_comment_count() – Retrieve the comment counts from our cache, or the database if the cached version isn’t set.

You appear to be a bot. Output may be restricted

Description

Retrieve the comment counts from our cache, or the database if the cached version isn't set.

Usage

$object = ActionScheduler_wpCommentLogger::get_comment_count();

Parameters

Returns

object

Source

File name: woocommerce/packages/action-scheduler/classes/data-stores/ActionScheduler_wpCommentLogger.php
Lines:

1 to 39 of 39
  protected function get_comment_count() {
    global $wpdb;

    $stats = get_transient( 'as_comment_count' );

    if ( ! $stats ) {
      $stats = array();

      $count = $wpdb->get_results( "SELECT comment_approved, COUNT( * ) AS num_comments FROM {$wpdb->comments} WHERE comment_type NOT IN('order_note','action_log') GROUP BY comment_approved", ARRAY_A );

      $total = 0;
      $stats = array();
      $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( 'as_comment_count', $stats );
    }

    return $stats;
  }
 

 View on GitHub View on Trac

Published: 6th April 2020 | Last updated: 6th April 2020

Primary Sidebar

Information

Function name: ActionScheduler_wpCommentLogger::get_comment_count
Class ref: ActionScheduler_wpCommentLogger
Plugin ref: WooCommerce
Version: 5.1.0
Sourcefile: packages/action-scheduler/classes/data-stores/ActionScheduler_wpCommentLogger.php
File ref: packages/action-scheduler/classes/data-stores/ActionScheduler_wpCommentLogger.php
Deprecated?: No
API Letters: A,C,G,W

Footer

WooCommerce a2z
WooCommerce a2z
WooCommerce
WordPress 5.7.1
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:  woocommerce.wp-a2z.org
© Copyright WooCommerce a2z 2014-2021. All rights reserved.


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

  • Home
  • Blog
  • Sitemap
  • Sites