WordPress.org

Make WordPress Core

Ticket #19903: 19903.diff

File 19903.diff, 3.9 KB (added by markjaquith, 6 years ago)
  • wp-includes/comment.php

    function get_lastcommentmodified($timezone = 'server') { 
    430430        return $lastcommentmodified;
    431431}
    432432
    433 /**
    434  * The amount of comments in a post or total comments.
    435  *
    436  * A lot like {@link wp_count_comments()}, in that they both return comment
    437  * stats (albeit with different types). The {@link wp_count_comments()} actual
    438  * caches, but this function does not.
    439  *
    440  * @since 2.0.0
    441  * @uses $wpdb
    442  *
    443  * @param int $post_id Optional. Comment amount in post if > 0, else total comments blog wide.
    444  * @return array The amount of spam, approved, awaiting moderation, and total comments.
    445  */
    446 function get_comment_count( $post_id = 0 ) {
    447         global $wpdb;
    448 
    449         $post_id = (int) $post_id;
    450 
    451         $where = '';
    452         if ( $post_id > 0 ) {
    453                 $where = $wpdb->prepare("WHERE comment_post_ID = %d", $post_id);
    454         }
    455 
    456         $totals = (array) $wpdb->get_results("
    457                 SELECT comment_approved, COUNT( * ) AS total
    458                 FROM {$wpdb->comments}
    459                 {$where}
    460                 GROUP BY comment_approved
    461         ", ARRAY_A);
    462 
    463         $comment_count = array(
    464                 "approved"              => 0,
    465                 "awaiting_moderation"   => 0,
    466                 "spam"                  => 0,
    467                 "total_comments"        => 0
    468         );
    469 
    470         foreach ( $totals as $row ) {
    471                 switch ( $row['comment_approved'] ) {
    472                         case 'spam':
    473                                 $comment_count['spam'] = $row['total'];
    474                                 $comment_count["total_comments"] += $row['total'];
    475                                 break;
    476                         case 1:
    477                                 $comment_count['approved'] = $row['total'];
    478                                 $comment_count['total_comments'] += $row['total'];
    479                                 break;
    480                         case 0:
    481                                 $comment_count['awaiting_moderation'] = $row['total'];
    482                                 $comment_count['total_comments'] += $row['total'];
    483                                 break;
    484                         default:
    485                                 break;
    486                 }
    487         }
    488 
    489         return $comment_count;
    490 }
    491 
    492433//
    493434// Comment meta functions
    494435//
  • wp-includes/deprecated.php

    function is_blog_user( $blog_id = 0 ) { 
    28642864
    28652865        return is_user_member_of_blog( get_current_user_id(), $blog_id );
    28662866}
     2867
     2868/**
     2869 * The amount of comments in a post or total comments.
     2870 *
     2871 * A lot like {@link wp_count_comments()}, in that they both return comment
     2872 * stats (albeit with different types). The {@link wp_count_comments()} actual
     2873 * caches, but this function does not.
     2874 *
     2875 * @since 2.0.0
     2876 * @deprecated 3.4
     2877 * @deprecated Use wp_count_comments()
     2878 * @uses $wpdb
     2879 *
     2880 * @param int $post_id Optional. Comment amount in post if > 0, else total comments blog wide.
     2881 * @return array The amount of spam, approved, awaiting moderation, and total comments.
     2882 */
     2883function get_comment_count( $post_id = 0 ) {
     2884        _deprecated_function( __FUNCTION__, '3.4', 'wp_count_comments()' );
     2885        global $wpdb;
     2886
     2887        $post_id = (int) $post_id;
     2888
     2889        $where = '';
     2890        if ( $post_id > 0 ) {
     2891                $where = $wpdb->prepare("WHERE comment_post_ID = %d", $post_id);
     2892        }
     2893
     2894        $totals = (array) $wpdb->get_results("
     2895                SELECT comment_approved, COUNT( * ) AS total
     2896                FROM {$wpdb->comments}
     2897                {$where}
     2898                GROUP BY comment_approved
     2899        ", ARRAY_A);
     2900
     2901        $comment_count = array(
     2902                "approved"              => 0,
     2903                "awaiting_moderation"   => 0,
     2904                "spam"                  => 0,
     2905                "total_comments"        => 0
     2906        );
     2907
     2908        foreach ( $totals as $row ) {
     2909                switch ( $row['comment_approved'] ) {
     2910                        case 'spam':
     2911                                $comment_count['spam'] = $row['total'];
     2912                                $comment_count["total_comments"] += $row['total'];
     2913                                break;
     2914                        case 1:
     2915                                $comment_count['approved'] = $row['total'];
     2916                                $comment_count['total_comments'] += $row['total'];
     2917                                break;
     2918                        case 0:
     2919                                $comment_count['awaiting_moderation'] = $row['total'];
     2920                                $comment_count['total_comments'] += $row['total'];
     2921                                break;
     2922                        default:
     2923                                break;
     2924                }
     2925        }
     2926
     2927        return $comment_count;
     2928}