#50434 closed defect (bug) (fixed)
Replace the `$new_whitelist_options` variable with a more inclusive name
Reported by: | desrosj | Owned by: | desrosj |
---|---|---|---|
Milestone: | 5.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | General | Keywords: | has-patch commit has-dev-note |
Focuses: | Cc: |
Description
Branching this off of #50413.
The global variable $new_whitelist_options
should be replaced with a more inclusive name. Because this is a global that a handful of plugins reference directly, care should be taken when renaming it.
I propose renaming the current variable (something like $new_allowed_options
), but maintaining the current variable for a period of time (maybe two releases?), and triggering a _doing_it_wrong()
notice.
Attachments (2)
Change History (14)
#2
@
4 years ago
I suppose the least disruptive approach would to $new_whitelist_options = &$new_allowed_options
, and submit tickets in relevant plugins to update the variable. This should add almost zero impact in terms of performance/memory usage because the $new_whitelist_options
shim is just a reference to the new variable name.
Another way would be to convert $new_allowed_options
to an ArrayAccess
implementation, and emit a deprecation notice every time an array key is accessed. This would require us to declare a new class and populate it, which can be take more resources for a feature that we eventually need to phrase out.
#3
@
4 years ago
- Keywords has-patch added; needs-patch removed
Submitting a patch that replaces the variable with $new_allowlist_options
, and creates a reference of it at $new_whitelist_options
. Unless a plugin goes out of its way to destroy the variable (which will only destroy the reference with the patch), this should seamlessly rename the variable.
This is the first approach I mentioned in comment 2.
@
4 years ago
Please ignore the previous patch. It had a missing @since
annotation that is fixed in this file.
This ticket was mentioned in PR #397 on WordPress/wordpress-develop by desrosj.
4 years ago
#4
Deprecate the old $new_whitelist_options
variable in favor of $new_allowed_options
and pass by reference.
Trac ticket: https://core.trac.wordpress.org/ticket/50434
#5
@
4 years ago
I was having issues with 50434.2.patch applying cleanly so I recreated the changes in a PR on GitHub attached to the ticket above.
I removed the inline @deprecated
documentation tag where the variable was passed by reference. I could not find any other instances in Core where something had a @deprecated
tag inline, except action and filter hooks.
Based on an initial scan of the plugin directory, it does not seem like this change should be too problematic. A lot of the instances being flagged on that search are caused by the plugin bundling the WPCS sniffs, which includes checks for the variable.
@ayeshrajans I did have one question on the patch. What is the need to pass the new variable by reference in unregister_setting()
? Is this to ensure that if a a plugin or theme manually erases and repopulates the global the setting is correctly unregistered?
#6
@
4 years ago
I wonder if we might want to introduce a _deprecated_global
function to properly warn folks. I also think it would fantastic if we could remove the global all together rather than rename it.
#7
follow-up:
↓ 8
@
4 years ago
@jorbin is there any prior history to look to where a global has been deprecated and removed in Core?
Where I dropped the ball and forgot to circle back to this before beta 1, I think a more conservative approach like the one in the current patch would be best for 5.5, and maybe we could outline the plan to add _deprecated_global()
and officially deprecate $new_whitelist_options
in 5.6?
#8
in reply to:
↑ 7
@
4 years ago
Replying to desrosj:
I think a more conservative approach like the one in the current patch would be best for 5.5, and maybe we could outline the plan to add
_deprecated_global()
and officially deprecate$new_whitelist_options
in 5.6?
Makes sense to me.
Noticed a couple of typos in the PR:
$new_whiltelist_options
(extra "l") in the@since
note.- The inline comments should start with
/*
, not/**
(the latter is for proper DocBlocks).
Looks good otherwise.
#10
@
4 years ago
- Owner set to desrosj
- Resolution set to fixed
- Status changed from new to closed
In 48477:
4 years ago
#11
This was merged into WordPress Core in https://core.trac.wordpress.org/changeset/48477.
In 48121: