Make WordPress Core

Opened 20 months ago

Closed 20 months ago

Last modified 20 months ago

#57671 closed defect (bug) (fixed)

Coding Standards: To maintain a valid snake case format, need to rename $comment_ID variable

Reported by: krunal265's profile krunal265 Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.2 Priority: normal
Severity: normal Version: 6.2
Component: Comments Keywords: has-patch
Focuses: coding-standards Cc:

Description

For the below files:

wp-admin/comment.php
wp-includes/comment-template.php
wp-includes/comment.php

Attachments (1)

57671.diff (38.9 KB) - added by SergeyBiryukov 20 months ago.

Download all attachments as: .zip

Change History (9)

#1 @costdev
20 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi @krunal265, I believe we're already tracking this enhancement in #56261

#2 @SergeyBiryukov
20 months ago

  • Component changed from General to Comments
  • Keywords has-patch added; needs-patch removed
  • Milestone set to 6.2
  • Resolution duplicate deleted
  • Severity changed from major to normal
  • Status changed from closed to reopened
  • Type changed from enhancement to defect (bug)

Hi there, thanks for the ticket!

Yeah, I've started looking into this as well after [55284] / #52322.

Reopening, as this can be done separately from #56261. That ticket is mostly focused on the comment_ID value of the comment data array in functions like wp_new_comment(), wp_update_comment(), or wp_filter_comment(), where plugins may expect both comment_id and comment_ID values to exist in the array.

This ticket can be focused strictly on renaming the $comment_ID variable to match core coding standards. This will affect function parameters, internal variables, and update hook DocBlocks to encourage better practices.

Aside from using PHP 8.0+ named parameters, which WordPress does not explicitly support at this time, backward compatibility should not be affected, so I think this can be done in 6.2 as part of other coding standards fixes.

57671.diff resolves all of these 83 WPCS warnings in core:

Variable "$comment_ID" is not in valid snake_case format, try "$comment_i_d"
Last edited 20 months ago by SergeyBiryukov (previous) (diff)

#3 @SergeyBiryukov
20 months ago

  • Owner set to SergeyBiryukov
  • Status changed from reopened to accepted

#4 @costdev
20 months ago

After a visual inspection, and since we aren't currently avoiding renaming function parameters, the patch looks good to me. PHPUnit tests pass and such too.

#5 @SergeyBiryukov
20 months ago

  • Resolution set to fixed
  • Status changed from accepted to closed

In 55308:

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.

#6 @bph
20 months ago

  • Keywords add-to-field-guide added

Should get a mention in the Misc Dev Note, as there might be extenders out there expecting $comment_ID

"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."
The database fields are still comment_ID

#7 @imath
20 months ago

Hi there,

My bad! Sorry for the noise, @bph asked for my opinion on 6.2 comments tickets & I overthought this one. After a second thought, unless you plan to write about the $post_ID change, I don't think this ticket needs to be mentionned on the field guide.

Last edited 20 months ago by imath (previous) (diff)

#8 @milana_cap
20 months ago

  • Keywords add-to-field-guide removed

This change doesn't really affect extenders so we can omit it from the field guide.

Note: See TracTickets for help on using tickets.