WordPress.org

Plugin Directory

Changeset 1611510


Ignore:
Timestamp:
03/09/17 21:00:22 (3 months ago)
Author:
coffee2code
Message:

Release v1.8:

  • Change: Adopt WP core style of showing pending comments in a red circle superscript to comments bubble icon
  • Change: Show comments bubble in "Comments" column of user listings instead of plain integer
  • Change: Don't link comments bubble when there are zero comments since approved and pending comments are available as separate links
  • Change: Extract comments bubble markup generation from comment_author() into new get_comments_bubble()
  • Change: Remove support for pre-WP 4.3 markup
  • Change: Prevent object instantiation of the class
  • Change: Use sprintf() to produce markup rather than concatenating various strings, function calls, and variables
  • Change: Update unit test bootstrap
    • Default WP_TESTS_DIR to /tmp/wordpress-tests-lib rather than erroring out if not defined via environment variable
    • Enable more error output for unit tests
  • Change: Note compatibility through WP 4.7+
  • Change: Remove support for WordPress older than 4.6 (should still work for earlier versions back to WP 4.3)
  • Change: Update readme.txt content and formatting
  • Change: Update copyright date (2017)
  • Change: Update screenshots
  • New: Add LICENSE file
Location:
admin-commenters-comments-count
Files:
2 added
15 edited
1 copied

Legend:

