WordPress.org

Make WordPress Core

Changeset 42684


Ignore:
Timestamp:
02/09/2018 06:45:30 PM (2 years ago)
Author:
johnbillion
Message:

Comments: Add a "Mine" link to the list of filters on the comment listing screen.

This filter shows comments made by the current user, and copies the same filter functionality that's available on the post listing screens.

Props Iceable

Fixes #42379

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-comments-list-table.php

    r42670 r42684  
    7979
    8080        $comment_status = isset( $_REQUEST['comment_status'] ) ? $_REQUEST['comment_status'] : 'all';
    81         if ( ! in_array( $comment_status, array( 'all', 'moderated', 'approved', 'spam', 'trash' ) ) ) {
     81        if ( ! in_array( $comment_status, array( 'all', 'mine', 'moderated', 'approved', 'spam', 'trash' ) ) ) {
    8282            $comment_status = 'all';
    8383        }
     
    117117
    118118        $status_map = array(
     119            'mine'      => '',
    119120            'moderated' => 'hold',
    120121            'approved'  => 'approve',
     
    223224            ), // singular not used
    224225
     226            /* translators: %s: current user's comments count */
     227            'mine' => _nx_noop(
     228                'Mine <span class="count">(%s)</span>',
     229                'Mine <span class="count">(%s)</span>',
     230                'comments'
     231            ),
     232
    225233            /* translators: %s: pending comments count */
    226234            'moderated' => _nx_noop(
     
    266274            if ( $status === $comment_status ) {
    267275                $current_link_attributes = ' class="current" aria-current="page"';
     276            }
     277
     278            if ( 'mine' === $status ) {
     279                $current_user_id    = get_current_user_id();
     280                $num_comments->mine = get_comments( array(
     281                    'user_id' => $current_user_id,
     282                    'count'   => true,
     283                ) );
     284                $link = add_query_arg( 'user_id', $current_user_id, $link );
     285            } else {
     286                $link = remove_query_arg( 'user_id', $link );
    268287            }
    269288
     
    294313         *
    295314         * @since 2.5.0
    296          *
    297          * @param array $status_links An array of fully-formed status links. Default 'All'.
    298          *                            Accepts 'All', 'Pending', 'Approved', 'Spam', and 'Trash'.
     315         * @since 5.0.0 The 'Mine' link was added.
     316         *
     317         * @param string[] $status_links An associative array of fully-formed comment status links. Includes 'All', 'Mine',
     318         *                              'Pending', 'Approved', 'Spam', and 'Trash'.
    299319         */
    300320        return apply_filters( 'comment_status_links', $status_links );
Note: See TracChangeset for help on using the changeset viewer.