Make WordPress Core

Opened 18 months ago

Closed 5 months ago

Last modified 5 months ago

#58134 closed defect (bug) (fixed)

Use correct plural of status

Reported by: presskopp's profile Presskopp Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 6.6 Priority: normal
Severity: normal Version:
Component: Posts, Post Types Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

Core uses a variable named $stati (10 times to be found, in 3 files), but that's not the correct plural form of 'status', neither in english, nor in latin or elsewhere. So I plead to change it to $statuses. While there seems to be no decent rule for variable names, so technically the variable could be named $stsii or whatever, still we are called to not

"abbreviate variable names unnecessarily; let the code be unambiguous and self-documenting."

see https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/

Also, as we all know, "Code is Poetry", isn't it? Now you could argue poetry has some freedoms, but I strongly believe it should use correct grammar, at least in this case.

So I may have convinced you finally of that one, but there's one more issue:

There's also a function

get_post_stati()

see https://developer.wordpress.org/reference/functions/get_post_stati/

c'mon, let's rename it to get_post_statuses, while we're on it.

You may think this is petty, but it gave me some confusion and after all it's just wrong. Let's get rid of an usage of a plural form which doesn't exist.

Change History (13)

#1 @sabernhardt
18 months ago

  • Component changed from Text Changes to General

#2 @sabernhardt
18 months ago

Searching _stati also found $post_stati and a global $avail_post_stati variable (with $avail_post_stati_backup in the related unit test).

#3 @sabernhardt
18 months ago

  • Keywords needs-patch added

I think it's worth replacing the $stati and $post_stati variables, but I'm not sure about the function or the global variable.

Outside core, directory searches found the get_post_stati() function in 534 plugins and the Storefront theme.

If the function gets a new name (alias), get_post_status_list() might be appropriate.

#4 in reply to: ↑ description ; follow-up: @SergeyBiryukov
14 months ago

Replying to Presskopp:

There's also a function

get_post_stati()

see https://developer.wordpress.org/reference/functions/get_post_stati/

c'mon, let's rename it to get_post_statuses, while we're on it.

Just noting that get_post_statuses() already exists for a slightly different purpose, so get_post_status_list() as suggested above might be another option.

#5 @SergeyBiryukov
14 months ago

  • Component changed from General to Posts, Post Types

#6 in reply to: ↑ 4 @SergeyBiryukov
14 months ago

Replying to SergeyBiryukov:

Just noting that get_post_statuses() already exists for a slightly different purpose, so get_post_status_list() as suggested above might be another option.

There is also get_available_post_statuses() for another slightly different purpose.

#7 @Presskopp
14 months ago

For clarity let me sum it up:

The following are existing functions:

get_available_post_statuses() ("Returns all the possible statuses for a post type.")

get_post_statuses() ("Retrieves all of the WordPress supported post statuses.")

get_post_stati() ("Gets a list of post statuses.")

That makes it impossible to rename get_post_stati() to get_post_statuses(), so get_post_status_list() could be helpful here.

#8 @manfcarlo
14 months ago

Why would it be impossible? What about preserving the existing behaviour of get_post_statuses when no arguments are provided, but enhancing it with the same parameters of get_post_stati and then turning get_post_stati into a wrapper function? Noting that the output of get_post_stati when no arguments are provided is not the same as the output of get_post_statuses, the default arguments could be slightly tweaked for get_post_statuses to preserve the old output (e.g. the default value of $args could specify only built-in statuses.) Would that work?

This ticket was mentioned in PR #6532 on WordPress/wordpress-develop by @sabernhardt.


5 months ago
#9

  • Keywords has-patch has-unit-tests added; needs-patch removed
  • Replaces $stati with $statuses
  • Replaces $post_stati with $post_statuses

Trac 58134

#10 @sabernhardt
5 months ago

#59080 suggested changing the get_post_stati function name, and that was closed as wontfix.

I just made a patch to change the two variable names that have less impact.

#11 @SergeyBiryukov
5 months ago

  • Owner set to SergeyBiryukov
  • Resolution set to fixed
  • Status changed from new to closed

In 58129:

Posts, Post Types: Use a consistent plural form of “status” in variable names.

Follow-up to [5575], [6796], [6993], [7638], [12162], [12719], [15578], [16652], [31046], [34515], [49472].

Props Presskopp, sabernhardt, manfcarlo, SergeyBiryukov.
Fixes #58134.

#12 @SergeyBiryukov
5 months ago

  • Milestone changed from Awaiting Review to 6.6

@SergeyBiryukov commented on PR #6532:


5 months ago
#13

Thanks for the PR! Merged in r58129.

Note: See TracTickets for help on using tickets.