WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (21 months ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/edit-comments.php

    r42228 r42343  
    1717}
    1818
    19 $wp_list_table = _get_list_table('WP_Comments_List_Table');
    20 $pagenum = $wp_list_table->get_pagenum();
     19$wp_list_table = _get_list_table( 'WP_Comments_List_Table' );
     20$pagenum       = $wp_list_table->get_pagenum();
    2121
    2222$doaction = $wp_list_table->current_action();
     
    2525    check_admin_referer( 'bulk-comments' );
    2626
    27     if ( 'delete_all' == $doaction && !empty( $_REQUEST['pagegen_timestamp'] ) ) {
     27    if ( 'delete_all' == $doaction && ! empty( $_REQUEST['pagegen_timestamp'] ) ) {
    2828        $comment_status = wp_unslash( $_REQUEST['comment_status'] );
    29         $delete_time = wp_unslash( $_REQUEST['pagegen_timestamp'] );
    30         $comment_ids = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s AND %s > comment_date_gmt", $comment_status, $delete_time ) );
    31         $doaction = 'delete';
     29        $delete_time    = wp_unslash( $_REQUEST['pagegen_timestamp'] );
     30        $comment_ids    = $wpdb->get_col( $wpdb->prepare( "SELECT comment_ID FROM $wpdb->comments WHERE comment_approved = %s AND %s > comment_date_gmt", $comment_status, $delete_time ) );
     31        $doaction       = 'delete';
    3232    } elseif ( isset( $_REQUEST['delete_comments'] ) ) {
    3333        $comment_ids = $_REQUEST['delete_comments'];
    34         $doaction = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2'];
     34        $doaction    = ( $_REQUEST['action'] != -1 ) ? $_REQUEST['action'] : $_REQUEST['action2'];
    3535    } elseif ( isset( $_REQUEST['ids'] ) ) {
    3636        $comment_ids = array_map( 'absint', explode( ',', $_REQUEST['ids'] ) );
     
    4848
    4949    foreach ( $comment_ids as $comment_id ) { // Check the permissions on each
    50         if ( !current_user_can( 'edit_comment', $comment_id ) )
     50        if ( ! current_user_can( 'edit_comment', $comment_id ) ) {
    5151            continue;
     52        }
    5253
    5354        switch ( $doaction ) {
    54             case 'approve' :
     55            case 'approve':
    5556                wp_set_comment_status( $comment_id, 'approve' );
    5657                $approved++;
    5758                break;
    58             case 'unapprove' :
     59            case 'unapprove':
    5960                wp_set_comment_status( $comment_id, 'hold' );
    6061                $unapproved++;
    6162                break;
    62             case 'spam' :
     63            case 'spam':
    6364                wp_spam_comment( $comment_id );
    6465                $spammed++;
    6566                break;
    66             case 'unspam' :
     67            case 'unspam':
    6768                wp_unspam_comment( $comment_id );
    6869                $unspammed++;
    6970                break;
    70             case 'trash' :
     71            case 'trash':
    7172                wp_trash_comment( $comment_id );
    7273                $trashed++;
    7374                break;
    74             case 'untrash' :
     75            case 'untrash':
    7576                wp_untrash_comment( $comment_id );
    7677                $untrashed++;
    7778                break;
    78             case 'delete' :
     79            case 'delete':
    7980                wp_delete_comment( $comment_id );
    8081                $deleted++;
     
    105106    wp_defer_comment_counting( false );
    106107
    107     if ( $approved )
     108    if ( $approved ) {
    108109        $redirect_to = add_query_arg( 'approved', $approved, $redirect_to );
    109     if ( $unapproved )
     110    }
     111    if ( $unapproved ) {
    110112        $redirect_to = add_query_arg( 'unapproved', $unapproved, $redirect_to );
    111     if ( $spammed )
     113    }
     114    if ( $spammed ) {
    112115        $redirect_to = add_query_arg( 'spammed', $spammed, $redirect_to );
    113     if ( $unspammed )
     116    }
     117    if ( $unspammed ) {
    114118        $redirect_to = add_query_arg( 'unspammed', $unspammed, $redirect_to );
    115     if ( $trashed )
     119    }
     120    if ( $trashed ) {
    116121        $redirect_to = add_query_arg( 'trashed', $trashed, $redirect_to );
    117     if ( $untrashed )
     122    }
     123    if ( $untrashed ) {
    118124        $redirect_to = add_query_arg( 'untrashed', $untrashed, $redirect_to );
    119     if ( $deleted )
     125    }
     126    if ( $deleted ) {
    120127        $redirect_to = add_query_arg( 'deleted', $deleted, $redirect_to );
    121     if ( $trashed || $spammed )
     128    }
     129    if ( $trashed || $spammed ) {
    122130        $redirect_to = add_query_arg( 'ids', join( ',', $comment_ids ), $redirect_to );
     131    }
    123132
    124133    wp_safe_redirect( $redirect_to );
     
    131140$wp_list_table->prepare_items();
    132141
    133 wp_enqueue_script('admin-comments');
     142wp_enqueue_script( 'admin-comments' );
    134143enqueue_comment_hotkeys_js();
    135144
    136145if ( $post_id ) {
    137     $comments_count = wp_count_comments( $post_id );
     146    $comments_count      = wp_count_comments( $post_id );
    138147    $draft_or_post_title = wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '…' );
    139148    if ( $comments_count->moderated > 0 ) {
    140149        /* translators: 1: comments count 2: post title */
    141         $title = sprintf( __( 'Comments (%1$s) on “%2$s”' ),
     150        $title = sprintf(
     151            __( 'Comments (%1$s) on “%2$s”' ),
    142152            number_format_i18n( $comments_count->moderated ),
    143153            $draft_or_post_title
     
    145155    } else {
    146156        /* translators: %s: post title */
    147         $title = sprintf( __( 'Comments on “%s”' ),
     157        $title = sprintf(
     158            __( 'Comments on “%s”' ),
    148159            $draft_or_post_title
    149160        );
     
    153164    if ( $comments_count->moderated > 0 ) {
    154165        /* translators: %s: comments count */
    155         $title = sprintf( __( 'Comments (%s)' ),
     166        $title = sprintf(
     167            __( 'Comments (%s)' ),
    156168            number_format_i18n( $comments_count->moderated )
    157169        );
     
    163175add_screen_option( 'per_page' );
    164176
    165 get_current_screen()->add_help_tab( array(
    166 'id'        => 'overview',
    167 'title'     => __('Overview'),
    168 'content'   =>
    169     '<p>' . __( 'You can manage comments made on your site similar to the way you manage posts and other content. This screen is customizable in the same ways as other management screens, and you can act on comments using the on-hover action links or the Bulk Actions.' ) . '</p>'
    170 ) );
    171 get_current_screen()->add_help_tab( array(
    172 'id'        => 'moderating-comments',
    173 'title'     => __('Moderating Comments'),
    174 'content'   =>
    175         '<p>' . __( 'A red bar on the left means the comment is waiting for you to moderate it.' ) . '</p>' .
    176         '<p>' . __( 'In the <strong>Author</strong> column, in addition to the author&#8217;s name, email address, and blog URL, the commenter&#8217;s IP address is shown. Clicking on this link will show you all the comments made from this IP address.' ) . '</p>' .
    177         '<p>' . __( 'In the <strong>Comment</strong> column, hovering over any comment gives you options to approve, reply (and approve), quick edit, edit, spam mark, or trash that comment.' ) . '</p>' .
    178         '<p>' . __( 'In the <strong>In Response To</strong> column, there are three elements. The text is the name of the post that inspired the comment, and links to the post editor for that entry. The View Post link leads to that post on your live site. The small bubble with the number in it shows the number of approved comments that post has received. If there are pending comments, a red notification circle with the number of pending comments is displayed. Clicking the notification circle will filter the comments screen to show only pending comments on that post.' ) . '</p>' .
    179         '<p>' . __( 'In the <strong>Submitted On</strong> column, the date and time the comment was left on your site appears. Clicking on the date/time link will take you to that comment on your live site.' ) . '</p>' .
    180         '<p>' . __( 'Many people take advantage of keyboard shortcuts to moderate their comments more quickly. Use the link to the side to learn more.' ) . '</p>'
    181 ) );
     177get_current_screen()->add_help_tab(
     178    array(
     179        'id'      => 'overview',
     180        'title'   => __( 'Overview' ),
     181        'content' =>
     182                 '<p>' . __( 'You can manage comments made on your site similar to the way you manage posts and other content. This screen is customizable in the same ways as other management screens, and you can act on comments using the on-hover action links or the Bulk Actions.' ) . '</p>',
     183    )
     184);
     185get_current_screen()->add_help_tab(
     186    array(
     187        'id'      => 'moderating-comments',
     188        'title'   => __( 'Moderating Comments' ),
     189        'content' =>
     190                     '<p>' . __( 'A red bar on the left means the comment is waiting for you to moderate it.' ) . '</p>' .
     191                     '<p>' . __( 'In the <strong>Author</strong> column, in addition to the author&#8217;s name, email address, and blog URL, the commenter&#8217;s IP address is shown. Clicking on this link will show you all the comments made from this IP address.' ) . '</p>' .
     192                     '<p>' . __( 'In the <strong>Comment</strong> column, hovering over any comment gives you options to approve, reply (and approve), quick edit, edit, spam mark, or trash that comment.' ) . '</p>' .
     193                     '<p>' . __( 'In the <strong>In Response To</strong> column, there are three elements. The text is the name of the post that inspired the comment, and links to the post editor for that entry. The View Post link leads to that post on your live site. The small bubble with the number in it shows the number of approved comments that post has received. If there are pending comments, a red notification circle with the number of pending comments is displayed. Clicking the notification circle will filter the comments screen to show only pending comments on that post.' ) . '</p>' .
     194                     '<p>' . __( 'In the <strong>Submitted On</strong> column, the date and time the comment was left on your site appears. Clicking on the date/time link will take you to that comment on your live site.' ) . '</p>' .
     195                     '<p>' . __( 'Many people take advantage of keyboard shortcuts to moderate their comments more quickly. Use the link to the side to learn more.' ) . '</p>',
     196    )
     197);
    182198
    183199get_current_screen()->set_help_sidebar(
     
    189205);
    190206
    191 get_current_screen()->set_screen_reader_content( array(
    192     'heading_views'      => __( 'Filter comments list' ),
    193     'heading_pagination' => __( 'Comments list navigation' ),
    194     'heading_list'       => __( 'Comments list' ),
    195 ) );
     207get_current_screen()->set_screen_reader_content(
     208    array(
     209        'heading_views'      => __( 'Filter comments list' ),
     210        'heading_pagination' => __( 'Comments list navigation' ),
     211        'heading_list'       => __( 'Comments list' ),
     212    )
     213);
    196214
    197215require_once( ABSPATH . 'wp-admin/admin-header.php' );
     
    199217
    200218<div class="wrap">
    201 <h1 class="wp-heading-inline"><?php
     219<h1 class="wp-heading-inline">
     220<?php
    202221if ( $post_id ) {
    203222    /* translators: %s: link to post */
    204     printf( __( 'Comments on &#8220;%s&#8221;' ),
    205         sprintf( '<a href="%1$s">%2$s</a>',
     223    printf(
     224        __( 'Comments on &#8220;%s&#8221;' ),
     225        sprintf(
     226            '<a href="%1$s">%2$s</a>',
    206227            get_edit_post_link( $post_id ),
    207228            wp_html_excerpt( _draft_or_post_title( $post_id ), 50, '&hellip;' )
     
    211232    _e( 'Comments' );
    212233}
    213 ?></h1>
    214 
    215 <?php
    216 if ( isset($_REQUEST['s']) && strlen( $_REQUEST['s'] ) ) {
     234?>
     235</h1>
     236
     237<?php
     238if ( isset( $_REQUEST['s'] ) && strlen( $_REQUEST['s'] ) ) {
    217239    echo '<span class="subtitle">';
    218240    /* translators: %s: search keywords */
    219     printf( __( 'Search results for &#8220;%s&#8221;' ),
     241    printf(
     242        __( 'Search results for &#8220;%s&#8221;' ),
    220243        wp_html_excerpt( esc_html( wp_unslash( $_REQUEST['s'] ) ), 50, '&hellip;' )
    221244    );
     
    228251<?php
    229252if ( isset( $_REQUEST['error'] ) ) {
    230     $error = (int) $_REQUEST['error'];
     253    $error     = (int) $_REQUEST['error'];
    231254    $error_msg = '';
    232255    switch ( $error ) {
    233         case 1 :
     256        case 1:
    234257            $error_msg = __( 'Invalid comment ID.' );
    235258            break;
    236         case 2 :
     259        case 2:
    237260            $error_msg = __( 'Sorry, you are not allowed to edit comments on this post.' );
    238261            break;
    239262    }
    240     if ( $error_msg )
     263    if ( $error_msg ) {
    241264        echo '<div id="moderated" class="error"><p>' . $error_msg . '</p></div>';
    242 }
    243 
    244 if ( isset($_REQUEST['approved']) || isset($_REQUEST['deleted']) || isset($_REQUEST['trashed']) || isset($_REQUEST['untrashed']) || isset($_REQUEST['spammed']) || isset($_REQUEST['unspammed']) || isset($_REQUEST['same']) ) {
    245     $approved  = isset( $_REQUEST['approved']  ) ? (int) $_REQUEST['approved']  : 0;
    246     $deleted   = isset( $_REQUEST['deleted']   ) ? (int) $_REQUEST['deleted']   : 0;
    247     $trashed   = isset( $_REQUEST['trashed']   ) ? (int) $_REQUEST['trashed']   : 0;
     265    }
     266}
     267
     268if ( isset( $_REQUEST['approved'] ) || isset( $_REQUEST['deleted'] ) || isset( $_REQUEST['trashed'] ) || isset( $_REQUEST['untrashed'] ) || isset( $_REQUEST['spammed'] ) || isset( $_REQUEST['unspammed'] ) || isset( $_REQUEST['same'] ) ) {
     269    $approved  = isset( $_REQUEST['approved'] ) ? (int) $_REQUEST['approved'] : 0;
     270    $deleted   = isset( $_REQUEST['deleted'] ) ? (int) $_REQUEST['deleted'] : 0;
     271    $trashed   = isset( $_REQUEST['trashed'] ) ? (int) $_REQUEST['trashed'] : 0;
    248272    $untrashed = isset( $_REQUEST['untrashed'] ) ? (int) $_REQUEST['untrashed'] : 0;
    249     $spammed   = isset( $_REQUEST['spammed']   ) ? (int) $_REQUEST['spammed']  : 0;
     273    $spammed   = isset( $_REQUEST['spammed'] ) ? (int) $_REQUEST['spammed'] : 0;
    250274    $unspammed = isset( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0;
    251     $same      = isset( $_REQUEST['same'] )      ? (int) $_REQUEST['same']      : 0;
     275    $same      = isset( $_REQUEST['same'] ) ? (int) $_REQUEST['same'] : 0;
    252276
    253277    if ( $approved > 0 || $deleted > 0 || $trashed > 0 || $untrashed > 0 || $spammed > 0 || $unspammed > 0 || $same > 0 ) {
     
    258282
    259283        if ( $spammed > 0 ) {
    260             $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0;
     284            $ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
    261285            /* translators: %s: number of comments marked as spam */
    262             $messages[] = sprintf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
     286            $messages[] = sprintf( _n( '%s comment marked as spam.', '%s comments marked as spam.', $spammed ), $spammed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=unspam&ids=$ids", 'bulk-comments' ) ) . '">' . __( 'Undo' ) . '</a><br />';
    263287        }
    264288
     
    269293
    270294        if ( $trashed > 0 ) {
    271             $ids = isset($_REQUEST['ids']) ? $_REQUEST['ids'] : 0;
     295            $ids = isset( $_REQUEST['ids'] ) ? $_REQUEST['ids'] : 0;
    272296            /* translators: %s: number of comments moved to the Trash */
    273             $messages[] = sprintf( _n( '%s comment moved to the Trash.', '%s comments moved to the Trash.', $trashed ), $trashed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", "bulk-comments" ) ) . '">' . __('Undo') . '</a><br />';
     297            $messages[] = sprintf( _n( '%s comment moved to the Trash.', '%s comments moved to the Trash.', $trashed ), $trashed ) . ' <a href="' . esc_url( wp_nonce_url( "edit-comments.php?doaction=undo&action=untrash&ids=$ids", 'bulk-comments' ) ) . '">' . __( 'Undo' ) . '</a><br />';
    274298        }
    275299
     
    286310        if ( $same > 0 && $comment = get_comment( $same ) ) {
    287311            switch ( $comment->comment_approved ) {
    288                 case '1' :
    289                     $messages[] = __('This comment is already approved.') . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
     312                case '1':
     313                    $messages[] = __( 'This comment is already approved.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
    290314                    break;
    291                 case 'trash' :
     315                case 'trash':
    292316                    $messages[] = __( 'This comment is already in the Trash.' ) . ' <a href="' . esc_url( admin_url( 'edit-comments.php?comment_status=trash' ) ) . '"> ' . __( 'View Trash' ) . '</a>';
    293317                    break;
    294                 case 'spam' :
     318                case 'spam':
    295319                    $messages[] = __( 'This comment is already marked as spam.' ) . ' <a href="' . esc_url( admin_url( "comment.php?action=editcomment&c=$same" ) ) . '">' . __( 'Edit comment' ) . '</a>';
    296320                    break;
     
    312336<input type="hidden" name="p" value="<?php echo esc_attr( intval( $post_id ) ); ?>" />
    313337<?php endif; ?>
    314 <input type="hidden" name="comment_status" value="<?php echo esc_attr($comment_status); ?>" />
    315 <input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr(current_time('mysql', 1)); ?>" />
    316 
    317 <input type="hidden" name="_total" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('total_items') ); ?>" />
    318 <input type="hidden" name="_per_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('per_page') ); ?>" />
    319 <input type="hidden" name="_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg('page') ); ?>" />
    320 
    321 <?php if ( isset($_REQUEST['paged']) ) { ?>
     338<input type="hidden" name="comment_status" value="<?php echo esc_attr( $comment_status ); ?>" />
     339<input type="hidden" name="pagegen_timestamp" value="<?php echo esc_attr( current_time( 'mysql', 1 ) ); ?>" />
     340
     341<input type="hidden" name="_total" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg( 'total_items' ) ); ?>" />
     342<input type="hidden" name="_per_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg( 'per_page' ) ); ?>" />
     343<input type="hidden" name="_page" value="<?php echo esc_attr( $wp_list_table->get_pagination_arg( 'page' ) ); ?>" />
     344
     345<?php if ( isset( $_REQUEST['paged'] ) ) { ?>
    322346    <input type="hidden" name="paged" value="<?php echo esc_attr( absint( $_REQUEST['paged'] ) ); ?>" />
    323347<?php } ?>
     
    330354
    331355<?php
    332 wp_comment_reply('-1', true, 'detail');
     356wp_comment_reply( '-1', true, 'detail' );
    333357wp_comment_trashnotice();
    334358include( ABSPATH . 'wp-admin/admin-footer.php' ); ?>
Note: See TracChangeset for help on using the changeset viewer.