Unmodified
Added
Removed
  • admin-commenters-comments-count/tags/1.8/admin-commenters-comments-count.php

    r1395943 r1611510  
    22/** 
    33 * Plugin Name: Admin Commenters Comments Count 
    4  * Version:     1.7 
     4 * Version:     1.8 
    55 * Plugin URI:  http://coffee2code.com/wp-plugins/admin-commenters-comments-count/ 
    66 * Author:      Scott Reilly 
     
    1111 * Description: Displays a count of each commenter's total number of comments (linked to those comments) next to their name on any admin page. 
    1212 * 
    13  * Compatible with WordPress 3.9 through 4.5+. 
     13 * Compatible with WordPress 4.6 through 4.7+. 
    1414 * 
    1515 * =>> Read the accompanying readme.txt file for instructions and documentation. 
     
    1919 * @package Admin_Commenters_Comments_Count 
    2020 * @author  Scott Reilly 
    21  * @version 1.7 
     21 * @version 1.8 
    2222 */ 
    2323 
     
    3434 
    3535/* 
    36     Copyright (c) 2009-2016 by Scott Reilly (aka coffee2code) 
     36    Copyright (c) 2009-2017 by Scott Reilly (aka coffee2code) 
    3737 
    3838    This program is free software; you can redistribute it and/or 
     
    8686 
    8787    /** 
     88     * Prevent instantiation. 
     89     * 
     90     * @since 1.8 
     91     */ 
     92    private function __construct() {} 
     93 
     94    /** 
     95     * Prevent unserializing an instance. 
     96     * 
     97     * @since 1.8 
     98     */ 
     99    private function __wakeup() {} 
     100 
     101    /** 
    88102     * Returns version of the plugin. 
    89103     * 
     
    91105     */ 
    92106    public static function version() { 
    93         return '1.7'; 
     107        return '1.8'; 
    94108    } 
    95109 
     
    169183        $user = get_user_by( 'id', $user_id ); 
    170184 
    171         list( $comment_count, $pending_count )  = self::get_comments_count( 'comment_author_email', $user->user_email, 'comment', $user->ID ); 
    172  
    173         $show_link = ( $comment_count + $pending_count ) > 0; 
    174  
    175         $ret = ''; 
    176  
    177         if ( $show_link ) { 
    178             $msg = sprintf( _n( '%d comment', '%d comments', $comment_count, 'admin-commenters-comments-count' ), $comment_count ); 
    179  
    180             if ( $pending_count ) { 
    181                 $msg .= '; ' . sprintf( __( '%s pending', 'admin-commenters-comments-count' ), $pending_count ); 
    182             } 
    183  
    184             $ret .= "<a href='" . esc_attr( self::get_comments_url( $user->user_email ) ) . "' title='" . esc_attr( $msg ) . "'>"; 
    185         } 
    186  
    187         $ret .= $comment_count; 
    188  
    189         if ( $show_link ) { 
    190             $ret .= '</a>'; 
    191         } 
    192  
    193         return $ret; 
     185        list( $comment_count, $pending_count ) = self::get_comments_count( 'comment_author_email', $user->user_email, 'comment', $user->ID ); 
     186 
     187        $msg = sprintf( _n( '%d comment', '%d comments', $comment_count, 'admin-commenters-comments-count' ), $comment_count ); 
     188 
     189        return self::get_comments_bubble( $user->user_email, $comment_count, $pending_count, $msg, false ); 
    194190    } 
    195191 
     
    256252     */ 
    257253    public static function get_comments_url( $email ) { 
    258         return admin_url( 'edit-comments.php?s=' . urlencode( $email ) ); 
     254        return add_query_arg( 's', urlencode( $email ), admin_url( 'edit-comments.php' ) ); 
    259255    } 
    260256 
     
    306302        } 
    307303 
    308         if ( $pending_count ) { 
    309             $msg .= '; ' . sprintf( __( '%s pending', 'admin-commenters-comments-count' ), $pending_count ); 
    310             $pclass = ' author-com-pending'; 
    311         } else { 
    312             $pclass = ''; 
    313         } 
    314  
    315         $url = ( $comment_count + $pending_count ) > 0 ? self::get_comments_url( $author_email ) : '#'; 
    316  
    317304        // If appearing on the dashboard, then don't need to break out of 
    318305        // pre-existing <strong> tags. 
     
    322309        $html = $is_dashboard ? '' : '</strong>'; 
    323310 
    324         if ( version_compare( $GLOBALS['wp_version'], '4.3', '<' ) ) { // Older than WP 4.3 
    325             $html .= " 
    326                 <span class='post-com-count-wrapper post-and-author-com-count-wrapper'> 
    327                 <a class='author-com-count post-com-count{$pclass}' href='" . esc_attr( $url ) . "' title='" . esc_attr( $msg ) . "'> 
    328                 <span class='comment-count comment-count-approved'>$comment_count</span> 
    329                 </a></span>"; 
    330         } else { // WP 4.3+ 
    331             $comment_str = sprintf( 
    332                 _n( '%s comment', '%s comments', $comment_count, 'admin-commenters-comments-count' ), 
    333                 number_format_i18n( $comment_count ) 
    334             ); 
    335             $html .= " 
    336                 <span class='column-response'> 
    337                 <span class='post-com-count-wrapper post-and-author-com-count-wrapper'> 
    338                 <a href='" . esc_attr( $url ) . "' title='" . esc_attr( $msg ) . "' class='author-com-count post-com-count{$pclass} post-com-count-approved'> 
    339                 <span class='comment-count-approved' aria-hidden='true'>$comment_count</span> 
    340                 <span class='screen-reader-text'>$comment_str</span> 
    341                 </a></span></span>"; 
    342         } 
     311        $html .= self::get_comments_bubble( $author_email, $comment_count, $pending_count, $msg ); 
    343312 
    344313        $html .= $is_dashboard ? '' : '<strong>'; 
    345314        $html .= $author_name; 
     315 
     316        return $html; 
     317    } 
     318 
     319    /** 
     320     * Returns the markup for the comments bubble for the given email address with 
     321     * with the provided counts. 
     322     * 
     323     * @since 1.8 
     324     * 
     325     * @param string $author_email       Comment author email address. 
     326     * @param int    $comment_count      The number of comments for the email 
     327     *                                   address. 
     328     * @param int    $pending_count      The number of pending comments for the 
     329     *                                   email address. 
     330     * @param string $msg.               String to use as title attribute for 
     331     *                                   comment bubble. 
     332     * @param bool.  $no_comments_bubble Should the comment bubble be shown if the 
     333     *                                   email address has no comments? 
     334     * 
     335     * @return string 
     336     */ 
     337    public static function get_comments_bubble( $author_email, $comment_count, $pending_count, $msg = '', $no_comments_bubble = true ) { 
     338        $html = ''; 
     339 
     340        $url = ( $comment_count + $pending_count ) > 0 ? self::get_comments_url( $author_email ) : '#'; 
     341 
     342        $comment_str = sprintf( 
     343            _n( '%s comment', '%s comments', $comment_count, 'admin-commenters-comments-count' ), 
     344            number_format_i18n( $comment_count ) 
     345        ); 
     346 
     347        $pending_class = $pending_count ? '' : ' author-com-count-no-pending'; 
     348 
     349        if ( ! $no_comments_bubble && ! $comment_count && ! $pending_count ) { 
     350            return sprintf( '<span aria-hidden="true">—</span><span class="screen-reader-text">%s</span>', 
     351                __( 'No comments', 'admin-commenters-comments-count' ) 
     352            ); 
     353        } 
     354 
     355        $html .= '<span class="column-response"><span class="post-com-count-wrapper post-and-author-com-count-wrapper author-com-count' . $pending_class . "\">\n"; 
     356 
     357        $comments_number = number_format_i18n( $comment_count ); 
     358 
     359        if ( $comment_count ) { 
     360            $html .= sprintf( 
     361                '<a href="%s" title="%s" class="post-com-count post-com-count-approved"> 
     362                    <span class="comment-count-approved" aria-hidden="true">%s</span> 
     363                    <span class="screen-reader-text">%s</span> 
     364                </a>', 
     365                esc_url( add_query_arg( 'comment_status', 'approved', $url ) ), 
     366                esc_attr( $msg ), 
     367                $comments_number, 
     368                $comment_str 
     369            ); 
     370        } else { 
     371            $html .= sprintf( 
     372                '<span class="post-com-count post-com-count-no-comments" title="%s"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>', 
     373                esc_attr( $msg ), 
     374                $comments_number, 
     375                $pending_count ? __( 'No approved comments', 'admin-commenters-comments-count' ) : __( 'No comments', 'admin-commenters-comments-count' ) 
     376            ); 
     377        } 
     378 
     379        $pending_comments_number = number_format_i18n( $pending_count ); 
     380        $pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_count, 'admin-commenters-comments-count' ), $pending_comments_number ); 
     381        if ( $pending_count ) { 
     382            $html .= sprintf( 
     383                '<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', 
     384                esc_url( add_query_arg( 'comment_status', 'moderated', $url ) ), 
     385                $pending_comments_number, 
     386                $pending_phrase 
     387            ); 
     388        } else { 
     389            $html .= sprintf( 
     390                '<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>', 
     391                $pending_comments_number, 
     392                $comment_count ? __( 'No pending comments', 'admin-commenters-comments-count' ) : __( 'No comments', 'admin-commenters-comments-count' ) 
     393            ); 
     394        } 
     395 
     396        $html .= "</span></span>"; 
    346397 
    347398        return $html; 
  • admin-commenters-comments-count/tags/1.8/assets/admin.css

    r1327235 r1611510  
    44.author-com-count { 
    55    float: right; 
    6     text-align: center; 
    7     margin-right: 5px; 
    8     margin-top: 2px; 
    9     height: 1.3em; 
    10     line-height: 1.1em; 
    116} 
    12 #dashboard_recent_comments .author-com-count { 
    13     margin-top: 5px; 
     7#the-comment-list .author-com-count-no-pending { 
     8    margin-right: 21px; 
    149} 
    1510.column-commenters_count { 
     
    1712    text-align: center; 
    1813} 
     14.column-commenters_count .author-com-count.author-com-count-no-pending { 
     15    float: none; 
     16} 
     17@media screen and (max-width: 782px) { 
     18    .wp-list-table.users .author-com-count { 
     19        float: none; 
     20    } 
     21    .wp-list-table.users .column-commenters_count { 
     22        text-align: left; 
     23    } 
     24} 
  • admin-commenters-comments-count/tags/1.8/readme.txt

    r1395943 r1611510  
    55License: GPLv2 or later 
    66License URI: http://www.gnu.org/licenses/gpl-2.0.html 
    7 Requires at least: 3.9 
    8 Tested up to: 4.5 
    9 Stable tag: 1.7 
     7Requires at least: 4.6 
     8Tested up to: 4.7 
     9Stable tag: 1.8 
    1010 
    1111Displays a count of each commenter's total number of comments (linked to those comments) next to their name on any admin page. 
     
    1414== Description == 
    1515 
    16 Next to all appearances of each commenter's name in the admin, this plugin shows a count of their total number of comments, linked to a listing of those comments. 
    17  
    18 By default in WordPress, it is not possible to tell via a single glance whether a particular commenter has commented before, and if so, how many times. 
    19  
    20 This plugin adds a handy feature to the WordPress admin pages to allow you to: 
     16Next to all appearances of each commenter's name in the admin, this plugin shows a comments bubble identical to the one shown for posts in the admin listing of posts. The comments bubble shows the number of approved comments for that person and potentially a red superscript circle indicating the number of pending comments for the person (assuming they have any). The comment counts are linked to listings of comments associated solely with that particular commenter. 
     17 
     18By default in WordPress, it is not possible to tell via a single glance whether a particular commenter has commented before or how many times the've commented. 
     19 
     20This plugin adds this handy capability to the WordPress admin pages that allows you to: 
    2121 
    2222* Quickly identify a first-time commenter 
    2323* Quickly identify unfamiliar commenters that have in fact commented before 
    2424* Quickly see how many total comments a particular commenter has made, and how many comments are pending 
    25 * Easily go to a listing of all comments by a commenter, in order to see what and when they last commented, or what/when they first commented 
    26  
    27 This plugin adds a linked comment count next to every appearance of a commenter in the admin. The link takes you to the admin page listing all comments for that particular commenter. The count displays all approved comments attributed to that commenter. If you hover over the comment count, the hover text indicates how many pending comments they also have, if any. 
     25* Easily navigate to a listing of all approved comments and all moderated comments by a commenter, in order to see what post and when they last commented (or first commented), get a feel for the nature of their comments, or find something they've said in the past 
    2826 
    2927Specifically, the linked comment count appears next to commenters in: 
     
    4240== Installation == 
    4341 
    44 1. Unzip `admin-commenters-comments-count.zip` inside the `/wp-content/plugins/` directory for your site (or install via the built-in WordPress plugin installer) 
    45 1. Activate the plugin through the 'Plugins' admin menu in WordPress 
     421. Install via the built-in WordPress plugin installer. Or download and unzip `admin-commenters-comments-count.zip` inside the plugins directory for your site (typically `wp-content/plugins/`) 
     432. Activate the plugin through the 'Plugins' admin menu in WordPress 
    4644 
    4745 
     
    5250There are many reasons, some of which might include: 
    5351 
    54 * Quickly identifying a first-time commenter 
    55 * Quickly identifying unfamiliar commenters that have in fact commented before 
    56 * Quickly seeing how many total comments a particular commenter has made, and how many comments are pending 
    57 * Easily going to a listing of all comments by a commenter, in order to see what and when they last commented, or what/when they first commented 
     52* Quickly identify a first-time commenter 
     53* Quickly identify unfamiliar commenters that have in fact commented before 
     54* Quickly see how many total comments a particular commenter has made, and how many comments are pending 
     55* Easily navigate to a listing of all approved comments and all moderated comments by a commenter, in order to see what post and when they last commented (or first commented), get a feel for the nature of their comments, or find something they've said in the past 
    5856 
    5957= How does the plugin know about all of the comments someone made to the site? = 
     
    7674== Screenshots == 
    7775 
    78 1. A screenshot of the 'Comments' admin page with the comment count appearing next to the commenter's name. The most recent comment is from someone who has not commented on the site before. The second comment is from someone who has commented 13 times before. The hover text on the comment bubble reveals there are currently 13 approved comments and 3 pending comments for the visitor. 
     761. A screenshot of the 'Comments' admin page with the comment count appearing next to the commenter's name. The most recent comment is from someone who has one approved commented on the site. The second comment is from someone who hasn't commented on the site before and has one comment in moderation. The third comment is from someone who has commented 12 times before and has 3 additional comments in moderation. 
    79772. A screenshot of the 'Comments on POST TITLE' admin page with the comment count appearing next to the commenter's name. 
    80783. A screenshot of the 'Activity' admin dashboard widget with the comment count appearing next to the commenter's name. 
    81794. A screenshot of the 'Comments' metabox on the 'Edit Post' admin page with the comment count appearing next to the commenter's name. 
    82 5. A screenshot of the 'Comments' column added to the admin user listing with the linked count of each user's comments. 
     805. A screenshot of the 'Comments' column added to the admin users listing. 
    8381 
    8482 
    8583== Changelog == 
     84 
     85= 1.8 (2017-03-04) = 
     86* Change: Adopt WP core style of showing pending comments in a red circle superscript to comments bubble icon 
     87* Change: Show comments bubble in "Comments" column of user listings instead of plain integer 
     88* Change: Don't link comments bubble when there are zero comments since approved and pending comments are available as separate links 
     89* Change: Extract comments bubble markup generation from `comment_author()` into new `get_comments_bubble()` 
     90* Change: Remove support for pre-WP 4.3 markup 
     91* Change: Prevent object instantiation of the class 
     92* Change: Use `sprintf()` to produce markup rather than concatenating various strings, function calls, and variables 
     93* Change: Update unit test bootstrap 
     94    * Default `WP_TESTS_DIR` to `/tmp/wordpress-tests-lib` rather than erroring out if not defined via environment variable 
     95    * Enable more error output for unit tests 
     96* Change: Note compatibility through WP 4.7+ 
     97* Change: Remove support for WordPress older than 4.6 (should still work for earlier versions back to WP 4.3) 
     98* Change: Update readme.txt content and formatting 
     99* Change: Update copyright date (2017) 
     100* Change: Update screenshots 
     101* New: Add LICENSE file 
    86102 
    87103= 1.7 (2016-01-11) = 
     
    212228== Upgrade Notice == 
    213229 
     230= 1.8 = 
     231Recommended update: adopted WP comments bubble red circle superscript to display pending comments count, shown comments bubble in users listing, noted compatibility through WP 4.7+, dropped compatibility with WP older than 4.6, more 
     232 
    214233= 1.7 = 
    215234Recommended update: bugfix for causing blank custom user columns, adjustments to utilize language packs, minor unit test tweaks, noted compatibility through WP 4.4+, and updated copyright date 
  • admin-commenters-comments-count/tags/1.8/tests/bootstrap.php

    r827598 r1611510  
    11<?php 
     2/** 
     3 * PHPUnit bootstrap file 
     4 * 
     5 * @package Admin_Commenters_Comments_Count 
     6 */ 
    27 
    3 require_once getenv( 'WP_TESTS_DIR' ) . '/includes/functions.php'; 
     8ini_set('display_errors','on'); 
     9error_reporting(E_ALL); 
    410 
     11$_tests_dir = getenv( 'WP_TESTS_DIR' ); 
     12if ( ! $_tests_dir ) { 
     13        $_tests_dir = '/tmp/wordpress-tests-lib'; 
     14} 
     15 
     16// Give access to tests_add_filter() function. 
     17require_once $_tests_dir . '/includes/functions.php'; 
     18 
     19/** 
     20 * Manually load the plugin being tested. 
     21 */ 
    522function _manually_load_plugin() { 
    6     require dirname( __FILE__ ) . '/../admin-commenters-comments-count.php'; 
     23        require dirname( dirname( __FILE__ ) ) . '/admin-commenters-comments-count.php'; 
    724} 
    825tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); 
    926 
    10 require getenv( 'WP_TESTS_DIR' ) . '/includes/bootstrap.php'; 
     27// Start up the WP testing environment. 
     28require $_tests_dir . '/includes/bootstrap.php'; 
  • admin-commenters-comments-count/tags/1.8/tests/test-admin-commenters-comments-count.php

    r1327235 r1611510  
    3939    } 
    4040 
    41     private function expected_output_pre_43( $approved_count = 0, $pending_count = 0, $name = '', $email = '' ) { 
     41    private function expected_output( $approved_count = 0, $pending_count = 0, $name = '', $email = '', $is_dashboard = false, $no_comments_bubble = true ) { 
    4242        $title = sprintf( _n( '%d comment', '%d comments', $approved_count ), $approved_count ); 
    43         $class = ''; 
    44         if ( $pending_count > 0 ) { 
    45             $title .= "; $pending_count pending"; 
    46             $class = ' author-com-pending'; 
    47         } 
    48         return "</strong> 
    49                 <span class='post-com-count-wrapper post-and-author-com-count-wrapper'> 
    50                 <a class='author-com-count post-com-count$class' href='http://example.org/wp-admin/edit-comments.php?s=" . esc_attr( urlencode( $email ) ) . "' title='" . esc_attr( $title ) . "'> 
    51                 <span class='comment-count comment-count-approved'>$approved_count</span> 
    52                 </a></span><strong>$name"; 
    53     } 
    54  
    55     private function expected_output( $approved_count = 0, $pending_count = 0, $name = '', $email = '' ) { 
    56         $title = sprintf( _n( '%d comment', '%d comments', $approved_count ), $approved_count ); 
    57         $class = ''; 
    58         if ( $pending_count > 0 ) { 
    59             $title .= "; $pending_count pending"; 
    60             $class = ' author-com-pending'; 
    61         } 
    62         return "</strong> 
    63                 <span class='column-response'> 
    64                 <span class='post-com-count-wrapper post-and-author-com-count-wrapper'> 
    65                 <a href='http://example.org/wp-admin/edit-comments.php?s=" . esc_attr( urlencode( $email ) ) . "' title='" . esc_attr( $title ) . "' class='author-com-count post-com-count$class post-com-count-approved'> 
    66                 <span class='comment-count-approved' aria-hidden='true'>$approved_count</span> 
    67                 <span class='screen-reader-text'>$approved_count comments</span> 
    68                 </a></span></span><strong>$name"; 
     43        $pending_class = $pending_count ? '' : ' author-com-count-no-pending'; 
     44 
     45        if ( ! $no_comments_bubble && ! $approved_count && ! $pending_count ) { 
     46            return '<span aria-hidden="true">—</span><span class="screen-reader-text">No comments</span>'; 
     47        } 
     48 
     49        $ret = $is_dashboard ? '' : '</strong>'; 
     50 
     51        $url = ( ! $approved_count && ! $pending_count ) 
     52            ? '#' 
     53            : add_query_arg( 's', urlencode( $email), 'http://example.org/wp-admin/edit-comments.php' ); 
     54 
     55        $ret .= '<span class="column-response"><span class="post-com-count-wrapper post-and-author-com-count-wrapper author-com-count' . $pending_class . '">' . "\n"; 
     56 
     57        $comments_number = number_format_i18n( $approved_count ); 
     58 
     59        if ( $approved_count )  { 
     60            $ret .= sprintf( 
     61                '<a href="%s" title="%s" class="post-com-count post-com-count-approved"> 
     62                    <span class="comment-count-approved" aria-hidden="true">%s</span> 
     63                    <span class="screen-reader-text">%s comments</span> 
     64                </a>', 
     65                esc_url( add_query_arg( 'comment_status', 'approved', $url ) ), 
     66                esc_attr( $title ), 
     67                $comments_number, 
     68                $approved_count 
     69            ); 
     70        } else { 
     71            $ret .= sprintf( 
     72                '<span class="post-com-count post-com-count-no-comments" title="%s"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>', 
     73                esc_attr( $title ), 
     74                $comments_number, 
     75                $pending_count ? __( 'No approved comments', 'admin-commenters-comments-count' ) : __( 'No comments', 'admin-commenters-comments-count' ) 
     76            ); 
     77        } 
     78 
     79        $pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_count ), number_format_i18n( $pending_count ) ); 
     80        if ( $pending_count ) { 
     81            $ret .= sprintf( 
     82'<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', 
     83                esc_url( 'http://example.org/wp-admin/edit-comments.php?s=' . urlencode( $email ) . '&comment_status=moderated' ), 
     84                $pending_count, 
     85                $pending_phrase 
     86            ); 
     87        } else { 
     88            $ret .= sprintf( 
     89                '<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>', 
     90                $pending_count, 
     91                $approved_count ? __( 'No pending comments' ) : __( 'No comments' ) 
     92            ); 
     93        } 
     94        $ret .= "</span></span>"; 
     95 
     96        $ret .= $is_dashboard ? '' : '<strong>'; 
     97 
     98        $ret .= $name; 
     99 
     100        return $ret; 
    69101    } 
    70102 
     
    85117 
    86118    public function test_plugin_version() { 
    87         $this->assertEquals( '1.7', c2c_AdminCommentersCommentsCount::version() ); 
     119        $this->assertEquals( '1.8', c2c_AdminCommentersCommentsCount::version() ); 
    88120    } 
    89121 
     
    132164    } 
    133165 
    134     public function test_get_comment_author_link_affected_on_backend_pre_43() { 
    135         $current_version = $GLOBALS['wp_version']; 
    136         $GLOBALS['wp_version'] = '4.2'; 
    137  
     166    /* 
     167     * get_comment_author_link() 
     168     */ 
     169 
     170    public function test_get_comment_author_link_affected_on_backend() { 
    138171        $post_id = $this->factory->post->create(); 
    139172 
     
    144177        $GLOBALS['comment'] = get_comment( $comment_id ); 
    145178 
    146         $expected_output = $this->expected_output_pre_43( 5, 1, 'Alpha User', 'alpha@example.org' ); 
     179        $expected_output = $this->expected_output( 5, 1, 'Alpha User', 'alpha@example.org' ); 
    147180        $this->assertEquals( $expected_output, get_comment_author_link( $comment_id ) ); 
    148181        $this->assertEquals( $expected_output, c2c_AdminCommentersCommentsCount::get_comment_author_link( $comment_id ) ); 
     
    150183        $GLOBALS['comment'] = get_comment( $bravo_comments[0] ); 
    151184 
    152         $expected_output = $this->expected_output_pre_43( 2, 0, 'Bravo User', 'bravo@example.org' ); 
     185        $expected_output = $this->expected_output( 2, 0, 'Bravo User', 'bravo@example.org' ); 
    153186        $this->assertEquals( $expected_output, get_comment_author_link( $comment_id ) ); 
    154187        $this->assertEquals( $expected_output, c2c_AdminCommentersCommentsCount::get_comment_author_link( $bravo_comments[0] ) ); 
    155  
    156         $GLOBALS['wp_version'] = $current_version; 
    157     } 
    158  
    159     public function test_get_comment_author_link_affected_on_backend() { 
     188    } 
     189 
     190    /* 
     191     * comment_author() 
     192     */ 
     193 
     194    public function test_comment_author_link_affected_on_backend() { 
    160195        $post_id = $this->factory->post->create(); 
    161196 
     
    166201        $GLOBALS['comment'] = get_comment( $comment_id ); 
    167202 
    168         $expected_output = $this->expected_output( 5, 1, 'Alpha User', 'alpha@example.org' ); 
    169         $this->assertEquals( $expected_output, get_comment_author_link( $comment_id ) ); 
    170         $this->assertEquals( $expected_output, c2c_AdminCommentersCommentsCount::get_comment_author_link( $comment_id ) ); 
    171  
    172         $GLOBALS['comment'] = get_comment( $bravo_comments[0] ); 
    173  
    174         $expected_output = $this->expected_output( 2, 0, 'Bravo User', 'bravo@example.org' ); 
    175         $this->assertEquals( $expected_output, get_comment_author_link( $comment_id ) ); 
    176         $this->assertEquals( $expected_output, c2c_AdminCommentersCommentsCount::get_comment_author_link( $bravo_comments[0] ) ); 
    177     } 
    178  
    179     public function test_comment_author_link_affected_on_backend_pre_43() { 
    180         $current_version = $GLOBALS['wp_version']; 
    181         $GLOBALS['wp_version'] = '4.2'; 
    182  
    183         $post_id = $this->factory->post->create(); 
    184  
    185         $this->create_comments( $post_id, 5, 'alpha' ); 
    186         $bravo_comments = $this->create_comments( $post_id, 2, 'bravo' ); 
    187         $comment_id = $this->create_comments( $post_id, 1, 'alpha', array( 'comment_approved' => '0' ) ); 
    188  
    189         $GLOBALS['comment'] = get_comment( $comment_id ); 
    190  
    191         $this->assertEquals( $this->expected_output_pre_43( 5, 1, 'Alpha User', 'alpha@example.org' ), $this->get_comment_author_output( $comment_id ) ); 
    192         $this->assertEquals( $this->expected_output_pre_43( 5, 1, 'Alpha User', 'alpha@example.org' ), c2c_AdminCommentersCommentsCount::comment_author( $comment_id ) ); 
    193  
    194         $GLOBALS['comment'] = get_comment( $bravo_comments[0] ); 
    195  
    196         $this->assertEquals( $this->expected_output_pre_43( 2, 0, 'Bravo User', 'bravo@example.org' ), $this->get_comment_author_output( $bravo_comments[0] ) ); 
    197         $this->assertEquals( $this->expected_output_pre_43( 2, 0, 'Bravo User', 'bravo@example.org' ), c2c_AdminCommentersCommentsCount::comment_author( $bravo_comments[0] ) ); 
    198  
    199         $GLOBALS['wp_version'] = $current_version; 
    200     } 
    201  
    202     public function test_comment_author_link_affected_on_backend() { 
    203         $post_id = $this->factory->post->create(); 
    204  
    205         $this->create_comments( $post_id, 5, 'alpha' ); 
    206         $bravo_comments = $this->create_comments( $post_id, 2, 'bravo' ); 
    207         $comment_id = $this->create_comments( $post_id, 1, 'alpha', array( 'comment_approved' => '0' ) ); 
    208  
    209         $GLOBALS['comment'] = get_comment( $comment_id ); 
    210  
    211203        $this->assertEquals( $this->expected_output( 5, 1, 'Alpha User', 'alpha@example.org' ), $this->get_comment_author_output( $comment_id ) ); 
    212204        $this->assertEquals( $this->expected_output( 5, 1, 'Alpha User', 'alpha@example.org' ), c2c_AdminCommentersCommentsCount::comment_author( $comment_id ) ); 
     
    217209        $this->assertEquals( $this->expected_output( 2, 0, 'Bravo User', 'bravo@example.org' ), c2c_AdminCommentersCommentsCount::comment_author( $bravo_comments[0] ) ); 
    218210    } 
     211 
     212    /* 
     213     * get_comments_count() 
     214     */ 
    219215 
    220216    public function test_get_comments_count_by_comment_author_email() { 
     
    249245    } 
    250246 
     247    /* 
     248     * get_comments_url() 
     249     */ 
     250 
    251251    public function test_get_comments_url() { 
    252252        $this->assertEquals( 
     
    255255        ); 
    256256    } 
     257 
     258    /* 
     259     * get_comments_url() 
     260     */ 
     261 
     262    public function test_get_comments_bubble() { 
     263        $this->assertEquals( 
     264            $this->expected_output( 10, 3, '', 'test@example.com', true ), 
     265            c2c_AdminCommentersCommentsCount::get_comments_bubble( 'test@example.com', 10, 3, '10 comments' ) 
     266        ); 
     267    } 
     268 
     269    public function test_get_comments_bubble_when_no_comments_and_true_no_comments_bubble() { 
     270        $this->assertEquals( 
     271            $this->expected_output( 0, 0, '', 'test@example.com', true, false ), 
     272            c2c_AdminCommentersCommentsCount::get_comments_bubble( 'test@example.com', 0, 0, '', false ) 
     273        ); 
     274    } 
     275 
     276    public function test_get_comments_bubble_when_no_comments_and_false_no_comments_bubble() { 
     277        $this->assertEquals( 
     278            $this->expected_output( 0, 0, '', 'test@example.com', true, true ), 
     279            c2c_AdminCommentersCommentsCount::get_comments_bubble( 'test@example.com', 0, 0, '0 comments', true ) 
     280        ); 
     281    } 
    257282} 
  • admin-commenters-comments-count/trunk/admin-commenters-comments-count.php

    r1395943 r1611510  
    22/** 
    33 * Plugin Name: Admin Commenters Comments Count 
    4  * Version:     1.7 
     4 * Version:     1.8 
    55 * Plugin URI:  http://coffee2code.com/wp-plugins/admin-commenters-comments-count/ 
    66 * Author:      Scott Reilly 
     
    1111 * Description: Displays a count of each commenter's total number of comments (linked to those comments) next to their name on any admin page. 
    1212 * 
    13  * Compatible with WordPress 3.9 through 4.5+. 
     13 * Compatible with WordPress 4.6 through 4.7+. 
    1414 * 
    1515 * =>> Read the accompanying readme.txt file for instructions and documentation. 
     
    1919 * @package Admin_Commenters_Comments_Count 
    2020 * @author  Scott Reilly 
    21  * @version 1.7 
     21 * @version 1.8 
    2222 */ 
    2323 
     
    3434 
    3535/* 
    36     Copyright (c) 2009-2016 by Scott Reilly (aka coffee2code) 
     36    Copyright (c) 2009-2017 by Scott Reilly (aka coffee2code) 
    3737 
    3838    This program is free software; you can redistribute it and/or 
     
    8686 
    8787    /** 
     88     * Prevent instantiation. 
     89     * 
     90     * @since 1.8 
     91     */ 
     92    private function __construct() {} 
     93 
     94    /** 
     95     * Prevent unserializing an instance. 
     96     * 
     97     * @since 1.8 
     98     */ 
     99    private function __wakeup() {} 
     100 
     101    /** 
    88102     * Returns version of the plugin. 
    89103     * 
     
    91105     */ 
    92106    public static function version() { 
    93         return '1.7'; 
     107        return '1.8'; 
    94108    } 
    95109 
     
    169183        $user = get_user_by( 'id', $user_id ); 
    170184 
    171         list( $comment_count, $pending_count )  = self::get_comments_count( 'comment_author_email', $user->user_email, 'comment', $user->ID ); 
    172  
    173         $show_link = ( $comment_count + $pending_count ) > 0; 
    174  
    175         $ret = ''; 
    176  
    177         if ( $show_link ) { 
    178             $msg = sprintf( _n( '%d comment', '%d comments', $comment_count, 'admin-commenters-comments-count' ), $comment_count ); 
    179  
    180             if ( $pending_count ) { 
    181                 $msg .= '; ' . sprintf( __( '%s pending', 'admin-commenters-comments-count' ), $pending_count ); 
    182             } 
    183  
    184             $ret .= "<a href='" . esc_attr( self::get_comments_url( $user->user_email ) ) . "' title='" . esc_attr( $msg ) . "'>"; 
    185         } 
    186  
    187         $ret .= $comment_count; 
    188  
    189         if ( $show_link ) { 
    190             $ret .= '</a>'; 
    191         } 
    192  
    193         return $ret; 
     185        list( $comment_count, $pending_count ) = self::get_comments_count( 'comment_author_email', $user->user_email, 'comment', $user->ID ); 
     186 
     187        $msg = sprintf( _n( '%d comment', '%d comments', $comment_count, 'admin-commenters-comments-count' ), $comment_count ); 
     188 
     189        return self::get_comments_bubble( $user->user_email, $comment_count, $pending_count, $msg, false ); 
    194190    } 
    195191 
     
    256252     */ 
    257253    public static function get_comments_url( $email ) { 
    258         return admin_url( 'edit-comments.php?s=' . urlencode( $email ) ); 
     254        return add_query_arg( 's', urlencode( $email ), admin_url( 'edit-comments.php' ) ); 
    259255    } 
    260256 
     
    306302        } 
    307303 
    308         if ( $pending_count ) { 
    309             $msg .= '; ' . sprintf( __( '%s pending', 'admin-commenters-comments-count' ), $pending_count ); 
    310             $pclass = ' author-com-pending'; 
    311         } else { 
    312             $pclass = ''; 
    313         } 
    314  
    315         $url = ( $comment_count + $pending_count ) > 0 ? self::get_comments_url( $author_email ) : '#'; 
    316  
    317304        // If appearing on the dashboard, then don't need to break out of 
    318305        // pre-existing <strong> tags. 
     
    322309        $html = $is_dashboard ? '' : '</strong>'; 
    323310 
    324         if ( version_compare( $GLOBALS['wp_version'], '4.3', '<' ) ) { // Older than WP 4.3 
    325             $html .= " 
    326                 <span class='post-com-count-wrapper post-and-author-com-count-wrapper'> 
    327                 <a class='author-com-count post-com-count{$pclass}' href='" . esc_attr( $url ) . "' title='" . esc_attr( $msg ) . "'> 
    328                 <span class='comment-count comment-count-approved'>$comment_count</span> 
    329                 </a></span>"; 
    330         } else { // WP 4.3+ 
    331             $comment_str = sprintf( 
    332                 _n( '%s comment', '%s comments', $comment_count, 'admin-commenters-comments-count' ), 
    333                 number_format_i18n( $comment_count ) 
    334             ); 
    335             $html .= " 
    336                 <span class='column-response'> 
    337                 <span class='post-com-count-wrapper post-and-author-com-count-wrapper'> 
    338                 <a href='" . esc_attr( $url ) . "' title='" . esc_attr( $msg ) . "' class='author-com-count post-com-count{$pclass} post-com-count-approved'> 
    339                 <span class='comment-count-approved' aria-hidden='true'>$comment_count</span> 
    340                 <span class='screen-reader-text'>$comment_str</span> 
    341                 </a></span></span>"; 
    342         } 
     311        $html .= self::get_comments_bubble( $author_email, $comment_count, $pending_count, $msg ); 
    343312 
    344313        $html .= $is_dashboard ? '' : '<strong>'; 
    345314        $html .= $author_name; 
     315 
     316        return $html; 
     317    } 
     318 
     319    /** 
     320     * Returns the markup for the comments bubble for the given email address with 
     321     * with the provided counts. 
     322     * 
     323     * @since 1.8 
     324     * 
     325     * @param string $author_email       Comment author email address. 
     326     * @param int    $comment_count      The number of comments for the email 
     327     *                                   address. 
     328     * @param int    $pending_count      The number of pending comments for the 
     329     *                                   email address. 
     330     * @param string $msg.               String to use as title attribute for 
     331     *                                   comment bubble. 
     332     * @param bool.  $no_comments_bubble Should the comment bubble be shown if the 
     333     *                                   email address has no comments? 
     334     * 
     335     * @return string 
     336     */ 
     337    public static function get_comments_bubble( $author_email, $comment_count, $pending_count, $msg = '', $no_comments_bubble = true ) { 
     338        $html = ''; 
     339 
     340        $url = ( $comment_count + $pending_count ) > 0 ? self::get_comments_url( $author_email ) : '#'; 
     341 
     342        $comment_str = sprintf( 
     343            _n( '%s comment', '%s comments', $comment_count, 'admin-commenters-comments-count' ), 
     344            number_format_i18n( $comment_count ) 
     345        ); 
     346 
     347        $pending_class = $pending_count ? '' : ' author-com-count-no-pending'; 
     348 
     349        if ( ! $no_comments_bubble && ! $comment_count && ! $pending_count ) { 
     350            return sprintf( '<span aria-hidden="true">—</span><span class="screen-reader-text">%s</span>', 
     351                __( 'No comments', 'admin-commenters-comments-count' ) 
     352            ); 
     353        } 
     354 
     355        $html .= '<span class="column-response"><span class="post-com-count-wrapper post-and-author-com-count-wrapper author-com-count' . $pending_class . "\">\n"; 
     356 
     357        $comments_number = number_format_i18n( $comment_count ); 
     358 
     359        if ( $comment_count ) { 
     360            $html .= sprintf( 
     361                '<a href="%s" title="%s" class="post-com-count post-com-count-approved"> 
     362                    <span class="comment-count-approved" aria-hidden="true">%s</span> 
     363                    <span class="screen-reader-text">%s</span> 
     364                </a>', 
     365                esc_url( add_query_arg( 'comment_status', 'approved', $url ) ), 
     366                esc_attr( $msg ), 
     367                $comments_number, 
     368                $comment_str 
     369            ); 
     370        } else { 
     371            $html .= sprintf( 
     372                '<span class="post-com-count post-com-count-no-comments" title="%s"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>', 
     373                esc_attr( $msg ), 
     374                $comments_number, 
     375                $pending_count ? __( 'No approved comments', 'admin-commenters-comments-count' ) : __( 'No comments', 'admin-commenters-comments-count' ) 
     376            ); 
     377        } 
     378 
     379        $pending_comments_number = number_format_i18n( $pending_count ); 
     380        $pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_count, 'admin-commenters-comments-count' ), $pending_comments_number ); 
     381        if ( $pending_count ) { 
     382            $html .= sprintf( 
     383                '<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', 
     384                esc_url( add_query_arg( 'comment_status', 'moderated', $url ) ), 
     385                $pending_comments_number, 
     386                $pending_phrase 
     387            ); 
     388        } else { 
     389            $html .= sprintf( 
     390                '<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>', 
     391                $pending_comments_number, 
     392                $comment_count ? __( 'No pending comments', 'admin-commenters-comments-count' ) : __( 'No comments', 'admin-commenters-comments-count' ) 
     393            ); 
     394        } 
     395 
     396        $html .= "</span></span>"; 
    346397 
    347398        return $html; 
  • admin-commenters-comments-count/trunk/assets/admin.css

    r1327235 r1611510  
    44.author-com-count { 
    55    float: right; 
    6     text-align: center; 
    7     margin-right: 5px; 
    8     margin-top: 2px; 
    9     height: 1.3em; 
    10     line-height: 1.1em; 
    116} 
    12 #dashboard_recent_comments .author-com-count { 
    13     margin-top: 5px; 
     7#the-comment-list .author-com-count-no-pending { 
     8    margin-right: 21px; 
    149} 
    1510.column-commenters_count { 
     
    1712    text-align: center; 
    1813} 
     14.column-commenters_count .author-com-count.author-com-count-no-pending { 
     15    float: none; 
     16} 
     17@media screen and (max-width: 782px) { 
     18    .wp-list-table.users .author-com-count { 
     19        float: none; 
     20    } 
     21    .wp-list-table.users .column-commenters_count { 
     22        text-align: left; 
     23    } 
     24} 
  • admin-commenters-comments-count/trunk/readme.txt

    r1395943 r1611510  
    55License: GPLv2 or later 
    66License URI: http://www.gnu.org/licenses/gpl-2.0.html 
    7 Requires at least: 3.9 
    8 Tested up to: 4.5 
    9 Stable tag: 1.7 
     7Requires at least: 4.6 
     8Tested up to: 4.7 
     9Stable tag: 1.8 
    1010 
    1111Displays a count of each commenter's total number of comments (linked to those comments) next to their name on any admin page. 
     
    1414== Description == 
    1515 
    16 Next to all appearances of each commenter's name in the admin, this plugin shows a count of their total number of comments, linked to a listing of those comments. 
    17  
    18 By default in WordPress, it is not possible to tell via a single glance whether a particular commenter has commented before, and if so, how many times. 
    19  
    20 This plugin adds a handy feature to the WordPress admin pages to allow you to: 
     16Next to all appearances of each commenter's name in the admin, this plugin shows a comments bubble identical to the one shown for posts in the admin listing of posts. The comments bubble shows the number of approved comments for that person and potentially a red superscript circle indicating the number of pending comments for the person (assuming they have any). The comment counts are linked to listings of comments associated solely with that particular commenter. 
     17 
     18By default in WordPress, it is not possible to tell via a single glance whether a particular commenter has commented before or how many times the've commented. 
     19 
     20This plugin adds this handy capability to the WordPress admin pages that allows you to: 
    2121 
    2222* Quickly identify a first-time commenter 
    2323* Quickly identify unfamiliar commenters that have in fact commented before 
    2424* Quickly see how many total comments a particular commenter has made, and how many comments are pending 
    25 * Easily go to a listing of all comments by a commenter, in order to see what and when they last commented, or what/when they first commented 
    26  
    27 This plugin adds a linked comment count next to every appearance of a commenter in the admin. The link takes you to the admin page listing all comments for that particular commenter. The count displays all approved comments attributed to that commenter. If you hover over the comment count, the hover text indicates how many pending comments they also have, if any. 
     25* Easily navigate to a listing of all approved comments and all moderated comments by a commenter, in order to see what post and when they last commented (or first commented), get a feel for the nature of their comments, or find something they've said in the past 
    2826 
    2927Specifically, the linked comment count appears next to commenters in: 
     
    4240== Installation == 
    4341 
    44 1. Unzip `admin-commenters-comments-count.zip` inside the `/wp-content/plugins/` directory for your site (or install via the built-in WordPress plugin installer) 
    45 1. Activate the plugin through the 'Plugins' admin menu in WordPress 
     421. Install via the built-in WordPress plugin installer. Or download and unzip `admin-commenters-comments-count.zip` inside the plugins directory for your site (typically `wp-content/plugins/`) 
     432. Activate the plugin through the 'Plugins' admin menu in WordPress 
    4644 
    4745 
     
    5250There are many reasons, some of which might include: 
    5351 
    54 * Quickly identifying a first-time commenter 
    55 * Quickly identifying unfamiliar commenters that have in fact commented before 
    56 * Quickly seeing how many total comments a particular commenter has made, and how many comments are pending 
    57 * Easily going to a listing of all comments by a commenter, in order to see what and when they last commented, or what/when they first commented 
     52* Quickly identify a first-time commenter 
     53* Quickly identify unfamiliar commenters that have in fact commented before 
     54* Quickly see how many total comments a particular commenter has made, and how many comments are pending 
     55* Easily navigate to a listing of all approved comments and all moderated comments by a commenter, in order to see what post and when they last commented (or first commented), get a feel for the nature of their comments, or find something they've said in the past 
    5856 
    5957= How does the plugin know about all of the comments someone made to the site? = 
     
    7674== Screenshots == 
    7775 
    78 1. A screenshot of the 'Comments' admin page with the comment count appearing next to the commenter's name. The most recent comment is from someone who has not commented on the site before. The second comment is from someone who has commented 13 times before. The hover text on the comment bubble reveals there are currently 13 approved comments and 3 pending comments for the visitor. 
     761. A screenshot of the 'Comments' admin page with the comment count appearing next to the commenter's name. The most recent comment is from someone who has one approved commented on the site. The second comment is from someone who hasn't commented on the site before and has one comment in moderation. The third comment is from someone who has commented 12 times before and has 3 additional comments in moderation. 
    79772. A screenshot of the 'Comments on POST TITLE' admin page with the comment count appearing next to the commenter's name. 
    80783. A screenshot of the 'Activity' admin dashboard widget with the comment count appearing next to the commenter's name. 
    81794. A screenshot of the 'Comments' metabox on the 'Edit Post' admin page with the comment count appearing next to the commenter's name. 
    82 5. A screenshot of the 'Comments' column added to the admin user listing with the linked count of each user's comments. 
     805. A screenshot of the 'Comments' column added to the admin users listing. 
    8381 
    8482 
    8583== Changelog == 
     84 
     85= 1.8 (2017-03-04) = 
     86* Change: Adopt WP core style of showing pending comments in a red circle superscript to comments bubble icon 
     87* Change: Show comments bubble in "Comments" column of user listings instead of plain integer 
     88* Change: Don't link comments bubble when there are zero comments since approved and pending comments are available as separate links 
     89* Change: Extract comments bubble markup generation from `comment_author()` into new `get_comments_bubble()` 
     90* Change: Remove support for pre-WP 4.3 markup 
     91* Change: Prevent object instantiation of the class 
     92* Change: Use `sprintf()` to produce markup rather than concatenating various strings, function calls, and variables 
     93* Change: Update unit test bootstrap 
     94    * Default `WP_TESTS_DIR` to `/tmp/wordpress-tests-lib` rather than erroring out if not defined via environment variable 
     95    * Enable more error output for unit tests 
     96* Change: Note compatibility through WP 4.7+ 
     97* Change: Remove support for WordPress older than 4.6 (should still work for earlier versions back to WP 4.3) 
     98* Change: Update readme.txt content and formatting 
     99* Change: Update copyright date (2017) 
     100* Change: Update screenshots 
     101* New: Add LICENSE file 
    86102 
    87103= 1.7 (2016-01-11) = 
     
    212228== Upgrade Notice == 
    213229 
     230= 1.8 = 
     231Recommended update: adopted WP comments bubble red circle superscript to display pending comments count, shown comments bubble in users listing, noted compatibility through WP 4.7+, dropped compatibility with WP older than 4.6, more 
     232 
    214233= 1.7 = 
    215234Recommended update: bugfix for causing blank custom user columns, adjustments to utilize language packs, minor unit test tweaks, noted compatibility through WP 4.4+, and updated copyright date 
  • admin-commenters-comments-count/trunk/tests/bootstrap.php

    r827598 r1611510  
    11<?php 
     2/** 
     3 * PHPUnit bootstrap file 
     4 * 
     5 * @package Admin_Commenters_Comments_Count 
     6 */ 
    27 
    3 require_once getenv( 'WP_TESTS_DIR' ) . '/includes/functions.php'; 
     8ini_set('display_errors','on'); 
     9error_reporting(E_ALL); 
    410 
     11$_tests_dir = getenv( 'WP_TESTS_DIR' ); 
     12if ( ! $_tests_dir ) { 
     13        $_tests_dir = '/tmp/wordpress-tests-lib'; 
     14} 
     15 
     16// Give access to tests_add_filter() function. 
     17require_once $_tests_dir . '/includes/functions.php'; 
     18 
     19/** 
     20 * Manually load the plugin being tested. 
     21 */ 
    522function _manually_load_plugin() { 
    6     require dirname( __FILE__ ) . '/../admin-commenters-comments-count.php'; 
     23        require dirname( dirname( __FILE__ ) ) . '/admin-commenters-comments-count.php'; 
    724} 
    825tests_add_filter( 'muplugins_loaded', '_manually_load_plugin' ); 
    926 
    10 require getenv( 'WP_TESTS_DIR' ) . '/includes/bootstrap.php'; 
     27// Start up the WP testing environment. 
     28require $_tests_dir . '/includes/bootstrap.php'; 
  • admin-commenters-comments-count/trunk/tests/test-admin-commenters-comments-count.php

    r1327235 r1611510  
    3939    } 
    4040 
    41     private function expected_output_pre_43( $approved_count = 0, $pending_count = 0, $name = '', $email = '' ) { 
     41    private function expected_output( $approved_count = 0, $pending_count = 0, $name = '', $email = '', $is_dashboard = false, $no_comments_bubble = true ) { 
    4242        $title = sprintf( _n( '%d comment', '%d comments', $approved_count ), $approved_count ); 
    43         $class = ''; 
    44         if ( $pending_count > 0 ) { 
    45             $title .= "; $pending_count pending"; 
    46             $class = ' author-com-pending'; 
    47         } 
    48         return "</strong> 
    49                 <span class='post-com-count-wrapper post-and-author-com-count-wrapper'> 
    50                 <a class='author-com-count post-com-count$class' href='http://example.org/wp-admin/edit-comments.php?s=" . esc_attr( urlencode( $email ) ) . "' title='" . esc_attr( $title ) . "'> 
    51                 <span class='comment-count comment-count-approved'>$approved_count</span> 
    52                 </a></span><strong>$name"; 
    53     } 
    54  
    55     private function expected_output( $approved_count = 0, $pending_count = 0, $name = '', $email = '' ) { 
    56         $title = sprintf( _n( '%d comment', '%d comments', $approved_count ), $approved_count ); 
    57         $class = ''; 
    58         if ( $pending_count > 0 ) { 
    59             $title .= "; $pending_count pending"; 
    60             $class = ' author-com-pending'; 
    61         } 
    62         return "</strong> 
    63                 <span class='column-response'> 
    64                 <span class='post-com-count-wrapper post-and-author-com-count-wrapper'> 
    65                 <a href='http://example.org/wp-admin/edit-comments.php?s=" . esc_attr( urlencode( $email ) ) . "' title='" . esc_attr( $title ) . "' class='author-com-count post-com-count$class post-com-count-approved'> 
    66                 <span class='comment-count-approved' aria-hidden='true'>$approved_count</span> 
    67                 <span class='screen-reader-text'>$approved_count comments</span> 
    68                 </a></span></span><strong>$name"; 
     43        $pending_class = $pending_count ? '' : ' author-com-count-no-pending'; 
     44 
     45        if ( ! $no_comments_bubble && ! $approved_count && ! $pending_count ) { 
     46            return '<span aria-hidden="true">—</span><span class="screen-reader-text">No comments</span>'; 
     47        } 
     48 
     49        $ret = $is_dashboard ? '' : '</strong>'; 
     50 
     51        $url = ( ! $approved_count && ! $pending_count ) 
     52            ? '#' 
     53            : add_query_arg( 's', urlencode( $email), 'http://example.org/wp-admin/edit-comments.php' ); 
     54 
     55        $ret .= '<span class="column-response"><span class="post-com-count-wrapper post-and-author-com-count-wrapper author-com-count' . $pending_class . '">' . "\n"; 
     56 
     57        $comments_number = number_format_i18n( $approved_count ); 
     58 
     59        if ( $approved_count )  { 
     60            $ret .= sprintf( 
     61                '<a href="%s" title="%s" class="post-com-count post-com-count-approved"> 
     62                    <span class="comment-count-approved" aria-hidden="true">%s</span> 
     63                    <span class="screen-reader-text">%s comments</span> 
     64                </a>', 
     65                esc_url( add_query_arg( 'comment_status', 'approved', $url ) ), 
     66                esc_attr( $title ), 
     67                $comments_number, 
     68                $approved_count 
     69            ); 
     70        } else { 
     71            $ret .= sprintf( 
     72                '<span class="post-com-count post-com-count-no-comments" title="%s"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>', 
     73                esc_attr( $title ), 
     74                $comments_number, 
     75                $pending_count ? __( 'No approved comments', 'admin-commenters-comments-count' ) : __( 'No comments', 'admin-commenters-comments-count' ) 
     76            ); 
     77        } 
     78 
     79        $pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_count ), number_format_i18n( $pending_count ) ); 
     80        if ( $pending_count ) { 
     81            $ret .= sprintf( 
     82'<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>', 
     83                esc_url( 'http://example.org/wp-admin/edit-comments.php?s=' . urlencode( $email ) . '&comment_status=moderated' ), 
     84                $pending_count, 
     85                $pending_phrase 
     86            ); 
     87        } else { 
     88            $ret .= sprintf( 
     89                '<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>', 
     90                $pending_count, 
     91                $approved_count ? __( 'No pending comments' ) : __( 'No comments' ) 
     92            ); 
     93        } 
     94        $ret .= "</span></span>"; 
     95 
     96        $ret .= $is_dashboard ? '' : '<strong>'; 
     97 
     98        $ret .= $name; 
     99 
     100        return $ret; 
    69101    } 
    70102 
     
    85117 
    86118    public function test_plugin_version() { 
    87         $this->assertEquals( '1.7', c2c_AdminCommentersCommentsCount::version() ); 
     119        $this->assertEquals( '1.8', c2c_AdminCommentersCommentsCount::version() ); 
    88120    } 
    89121 
     
    132164    } 
    133165 
    134     public function test_get_comment_author_link_affected_on_backend_pre_43() { 
    135         $current_version = $GLOBALS['wp_version']; 
    136         $GLOBALS['wp_version'] = '4.2'; 
    137  
     166    /* 
     167     * get_comment_author_link() 
     168     */ 
     169 
     170    public function test_get_comment_author_link_affected_on_backend() { 
    138171        $post_id = $this->factory->post->create(); 
    139172 
     
    144177        $GLOBALS['comment'] = get_comment( $comment_id ); 
    145178 
    146         $expected_output = $this->expected_output_pre_43( 5, 1, 'Alpha User', 'alpha@example.org' ); 
     179        $expected_output = $this->expected_output( 5, 1, 'Alpha User', 'alpha@example.org' ); 
    147180        $this->assertEquals( $expected_output, get_comment_author_link( $comment_id ) ); 
    148181        $this->assertEquals( $expected_output, c2c_AdminCommentersCommentsCount::get_comment_author_link( $comment_id ) ); 
     
    150183        $GLOBALS['comment'] = get_comment( $bravo_comments[0] ); 
    151184 
    152         $expected_output = $this->expected_output_pre_43( 2, 0, 'Bravo User', 'bravo@example.org' ); 
     185        $expected_output = $this->expected_output( 2, 0, 'Bravo User', 'bravo@example.org' ); 
    153186        $this->assertEquals( $expected_output, get_comment_author_link( $comment_id ) ); 
    154187        $this->assertEquals( $expected_output, c2c_AdminCommentersCommentsCount::get_comment_author_link( $bravo_comments[0] ) ); 
    155  
    156         $GLOBALS['wp_version'] = $current_version; 
    157     } 
    158  
    159     public function test_get_comment_author_link_affected_on_backend() { 
     188    } 
     189 
     190    /* 
     191     * comment_author() 
     192     */ 
     193 
     194    public function test_comment_author_link_affected_on_backend() { 
    160195        $post_id = $this->factory->post->create(); 
    161196 
     
    166201        $GLOBALS['comment'] = get_comment( $comment_id ); 
    167202 
    168         $expected_output = $this->expected_output( 5, 1, 'Alpha User', 'alpha@example.org' ); 
    169         $this->assertEquals( $expected_output, get_comment_author_link( $comment_id ) ); 
    170         $this->assertEquals( $expected_output, c2c_AdminCommentersCommentsCount::get_comment_author_link( $comment_id ) ); 
    171  
    172         $GLOBALS['comment'] = get_comment( $bravo_comments[0] ); 
    173  
    174         $expected_output = $this->expected_output( 2, 0, 'Bravo User', 'bravo@example.org' ); 
    175         $this->assertEquals( $expected_output, get_comment_author_link( $comment_id ) ); 
    176         $this->assertEquals( $expected_output, c2c_AdminCommentersCommentsCount::get_comment_author_link( $bravo_comments[0] ) ); 
    177     } 
    178  
    179     public function test_comment_author_link_affected_on_backend_pre_43() { 
    180         $current_version = $GLOBALS['wp_version']; 
    181         $GLOBALS['wp_version'] = '4.2'; 
    182  
    183         $post_id = $this->factory->post->create(); 
    184  
    185         $this->create_comments( $post_id, 5, 'alpha' ); 
    186         $bravo_comments = $this->create_comments( $post_id, 2, 'bravo' ); 
    187         $comment_id = $this->create_comments( $post_id, 1, 'alpha', array( 'comment_approved' => '0' ) ); 
    188  
    189         $GLOBALS['comment'] = get_comment( $comment_id ); 
    190  
    191         $this->assertEquals( $this->expected_output_pre_43( 5, 1, 'Alpha User', 'alpha@example.org' ), $this->get_comment_author_output( $comment_id ) ); 
    192         $this->assertEquals( $this->expected_output_pre_43( 5, 1, 'Alpha User', 'alpha@example.org' ), c2c_AdminCommentersCommentsCount::comment_author( $comment_id ) ); 
    193  
    194         $GLOBALS['comment'] = get_comment( $bravo_comments[0] ); 
    195  
    196         $this->assertEquals( $this->expected_output_pre_43( 2, 0, 'Bravo User', 'bravo@example.org' ), $this->get_comment_author_output( $bravo_comments[0] ) ); 
    197         $this->assertEquals( $this->expected_output_pre_43( 2, 0, 'Bravo User', 'bravo@example.org' ), c2c_AdminCommentersCommentsCount::comment_author( $bravo_comments[0] ) ); 
    198  
    199         $GLOBALS['wp_version'] = $current_version; 
    200     } 
    201  
    202     public function test_comment_author_link_affected_on_backend() { 
    203         $post_id = $this->factory->post->create(); 
    204  
    205         $this->create_comments( $post_id, 5, 'alpha' ); 
    206         $bravo_comments = $this->create_comments( $post_id, 2, 'bravo' ); 
    207         $comment_id = $this->create_comments( $post_id, 1, 'alpha', array( 'comment_approved' => '0' ) ); 
    208  
    209         $GLOBALS['comment'] = get_comment( $comment_id ); 
    210  
    211203        $this->assertEquals( $this->expected_output( 5, 1, 'Alpha User', 'alpha@example.org' ), $this->get_comment_author_output( $comment_id ) ); 
    212204        $this->assertEquals( $this->expected_output( 5, 1, 'Alpha User', 'alpha@example.org' ), c2c_AdminCommentersCommentsCount::comment_author( $comment_id ) ); 
     
    217209        $this->assertEquals( $this->expected_output( 2, 0, 'Bravo User', 'bravo@example.org' ), c2c_AdminCommentersCommentsCount::comment_author( $bravo_comments[0] ) ); 
    218210    } 
     211 
     212    /* 
     213     * get_comments_count() 
     214     */ 
    219215 
    220216    public function test_get_comments_count_by_comment_author_email() { 
     
    249245    } 
    250246 
     247    /* 
     248     * get_comments_url() 
     249     */ 
     250 
    251251    public function test_get_comments_url() { 
    252252        $this->assertEquals( 
     
    255255        ); 
    256256    } 
     257 
     258    /* 
     259     * get_comments_url() 
     260     */ 
     261 
     262    public function test_get_comments_bubble() { 
     263        $this->assertEquals( 
     264            $this->expected_output( 10, 3, '', 'test@example.com', true ), 
     265            c2c_AdminCommentersCommentsCount::get_comments_bubble( 'test@example.com', 10, 3, '10 comments' ) 
     266        ); 
     267    } 
     268 
     269    public function test_get_comments_bubble_when_no_comments_and_true_no_comments_bubble() { 
     270        $this->assertEquals( 
     271            $this->expected_output( 0, 0, '', 'test@example.com', true, false ), 
     272            c2c_AdminCommentersCommentsCount::get_comments_bubble( 'test@example.com', 0, 0, '', false ) 
     273        ); 
     274    } 
     275 
     276    public function test_get_comments_bubble_when_no_comments_and_false_no_comments_bubble() { 
     277        $this->assertEquals( 
     278            $this->expected_output( 0, 0, '', 'test@example.com', true, true ), 
     279            c2c_AdminCommentersCommentsCount::get_comments_bubble( 'test@example.com', 0, 0, '0 comments', true ) 
     280        ); 
     281    } 
    257282} 
Note: See TracChangeset for help on using the changeset viewer.