Make WordPress Core

Changeset 53729


Ignore:
Timestamp:
07/20/2022 02:12:02 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Standardize on user_id when passing data to comment functions.

The wp_new_comment(), wp_update_comment(), and wp_filter_comment() functions already normalize the user_ID parameter internally to user_id, which matches the database field name.

This commit aims to bring some consistency when passing the parameter in core.

The corresponding $user_ID variable is also renamed to $user_id to match the other variables when not referring to the $user_ID global, which has an exception in the WordPress coding standards.

Follow-up to [8543], [8720], [12267], [12300], [26491], [28915], [28922], [34799], [49303].

See #55647, #56244.

Location:
trunk
Files:
5 edited

Legend:

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

    r53723 r53729  
    12981298
    12991299        if ( $user->exists() ) {
    1300                 $user_ID              = $user->ID;
     1300                $user_id              = $user->ID;
    13011301                $comment_author       = wp_slash( $user->display_name );
    13021302                $comment_author_email = wp_slash( $user->user_email );
    … …  
    13441344                'comment_type',
    13451345                'comment_parent',
    1346                 'user_ID'
     1346                'user_id'
    13471347        );
    13481348
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r53723 r53729  
    39513951                        $comment['comment_author_email'] = $this->escape( $user_email );
    39523952                        $comment['comment_author_url']   = $this->escape( $user_url );
    3953                         $comment['user_ID']              = $user->ID;
     3953                        $comment['user_id']              = $user->ID;
    39543954                } else {
    39553955                        $comment['comment_author'] = '';
    … …  
    39683968                        }
    39693969
    3970                         $comment['user_ID'] = 0;
     3970                        $comment['user_id'] = 0;
    39713971
    39723972                        if ( get_option( 'require_name_email' ) ) {
  • trunk/src/wp-includes/comment.php

    r53723 r53729  
    20902090                 * Filters the comment author's user ID before it is set.
    20912091                 *
    2092                  * The first time this filter is evaluated, 'user_ID' is checked
    2093                  * (for back-compat), followed by the standard 'user_id' value.
     2092                 * The first time this filter is evaluated, `user_ID` is checked
     2093                 * (for back-compat), followed by the standard `user_id` value.
    20942094                 *
    20952095                 * @since 1.5.0
    20962096                 *
    2097                  * @param int $user_ID The comment author's user ID.
     2097                 * @param int $user_id The comment author's user ID.
    20982098                 */
    20992099                $commentdata['user_id'] = apply_filters( 'pre_user_id', $commentdata['user_ID'] );
    … …  
    21332133        /** This filter is documented in wp-includes/comment.php */
    21342134        $commentdata['comment_author_email'] = apply_filters( 'pre_comment_author_email', $commentdata['comment_author_email'] );
    2135         $commentdata['filtered']             = true;
     2135
     2136        $commentdata['filtered'] = true;
     2137
    21362138        return $commentdata;
    21372139}
    … …  
    22662268
    22672269        $commentdata['comment_approved'] = wp_allow_comment( $commentdata, $wp_error );
     2270
    22682271        if ( is_wp_error( $commentdata['comment_approved'] ) ) {
    22692272                return $commentdata['comment_approved'];
    … …  
    22712274
    22722275        $comment_ID = wp_insert_comment( $commentdata );
     2276
    22732277        if ( ! $comment_ID ) {
    22742278                $fields = array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content' );
    … …  
    24692473        // First, get all of the original fields.
    24702474        $comment = get_comment( $commentarr['comment_ID'], ARRAY_A );
     2475
    24712476        if ( empty( $comment ) ) {
    24722477                if ( $wp_error ) {
    … …  
    34223427 */
    34233428function wp_handle_comment_submission( $comment_data ) {
    3424 
    34253429        $comment_post_id      = 0;
    3426         $comment_parent       = 0;
    3427         $user_ID              = 0;
    34283430        $comment_author       = null;
    34293431        $comment_author_email = null;
    34303432        $comment_author_url   = null;
    34313433        $comment_content      = null;
     3434        $comment_parent       = 0;
     3435        $user_id              = 0;
    34323436
    34333437        if ( isset( $comment_data['comment_post_ID'] ) ) {
    … …  
    35543558                $comment_author_email = $user->user_email;
    35553559                $comment_author_url   = $user->user_url;
    3556                 $user_ID              = $user->ID;
     3560                $user_id              = $user->ID;
    35573561
    35583562                if ( current_user_can( 'unfiltered_html' ) ) {
    … …  
    35843588        $commentdata = array(
    35853589                'comment_post_ID' => $comment_post_id,
     3590                'user_ID'         => $user_id,
    35863591        );
    35873592
    … …  
    35933598                'comment_type',
    35943599                'comment_parent',
    3595                 'user_ID'
    35963600        );
    35973601
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php

    r53139 r53729  
    18841884                        array(
    18851885                                'comment_post_ID'      => 0,
    1886                                 'comment_parent'       => 0,
    1887                                 'user_ID'              => 0,
    18881886                                'comment_author'       => null,
    18891887                                'comment_author_email' => null,
    18901888                                'comment_author_url'   => null,
     1889                                'comment_parent'       => 0,
     1890                                'user_id'              => 0,
    18911891                        )
    18921892                );
  • trunk/tests/phpunit/tests/comment-submission.php

    r52010 r53729  
    812812
    813813                $this->assertNotWPError( $comment );
    814                 $this->assertSame(
     814                $this->assertSameSets(
    815815                        array(
    816816                                'comment_post_ID'      => self::$post->ID,
Note: See TracChangeset for help on using the changeset viewer.