Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (8 years 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/includes/comment.php

    r37914 r42343  
    3333    }
    3434
    35     return $wpdb->get_var( $wpdb->prepare("SELECT comment_post_ID FROM $wpdb->comments
     35    return $wpdb->get_var(
     36        $wpdb->prepare(
     37            "SELECT comment_post_ID FROM $wpdb->comments
    3638            WHERE comment_author = %s AND $date_field = %s",
    3739            stripslashes( $comment_author ),
    3840            stripslashes( $comment_date )
    39     ) );
     41        )
     42    );
    4043}
    4144
     
    4649 */
    4750function edit_comment() {
    48     if ( ! current_user_can( 'edit_comment', (int) $_POST['comment_ID'] ) )
    49         wp_die ( __( 'Sorry, you are not allowed to edit comments on this post.' ) );
    50 
    51     if ( isset( $_POST['newcomment_author'] ) )
     51    if ( ! current_user_can( 'edit_comment', (int) $_POST['comment_ID'] ) ) {
     52        wp_die( __( 'Sorry, you are not allowed to edit comments on this post.' ) );
     53    }
     54
     55    if ( isset( $_POST['newcomment_author'] ) ) {
    5256        $_POST['comment_author'] = $_POST['newcomment_author'];
    53     if ( isset( $_POST['newcomment_author_email'] ) )
     57    }
     58    if ( isset( $_POST['newcomment_author_email'] ) ) {
    5459        $_POST['comment_author_email'] = $_POST['newcomment_author_email'];
    55     if ( isset( $_POST['newcomment_author_url'] ) )
     60    }
     61    if ( isset( $_POST['newcomment_author_url'] ) ) {
    5662        $_POST['comment_author_url'] = $_POST['newcomment_author_url'];
    57     if ( isset( $_POST['comment_status'] ) )
     63    }
     64    if ( isset( $_POST['comment_status'] ) ) {
    5865        $_POST['comment_approved'] = $_POST['comment_status'];
    59     if ( isset( $_POST['content'] ) )
     66    }
     67    if ( isset( $_POST['content'] ) ) {
    6068        $_POST['comment_content'] = $_POST['content'];
    61     if ( isset( $_POST['comment_ID'] ) )
     69    }
     70    if ( isset( $_POST['comment_ID'] ) ) {
    6271        $_POST['comment_ID'] = (int) $_POST['comment_ID'];
    63 
    64     foreach ( array ('aa', 'mm', 'jj', 'hh', 'mn') as $timeunit ) {
    65         if ( !empty( $_POST['hidden_' . $timeunit] ) && $_POST['hidden_' . $timeunit] != $_POST[$timeunit] ) {
     72    }
     73
     74    foreach ( array( 'aa', 'mm', 'jj', 'hh', 'mn' ) as $timeunit ) {
     75        if ( ! empty( $_POST[ 'hidden_' . $timeunit ] ) && $_POST[ 'hidden_' . $timeunit ] != $_POST[ $timeunit ] ) {
    6676            $_POST['edit_date'] = '1';
    6777            break;
     
    6979    }
    7080
    71     if ( !empty ( $_POST['edit_date'] ) ) {
    72         $aa = $_POST['aa'];
    73         $mm = $_POST['mm'];
    74         $jj = $_POST['jj'];
    75         $hh = $_POST['hh'];
    76         $mn = $_POST['mn'];
    77         $ss = $_POST['ss'];
    78         $jj = ($jj > 31 ) ? 31 : $jj;
    79         $hh = ($hh > 23 ) ? $hh -24 : $hh;
    80         $mn = ($mn > 59 ) ? $mn -60 : $mn;
    81         $ss = ($ss > 59 ) ? $ss -60 : $ss;
     81    if ( ! empty( $_POST['edit_date'] ) ) {
     82        $aa                    = $_POST['aa'];
     83        $mm                    = $_POST['mm'];
     84        $jj                    = $_POST['jj'];
     85        $hh                    = $_POST['hh'];
     86        $mn                    = $_POST['mn'];
     87        $ss                    = $_POST['ss'];
     88        $jj                    = ( $jj > 31 ) ? 31 : $jj;
     89        $hh                    = ( $hh > 23 ) ? $hh - 24 : $hh;
     90        $mn                    = ( $mn > 59 ) ? $mn - 60 : $mn;
     91        $ss                    = ( $ss > 59 ) ? $ss - 60 : $ss;
    8292        $_POST['comment_date'] = "$aa-$mm-$jj $hh:$mn:$ss";
    8393    }
     
    95105 */
    96106function get_comment_to_edit( $id ) {
    97     if ( !$comment = get_comment($id) )
     107    if ( ! $comment = get_comment( $id ) ) {
    98108        return false;
    99 
    100     $comment->comment_ID = (int) $comment->comment_ID;
     109    }
     110
     111    $comment->comment_ID      = (int) $comment->comment_ID;
    101112    $comment->comment_post_ID = (int) $comment->comment_post_ID;
    102113
     
    111122    $comment->comment_content = apply_filters( 'comment_edit_pre', $comment->comment_content );
    112123
    113     $comment->comment_author = format_to_edit( $comment->comment_author );
     124    $comment->comment_author       = format_to_edit( $comment->comment_author );
    114125    $comment->comment_author_email = format_to_edit( $comment->comment_author_email );
    115     $comment->comment_author_url = format_to_edit( $comment->comment_author_url );
    116     $comment->comment_author_url = esc_url($comment->comment_author_url);
     126    $comment->comment_author_url   = format_to_edit( $comment->comment_author_url );
     127    $comment->comment_author_url   = esc_url( $comment->comment_author_url );
    117128
    118129    return $comment;
     
    133144
    134145    $single = false;
    135     if ( !is_array($post_id) ) {
     146    if ( ! is_array( $post_id ) ) {
    136147        $post_id_array = (array) $post_id;
    137         $single = true;
     148        $single        = true;
    138149    } else {
    139150        $post_id_array = $post_id;
    140151    }
    141     $post_id_array = array_map('intval', $post_id_array);
    142     $post_id_in = "'" . implode("', '", $post_id_array) . "'";
     152    $post_id_array = array_map( 'intval', $post_id_array );
     153    $post_id_in    = "'" . implode( "', '", $post_id_array ) . "'";
    143154
    144155    $pending = $wpdb->get_results( "SELECT comment_post_ID, COUNT(comment_ID) as num_comments FROM $wpdb->comments WHERE comment_post_ID IN ( $post_id_in ) AND comment_approved = '0' GROUP BY comment_post_ID", ARRAY_A );
    145156
    146157    if ( $single ) {
    147         if ( empty($pending) )
     158        if ( empty( $pending ) ) {
    148159            return 0;
    149         else
    150             return absint($pending[0]['num_comments']);
     160        } else {
     161            return absint( $pending[0]['num_comments'] );
     162        }
    151163    }
    152164
     
    154166
    155167    // Default to zero pending for all posts in request
    156     foreach ( $post_id_array as $id )
    157         $pending_keyed[$id] = 0;
    158 
    159     if ( !empty($pending) )
    160         foreach ( $pending as $pend )
    161             $pending_keyed[$pend['comment_post_ID']] = absint($pend['num_comments']);
     168    foreach ( $post_id_array as $id ) {
     169        $pending_keyed[ $id ] = 0;
     170    }
     171
     172    if ( ! empty( $pending ) ) {
     173        foreach ( $pending as $pend ) {
     174            $pending_keyed[ $pend['comment_post_ID'] ] = absint( $pend['num_comments'] );
     175        }
     176    }
    162177
    163178    return $pending_keyed;
     
    181196 */
    182197function enqueue_comment_hotkeys_js() {
    183     if ( 'true' == get_user_option( 'comment_shortcuts' ) )
     198    if ( 'true' == get_user_option( 'comment_shortcuts' ) ) {
    184199        wp_enqueue_script( 'jquery-table-hotkeys' );
     200    }
    185201}
    186202
Note: See TracChangeset for help on using the changeset viewer.