Make WordPress Core

Opened 19 months ago

Last modified 13 months ago

#56261 accepted enhancement

Normalize comment function parameters with mixed case names

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: Future Release Priority: normal
Severity: normal Version:
Component: Comments Keywords: needs-patch
Focuses: docs, coding-standards Cc:

Description

Background: #56244

As of WordPress 2.9, core normalizes the user_ID parameter to user_id when passing data to comment functions, see [12267], [12300], and [28915].

We should consider normalizing other parameters in the same way as it was done for user_IDuser_id:

  • comment_IDcomment_id
  • comment_post_IDcomment_post_id
  • comment_author_IPcomment_author_ip

Then any combination of these parameters would work regardless of the case.

This would allow extenders to name variables in accordance with the WordPress coding standards:

  • $comment_id
  • $comment_post_id
  • $comment_author_ip

and use them subsequently in a compact() call without having to worry about a case mismatch.

This would also allow us to revert some of compact() rearrangements made in [53719] and [53723]:

$compacted = array(
	'comment_post_ID'   => $comment_post_id,
	'comment_author_IP' => $comment_author_ip,
);

$compacted += compact(
	'comment_author',
	'comment_author_email',
	'comment_author_url',
	...
	'user_id'
);

which could then be:

$compacted = compact(
	'comment_post_id',
	'comment_author',
	'comment_author_email',
	'comment_author_url',
	'comment_author_ip',
	...
	'user_id'
);

The list of functions this may affect:

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

Change History (10)

#1 @SergeyBiryukov
19 months ago

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

#2 in reply to: ↑ description @SergeyBiryukov
19 months ago

Replying to SergeyBiryukov:

This would allow extenders to name variables in accordance with the WordPress coding standards:

  • $comment_id
  • $comment_post_id
  • $comment_author_ip

and use them subsequently in a compact() call without having to worry about a case mismatch.

To clarify a bit, this aims to fix WPCS issues like this:

| WARNING | [ ] Variable "$comment_ID" is not in valid snake_case
|         |     format, try "$comment_i_d"
|         |     (WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase)
| WARNING | [ ] Variable "$comment_post_ID" is not in valid snake_case
|         |     format, try "$comment_post_i_d"
|         |     (WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase)
| WARNING | [ ] Variable "$comment_author_IP" is not in valid snake_case
|         |     format, try "$comment_author_i_p"
|         |     (WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase)

This ticket was mentioned in Slack in #core by sergey. View the logs.


19 months ago

#4 @SergeyBiryukov
17 months ago

  • Milestone changed from 6.1 to 6.2

This ticket was mentioned in Slack in #core by costdev. View the logs.


13 months ago

This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.


13 months ago

#7 @mukesh27
13 months ago

  • Keywords needs-patch added

This ticket was discussed in the recent bug scrub.

@SergeyBiryukov Is this a to-do item for you, and will you submit a patch?

Props to @costdev

This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.


13 months ago

#9 @mukesh27
13 months ago

  • Milestone changed from 6.2 to Future Release

Thanks @SergeyBiryukov for the ticket.

This ticket was discussed during the bug scrub. As this ticket still needs patch and 6.2 Beta 1 is being released today, I'll move this to Future Release.

Additional props: @costdev

#10 @costdev
13 months ago

#57671 was marked as a duplicate.

Note: See TracTickets for help on using tickets.