Make WordPress Core


Ignore:
Timestamp:
07/19/2022 04:17:56 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Rename $comment_post_ID and $comment_author_IP variables in various files.

This fixes two WPCS warnings:

  • Variable "$comment_post_ID" is not in valid snake_case format
  • Variable "$comment_author_IP" is not in valid snake_case format

While matching the database fields of the same name, these variables did not follow the WordPress coding standards, and are now renamed to address that.

Note: The name change only affects internal variables and parameters for a few actions receiving a comment post ID:

  • edit_comment
  • comment_id_not_found
  • comment_closed
  • comment_on_trash
  • comment_on_draft
  • comment_on_password_protected
  • pre_comment_on_post

The change does not affect parameters for functions receiving an array of comment data:

  • wp_insert_comment()
  • wp_new_comment()
  • wp_update_comment()
  • wp_handle_comment_submission()

The associated array keys still match the database fields: comment_post_ID and comment_author_IP.

Follow-up to [1706], [2894], [8720], [28427], [28437], [28457], [34799], [53720],

See #55647, #56244.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment.php

    r53715 r53723  
    727727         * @since 5.5.0 The `$avoid_die` parameter was renamed to `$wp_error`.
    728728         *
    729          * @param string $comment_author_IP    Comment author's IP address.
     729         * @param string $comment_author_ip    Comment author's IP address.
    730730         * @param string $comment_author_email Comment author's email.
    731731         * @param string $comment_date_gmt     GMT date the comment was posted.
    … …  
    750750         *
    751751         * @param bool   $is_flood             Is a comment flooding occurring? Default false.
    752          * @param string $comment_author_IP    Comment author's IP address.
     752         * @param string $comment_author_ip    Comment author's IP address.
    753753         * @param string $comment_author_email Comment author's email.
    754754         * @param string $comment_date_gmt     GMT date the comment was posted.
    … …  
    19981998        $comment_author_email = ! isset( $data['comment_author_email'] ) ? '' : $data['comment_author_email'];
    19991999        $comment_author_url   = ! isset( $data['comment_author_url'] ) ? '' : $data['comment_author_url'];
    2000         $comment_author_IP    = ! isset( $data['comment_author_IP'] ) ? '' : $data['comment_author_IP'];
     2000        $comment_author_ip    = ! isset( $data['comment_author_IP'] ) ? '' : $data['comment_author_IP'];
    20012001
    20022002        $comment_date     = ! isset( $data['comment_date'] ) ? current_time( 'mysql' ) : $data['comment_date'];
    20032003        $comment_date_gmt = ! isset( $data['comment_date_gmt'] ) ? get_gmt_from_date( $comment_date ) : $data['comment_date_gmt'];
    20042004
    2005         $comment_post_ID  = ! isset( $data['comment_post_ID'] ) ? 0 : $data['comment_post_ID'];
     2005        $comment_post_id  = ! isset( $data['comment_post_ID'] ) ? 0 : $data['comment_post_ID'];
    20062006        $comment_content  = ! isset( $data['comment_content'] ) ? '' : $data['comment_content'];
    20072007        $comment_karma    = ! isset( $data['comment_karma'] ) ? 0 : $data['comment_karma'];
    … …  
    20132013        $user_id = ! isset( $data['user_id'] ) ? 0 : $data['user_id'];
    20142014
    2015         $compacted = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_date', 'comment_date_gmt', 'comment_content', 'comment_karma', 'comment_approved', 'comment_agent', 'comment_type', 'comment_parent', 'user_id' );
     2015        $compacted = array(
     2016                'comment_post_ID'   => $comment_post_id,
     2017                'comment_author_IP' => $comment_author_ip,
     2018        );
     2019
     2020        $compacted += compact(
     2021                'comment_author',
     2022                'comment_author_email',
     2023                'comment_author_url',
     2024                'comment_date',
     2025                'comment_date_gmt',
     2026                'comment_content',
     2027                'comment_karma',
     2028                'comment_approved',
     2029                'comment_agent',
     2030                'comment_type',
     2031                'comment_parent',
     2032                'user_id'
     2033        );
     2034
    20162035        if ( ! $wpdb->insert( $wpdb->comments, $compacted ) ) {
    20172036                return false;
    … …  
    20212040
    20222041        if ( 1 == $comment_approved ) {
    2023                 wp_update_comment_count( $comment_post_ID );
     2042                wp_update_comment_count( $comment_post_id );
    20242043
    20252044                $data = array();
    … …  
    22142233
    22152234        $commentdata['comment_post_ID'] = (int) $commentdata['comment_post_ID'];
     2235
    22162236        if ( isset( $commentdata['user_ID'] ) && $prefiltered_user_id !== (int) $commentdata['user_ID'] ) {
    22172237                $commentdata['user_ID'] = (int) $commentdata['user_ID'];
    … …  
    24982518        }
    24992519
    2500         $comment_ID      = $data['comment_ID'];
    2501         $comment_post_ID = $data['comment_post_ID'];
     2520        $comment_id      = $data['comment_ID'];
     2521        $comment_post_id = $data['comment_post_ID'];
    25022522
    25032523        /**
    … …  
    25252545        }
    25262546
    2527         $keys = array( 'comment_post_ID', 'comment_content', 'comment_author', 'comment_author_email', 'comment_approved', 'comment_karma', 'comment_author_url', 'comment_date', 'comment_date_gmt', 'comment_type', 'comment_parent', 'user_id', 'comment_agent', 'comment_author_IP' );
     2547        $keys = array(
     2548                'comment_post_ID',
     2549                'comment_author',
     2550                'comment_author_email',
     2551                'comment_author_url',
     2552                'comment_author_IP',
     2553                'comment_date',
     2554                'comment_date_gmt',
     2555                'comment_content',
     2556                'comment_karma',
     2557                'comment_approved',
     2558                'comment_agent',
     2559                'comment_type',
     2560                'comment_parent',
     2561                'user_id',
     2562        );
     2563
    25282564        $data = wp_array_slice_assoc( $data, $keys );
    25292565
    2530         $rval = $wpdb->update( $wpdb->comments, $data, compact( 'comment_ID' ) );
    2531 
    2532         if ( false === $rval ) {
     2566        $result = $wpdb->update( $wpdb->comments, $data, array( 'comment_ID' => $comment_id ) );
     2567
     2568        if ( false === $result ) {
    25332569                if ( $wp_error ) {
    25342570                        return new WP_Error( 'db_update_error', __( 'Could not update comment in the database.' ), $wpdb->last_error );
    … …  
    25412577        if ( isset( $commentarr['comment_meta'] ) && is_array( $commentarr['comment_meta'] ) ) {
    25422578                foreach ( $commentarr['comment_meta'] as $meta_key => $meta_value ) {
    2543                         update_comment_meta( $comment_ID, $meta_key, $meta_value );
    2544                 }
    2545         }
    2546 
    2547         clean_comment_cache( $comment_ID );
    2548         wp_update_comment_count( $comment_post_ID );
     2579                        update_comment_meta( $comment_id, $meta_key, $meta_value );
     2580                }
     2581        }
     2582
     2583        clean_comment_cache( $comment_id );
     2584        wp_update_comment_count( $comment_post_id );
    25492585
    25502586        /**
    … …  
    25562592         * @since 4.6.0 Added the `$data` parameter.
    25572593         *
    2558          * @param int   $comment_ID The comment ID.
     2594         * @param int   $comment_id The comment ID.
    25592595         * @param array $data       Comment data.
    25602596         */
    2561         do_action( 'edit_comment', $comment_ID, $data );
    2562 
    2563         $comment = get_comment( $comment_ID );
     2597        do_action( 'edit_comment', $comment_id, $data );
     2598
     2599        $comment = get_comment( $comment_id );
    25642600
    25652601        wp_transition_comment_status( $comment->comment_approved, $old_status, $comment );
    25662602
    2567         return $rval;
     2603        return $result;
    25682604}
    25692605
    … …  
    33873423function wp_handle_comment_submission( $comment_data ) {
    33883424
    3389         $comment_post_ID      = 0;
     3425        $comment_post_id      = 0;
    33903426        $comment_parent       = 0;
    33913427        $user_ID              = 0;
    … …  
    33963432
    33973433        if ( isset( $comment_data['comment_post_ID'] ) ) {
    3398                 $comment_post_ID = (int) $comment_data['comment_post_ID'];
     3434                $comment_post_id = (int) $comment_data['comment_post_ID'];
    33993435        }
    34003436        if ( isset( $comment_data['author'] ) && is_string( $comment_data['author'] ) ) {
    … …  
    34143450        }
    34153451
    3416         $post = get_post( $comment_post_ID );
     3452        $post = get_post( $comment_post_id );
    34173453
    34183454        if ( empty( $post->comment_status ) ) {
    … …  
    34233459                 * @since 1.5.0
    34243460                 *
    3425                  * @param int $comment_post_ID Post ID.
     3461                 * @param int $comment_post_id Post ID.
    34263462                 */
    3427                 do_action( 'comment_id_not_found', $comment_post_ID );
     3463                do_action( 'comment_id_not_found', $comment_post_id );
    34283464
    34293465                return new WP_Error( 'comment_id_not_found' );
    … …  
    34343470        $status = get_post_status( $post );
    34353471
    3436         if ( ( 'private' === $status ) && ! current_user_can( 'read_post', $comment_post_ID ) ) {
     3472        if ( ( 'private' === $status ) && ! current_user_can( 'read_post', $comment_post_id ) ) {
    34373473                return new WP_Error( 'comment_id_not_found' );
    34383474        }
    … …  
    34403476        $status_obj = get_post_status_object( $status );
    34413477
    3442         if ( ! comments_open( $comment_post_ID ) ) {
     3478        if ( ! comments_open( $comment_post_id ) ) {
    34433479
    34443480                /**
    … …  
    34473483                 * @since 1.5.0
    34483484                 *
    3449                  * @param int $comment_post_ID Post ID.
     3485                 * @param int $comment_post_id Post ID.
    34503486                 */
    3451                 do_action( 'comment_closed', $comment_post_ID );
     3487                do_action( 'comment_closed', $comment_post_id );
    34523488
    34533489                return new WP_Error( 'comment_closed', __( 'Sorry, comments are closed for this item.' ), 403 );
    … …  
    34603496                 * @since 2.9.0
    34613497                 *
    3462                  * @param int $comment_post_ID Post ID.
     3498                 * @param int $comment_post_id Post ID.
    34633499                 */
    3464                 do_action( 'comment_on_trash', $comment_post_ID );
     3500                do_action( 'comment_on_trash', $comment_post_id );
    34653501
    34663502                return new WP_Error( 'comment_on_trash' );
    … …  
    34733509                 * @since 1.5.1
    34743510                 *
    3475                  * @param int $comment_post_ID Post ID.
     3511                 * @param int $comment_post_id Post ID.
    34763512                 */
    3477                 do_action( 'comment_on_draft', $comment_post_ID );
    3478 
    3479                 if ( current_user_can( 'read_post', $comment_post_ID ) ) {
     3513                do_action( 'comment_on_draft', $comment_post_id );
     3514
     3515                if ( current_user_can( 'read_post', $comment_post_id ) ) {
    34803516                        return new WP_Error( 'comment_on_draft', __( 'Sorry, comments are not allowed for this item.' ), 403 );
    34813517                } else {
    34823518                        return new WP_Error( 'comment_on_draft' );
    34833519                }
    3484         } elseif ( post_password_required( $comment_post_ID ) ) {
     3520        } elseif ( post_password_required( $comment_post_id ) ) {
    34853521
    34863522                /**
    … …  
    34893525                 * @since 2.9.0
    34903526                 *
    3491                  * @param int $comment_post_ID Post ID.
     3527                 * @param int $comment_post_id Post ID.
    34923528                 */
    3493                 do_action( 'comment_on_password_protected', $comment_post_ID );
     3529                do_action( 'comment_on_password_protected', $comment_post_id );
    34943530
    34953531                return new WP_Error( 'comment_on_password_protected' );
    … …  
    35023538                 * @since 2.8.0
    35033539                 *
    3504                  * @param int $comment_post_ID Post ID.
     3540                 * @param int $comment_post_id Post ID.
    35053541                 */
    3506                 do_action( 'pre_comment_on_post', $comment_post_ID );
     3542                do_action( 'pre_comment_on_post', $comment_post_id );
    35073543
    35083544        }
    … …  
    35143550                        $user->display_name = $user->user_login;
    35153551                }
     3552
    35163553                $comment_author       = $user->display_name;
    35173554                $comment_author_email = $user->user_email;
    35183555                $comment_author_url   = $user->user_url;
    35193556                $user_ID              = $user->ID;
     3557
    35203558                if ( current_user_can( 'unfiltered_html' ) ) {
    35213559                        if ( ! isset( $comment_data['_wp_unfiltered_html_comment'] )
    3522                                 || ! wp_verify_nonce( $comment_data['_wp_unfiltered_html_comment'], 'unfiltered-html-comment_' . $comment_post_ID )
     3560                                || ! wp_verify_nonce( $comment_data['_wp_unfiltered_html_comment'], 'unfiltered-html-comment_' . $comment_post_id )
    35233561                        ) {
    35243562                                kses_remove_filters(); // Start with a clean slate.
    … …  
    35443582        }
    35453583
    3546         $commentdata = compact(
    3547                 'comment_post_ID',
     3584        $commentdata = array(
     3585                'comment_post_ID' => $comment_post_id,
     3586        );
     3587
     3588        $commentdata += compact(
    35483589                'comment_author',
    35493590                'comment_author_email',
Note: See TracChangeset for help on using the changeset viewer.