Make WordPress Core

Opened 4 weeks ago

Last modified 2 days ago

#44238 new enhancement

Add protected param to register meta

Reported by: spacedmonkey Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 3.1.3
Component: Options, Meta APIs Keywords: has-patch
Focuses: Cc:


It has been possible for developers to make meta keys protected / not protected since 3.2.0, when the is_protected_meta filter was added. By default all meta keys that start with an underscore as seen as protected, all those this overriden by the filter. There should be a way to a meta key as protected while using register_meta function. This would make the register meta function, a point of truth for all meta keys / meta type, where a state, type and access are defined in one place.

Attachments (3)

44238.diff (2.3 KB) - added by spacedmonkey 4 weeks ago.
44238.1.diff (2.1 KB) - added by spacedmonkey 4 weeks ago.
44238.2.diff (9.2 KB) - added by spacedmonkey 4 days ago.

Download all attachments as: .zip

Change History (8)

4 weeks ago

4 weeks ago

#1 @spacedmonkey
4 weeks ago

I have written two ways of the doing this.

The first patch, 44238.diff added a param of protected_callback which, if set is passed onto the new protected_{$meta_type}_meta_{$meta_key} filter. This is inline with other params on the register meta api, that allow developers to write there own logic. If they don't want to write there own logic there they can always use the helper functions __return_true and __return_false.

The second patch, 44238.1.diff is much more simple implementation, that added a boolean protected. This is much more defined if something is or is not conditional, but it much more restrictive. However, it makes the definition of a meta_key much cleaner if you look it up.

Not sure which is better, please comment below with feedback.

This ticket was mentioned in Slack in #core-multisite by spacedmonkey. View the logs.

3 weeks ago

4 days ago

This ticket was mentioned in Slack in #core-restapi by spacedmonkey. View the logs.

2 days ago

Note: See TracTickets for help on using tickets.