Make WordPress Core

Changeset 53723


Ignore:
Timestamp:
07/19/2022 04:17:56 PM (2 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.

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/ajax-actions.php

    r53455 r53723  
    12781278    check_ajax_referer( $action, '_ajax_nonce-replyto-comment' );
    12791279
    1280     $comment_post_ID = (int) $_POST['comment_post_ID'];
    1281     $post            = get_post( $comment_post_ID );
     1280    $comment_post_id = (int) $_POST['comment_post_ID'];
     1281    $post            = get_post( $comment_post_id );
    12821282
    12831283    if ( ! $post ) {
     
    12851285    }
    12861286
    1287     if ( ! current_user_can( 'edit_post', $comment_post_ID ) ) {
     1287    if ( ! current_user_can( 'edit_post', $comment_post_id ) ) {
    12881288        wp_die( -1 );
    12891289    }
     
    13321332
    13331333    $comment_auto_approved = false;
    1334     $commentdata           = compact( 'comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID' );
     1334
     1335    $commentdata = array(
     1336        'comment_post_ID' => $comment_post_id,
     1337    );
     1338
     1339    $commentdata += compact(
     1340        'comment_author',
     1341        'comment_author_email',
     1342        'comment_author_url',
     1343        'comment_content',
     1344        'comment_type',
     1345        'comment_parent',
     1346        'user_ID'
     1347    );
    13351348
    13361349    // Automatically approve parent comment.
     
    13381351        $parent = get_comment( $comment_parent );
    13391352
    1340         if ( $parent && '0' === $parent->comment_approved && $parent->comment_post_ID == $comment_post_ID ) {
     1353        if ( $parent && '0' === $parent->comment_approved && $parent->comment_post_ID == $comment_post_id ) {
    13411354            if ( ! current_user_can( 'edit_comment', $parent->comment_ID ) ) {
    13421355                wp_die( -1 );
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r53132 r53723  
    70147014        $pagelinkedfrom = $this->escape( $pagelinkedfrom );
    70157015
    7016         $comment_post_ID      = (int) $post_ID;
     7016        $comment_post_id      = (int) $post_ID;
    70177017        $comment_author       = $title;
    70187018        $comment_author_email = '';
     
    70237023        $comment_type = 'pingback';
    70247024
    7025         $commentdata = compact(
    7026             'comment_post_ID',
     7025        $commentdata = array(
     7026            'comment_post_ID' => $comment_post_id,
     7027        );
     7028
     7029        $commentdata += compact(
    70277030            'comment_author',
    70287031            'comment_author_url',
  • trunk/src/wp-includes/comment-template.php

    r53719 r53723  
    275275     * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
    276276     *
    277      * @param string     $comment_author_IP The comment author's IP address, or an empty string if it's not available.
     277     * @param string     $comment_author_ip The comment author's IP address, or an empty string if it's not available.
    278278     * @param string     $comment_ID        The comment ID as a numeric string.
    279279     * @param WP_Comment $comment           The comment object.
  • 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',
  • trunk/src/wp-includes/post.php

    r53715 r53723  
    43364336
    43374337    // Expected_slashed (everything!).
    4338     $data = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_content_filtered', 'post_title', 'post_excerpt', 'post_status', 'post_type', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping', 'pinged', 'post_modified', 'post_modified_gmt', 'post_parent', 'menu_order', 'post_mime_type', 'guid' );
     4338    $data = compact(
     4339        'post_author',
     4340        'post_date',
     4341        'post_date_gmt',
     4342        'post_content',
     4343        'post_content_filtered',
     4344        'post_title',
     4345        'post_excerpt',
     4346        'post_status',
     4347        'post_type',
     4348        'comment_status',
     4349        'ping_status',
     4350        'post_password',
     4351        'post_name',
     4352        'to_ping',
     4353        'pinged',
     4354        'post_modified',
     4355        'post_modified_gmt',
     4356        'post_parent',
     4357        'menu_order',
     4358        'post_mime_type',
     4359        'guid'
     4360    );
    43394361
    43404362    $emoji_fields = array( 'post_title', 'post_content', 'post_excerpt' );
Note: See TracChangeset for help on using the changeset viewer.