Make WordPress Core


Ignore:
Timestamp:
02/12/2023 06:06:33 PM (19 months ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Rename $comment_ID variable to $comment_id in various files.

This resolves 80+ WPCS warnings in core:

Variable "$comment_ID" is not in valid snake_case format

While matching the database field of the same name, the $comment_ID variable did not follow the WordPress coding standards, and is now renamed to address that.

This affects:

  • Function parameters in:
    • get_comment_author()
    • comment_author()
    • get_comment_author_email()
    • comment_author_email()
    • get_comment_author_link()
    • comment_author_link()
    • get_comment_author_IP()
    • comment_author_IP()
    • get_comment_author_rl()
    • comment_author_url()
    • get_comment_date()
    • comment_date()
    • get_comment_excerpt()
    • comment_excerpt()
    • get_comment_text()
    • comment_text()
    • get_comment_time()
    • comment_time()
    • get_comment_type()
    • get_page_of_comment()
    • wp_new_comment_notify_moderator()
    • wp_new_comment_notify_postauthor()
    • get_commentdata()
  • Internal variables in:
    • get_comment_ID()
    • wp_new_comment()
    • wp_xmlrpc_server::wp_deleteComment()
    • wp_xmlrpc_server::wp_editComment()
    • wp_xmlrpc_server::wp_newComment()
    • wp_xmlrpc_server::pingback_ping()
  • Hook parameters in:
    • get_comment_author
    • comment_author
    • get_comment_author_email
    • author_email
    • get_comment_author_link
    • get_comment_author_IP
    • get_comment_author_url
    • comment_url
    • get_comment_excerpt
    • comment_excerpt
    • get_comment_ID
    • get_comment_type
    • get_page_of_comment
    • comment_{$new_status}_{$comment->comment_type}
    • comment_post
    • notify_moderator
    • notify_post_author
    • commentrss2_item
    • xmlrpc_call_success_wp_deleteComment
    • xmlrpc_call_success_wp_editComment
    • xmlrpc_call_success_wp_newComment
    • pingback_post

Note: The name change only affects variable names and DocBlocks.

The change does not affect:

  • comment_ID as the $orderby value in WP_Comment_Query::__construct()
  • comment_ID as the $orderby value in WP_Comment::get_children()
  • comment_ID as part of $commentarr parameter in wp_update_comment()

The associated array keys still match the database field.

Follow-up to [53723].

Props krunal265, costdev, SergeyBiryukov.
Fixes #57671. See #56791.

File:
1 edited

Legend:

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

    r55258 r55308  
    10401040 * @global wpdb $wpdb WordPress database abstraction object.
    10411041 *
    1042  * @param int   $comment_ID Comment ID.
     1042 * @param int   $comment_id Comment ID.
    10431043 * @param array $args {
    10441044 *     Array of optional arguments.
     
    10501050 *                                 Defaults to the value of the 'comments_per_page' option.
    10511051 *     @type int|string $max_depth If greater than 1, comment page will be determined
    1052  *                                 for the top-level parent `$comment_ID`.
     1052 *                                 for the top-level parent `$comment_id`.
    10531053 *                                 Defaults to the value of the 'thread_comments_depth' option.
    10541054 * } *
    10551055 * @return int|null Comment page number or null on error.
    10561056 */
    1057 function get_page_of_comment( $comment_ID, $args = array() ) {
     1057function get_page_of_comment( $comment_id, $args = array() ) {
    10581058    global $wpdb;
    10591059
    10601060    $page = null;
    10611061
    1062     $comment = get_comment( $comment_ID );
     1062    $comment = get_comment( $comment_id );
    10631063    if ( ! $comment ) {
    10641064        return;
     
    11761176     *
    11771177     * @since 4.4.0
    1178      * @since 4.7.0 Introduced the `$comment_ID` parameter.
     1178     * @since 4.7.0 Introduced the `$comment_id` parameter.
    11791179     *
    11801180     * @param int   $page          Comment page.
     
    11971197     *     @type int    $max_depth Maximum comment threading depth allowed.
    11981198     * }
    1199      * @param int $comment_ID ID of the comment.
    1200      */
    1201     return apply_filters( 'get_page_of_comment', (int) $page, $args, $original_args, $comment_ID );
     1199     * @param int $comment_id ID of the comment.
     1200     */
     1201    return apply_filters( 'get_page_of_comment', (int) $page, $args, $original_args, $comment_id );
    12021202}
    12031203
     
    18381838     * @since 2.7.0
    18391839     *
    1840      * @param string     $comment_ID The comment ID as a numeric string.
     1840     * @param string     $comment_id The comment ID as a numeric string.
    18411841     * @param WP_Comment $comment    Comment object.
    18421842     */
     
    22822282    }
    22832283
    2284     $comment_ID = wp_insert_comment( $commentdata );
    2285 
    2286     if ( ! $comment_ID ) {
     2284    $comment_id = wp_insert_comment( $commentdata );
     2285
     2286    if ( ! $comment_id ) {
    22872287        $fields = array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content' );
    22882288
     
    23002300        }
    23012301
    2302         $comment_ID = wp_insert_comment( $commentdata );
    2303         if ( ! $comment_ID ) {
     2302        $comment_id = wp_insert_comment( $commentdata );
     2303        if ( ! $comment_id ) {
    23042304            return false;
    23052305        }
     
    23122312     * @since 4.5.0 The `$commentdata` parameter was added.
    23132313     *
    2314      * @param int        $comment_ID       The comment ID.
     2314     * @param int        $comment_id       The comment ID.
    23152315     * @param int|string $comment_approved 1 if the comment is approved, 0 if not, 'spam' if spam.
    23162316     * @param array      $commentdata      Comment data.
    23172317     */
    2318     do_action( 'comment_post', $comment_ID, $commentdata['comment_approved'], $commentdata );
    2319 
    2320     return $comment_ID;
     2318    do_action( 'comment_post', $comment_id, $commentdata['comment_approved'], $commentdata );
     2319
     2320    return $comment_id;
    23212321}
    23222322
     
    23262326 * @since 4.4.0
    23272327 *
    2328  * @param int $comment_ID ID of the comment.
     2328 * @param int $comment_id ID of the comment.
    23292329 * @return bool True on success, false on failure.
    23302330 */
    2331 function wp_new_comment_notify_moderator( $comment_ID ) {
    2332     $comment = get_comment( $comment_ID );
     2331function wp_new_comment_notify_moderator( $comment_id ) {
     2332    $comment = get_comment( $comment_id );
    23332333
    23342334    // Only send notifications for pending comments.
     
    23362336
    23372337    /** This filter is documented in wp-includes/comment.php */
    2338     $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_ID );
     2338    $maybe_notify = apply_filters( 'notify_moderator', $maybe_notify, $comment_id );
    23392339
    23402340    if ( ! $maybe_notify ) {
     
    23422342    }
    23432343
    2344     return wp_notify_moderator( $comment_ID );
     2344    return wp_notify_moderator( $comment_id );
    23452345}
    23462346
     
    23532353 * should be notified when a new comment is added, overriding site setting.
    23542354 *
    2355  * @param int $comment_ID Comment ID.
     2355 * @param int $comment_id Comment ID.
    23562356 * @return bool True on success, false on failure.
    23572357 */
    2358 function wp_new_comment_notify_postauthor( $comment_ID ) {
    2359     $comment = get_comment( $comment_ID );
     2358function wp_new_comment_notify_postauthor( $comment_id ) {
     2359    $comment = get_comment( $comment_id );
    23602360
    23612361    $maybe_notify = get_option( 'comments_notify' );
     
    23682368     *
    23692369     * @param bool $maybe_notify Whether to notify the post author about the new comment.
    2370      * @param int  $comment_ID   The ID of the comment for the notification.
    2371      */
    2372     $maybe_notify = apply_filters( 'notify_post_author', $maybe_notify, $comment_ID );
     2370     * @param int  $comment_id   The ID of the comment for the notification.
     2371     */
     2372    $maybe_notify = apply_filters( 'notify_post_author', $maybe_notify, $comment_id );
    23732373
    23742374    /*
     
    23852385    }
    23862386
    2387     return wp_notify_postauthor( $comment_ID );
     2387    return wp_notify_postauthor( $comment_id );
    23882388}
    23892389
Note: See TracChangeset for help on using the changeset viewer.