Make WordPress Core

Opened 5 months ago

Closed 5 months ago

Last modified 5 months ago

#61939 closed defect (bug) (fixed)

Stop using 'yes' and 'no' for autoloading in favor of recommended boolean

Reported by: flixos90's profile flixos90 Owned by: flixos90's profile flixos90
Milestone: 6.7 Priority: normal
Severity: normal Version:
Component: Options, Meta APIs Keywords: has-patch has-unit-tests commit
Focuses: performance Cc:

Description

As of WordPress 6.6, add_option() and update_option() encourage using a boolean for the $autoload parameter rather than strings 'yes' and 'no'.

#61929 makes the same update to the more recently introduced option autoloading functions from WordPress 6.4.

While the old values remain supported for backward compatibility, it makes sense for core to no longer use strings for the $autoload parameter of the various function calls.

Note: Also related is #61103, however that ticket is focused on explicitly setting an autoload values where previously none was provided, which is a different purpose (and certainly a more complex one than this right here).

Change History (8)

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


5 months ago
#1

  • Keywords has-patch has-unit-tests added; needs-patch removed

This PR includes no functional changes. All it does change 'yes' to true and 'no' to false in the various function calls where an $autoload parameter is passed. The only places where 'yes' and 'no' continue to be used is in some PHPUnit tests that are more explicitly about these values (now for backward compatibility).

Trac ticket: https://core.trac.wordpress.org/ticket/61939

#2 follow-up: @joemcgill
5 months ago

Just noting that changing these values in the upgrade routine and the existing unit tests were an intentional omission when the values were updated in #61045.

I believe that my thinking at the time was that upgrade routines should remain compatible with the version of Core being upgraded by that routine in case something fails during upgrades, and the previous unit tests should stay unchanged to ensure that the changes we made to those APIs were still backwards compatible for folks using the long-established "yes"/"no" values.

In retrospect, I don't think the caution with upgrade routines is warranted since upgrades are being executed using the functions as defined in the version being upgraded to. For the PHPUnit tests, as long as we have other unit tests in place to ensure backwards compatibility for "yes"/"no" values, I see no reason not to update the rest of the unit tests here.

#3 in reply to: ↑ 2 @flixos90
5 months ago

Replying to joemcgill:

Just noting that changing these values in the upgrade routine and the existing unit tests were an intentional omission when the values were updated in #61045.

Thanks for raising that. Looking at that changeset [58105], it looks like some of the add_option() / update_option() calls were updated to use 'on'|'off', which doesn't look right. They should probably be updated here too to use the booleans. 'on'|'off' should only be used when dealing with the database values directly. I'll update the PR https://github.com/WordPress/wordpress-develop/pull/7251 to replace the relevant 'on'|'off' as well. Update: Never mind, it looks like those were already fixed in another subsequent changeset. :)

[...]

In retrospect, I don't think the caution with upgrade routines is warranted since upgrades are being executed using the functions as defined in the version being upgraded to.

Agreed. This is a good point, though the boolean values true|false have always been supported, so like you're saying this change is still compatible with those older versions.

For the PHPUnit tests, as long as we have other unit tests in place to ensure backwards compatibility for "yes"/"no" values, I see no reason not to update the rest of the unit tests here.

+1, that's what I was thinking and what I've done so far in https://github.com/WordPress/wordpress-develop/pull/7251.

Last edited 5 months ago by flixos90 (previous) (diff)

#4 @mukesh27
5 months ago

  • Keywords commit added

The PR got enough approval for merge. Mark for commit

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


5 months ago

#6 @flixos90
5 months ago

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

In 58945:

Options, Meta APIs: Stop using 'yes' and 'no' for autoload parameter in favor of recommended boolean.

This changeset does not modify any behavior, it only updates the code to use the recommended type for the $autoload parameter as of WordPress 6.6. The old values 'yes' and 'no' are only maintained in certain tests that are explicitly about these backward compatibility values.

Props flixos90, joemcgill, mukesh27.
Fixes #61939.
See #61103, #61929.

#8 @flixos90
5 months ago

In 58949:

Options, Meta APIs: Soft-deprecate use of 'yes' and 'no' as $autoload parameter.

WordPress 6.6 option autoload enhancements included discouraging the use of 'yes' and 'no' to indicate whether to autoload an option when calling add_option() or update_option(). Instead, a boolean should be used.

This changeset brings the newer autoload related functions wp_set_option_autoload_values(), wp_set_options_autoload(), and wp_set_option_autoload() in line with those changes. Additionally, it soft-deprecates the values more formally, as they should no longer be used. No PHP warnings will be emitted though as this is not a hard deprecation. This change is purely about documentation.

Props flixos90, joemcgill, jrf, mukesh27.
Fixes #61929.
See #61103, #61939.

Note: See TracTickets for help on using tickets.