Make WordPress Core

Opened 3 weeks ago

Last modified 7 days ago

#43941 new enhancement

Add default value to register meta

Reported by: spacedmonkey Owned by:
Milestone: 5.0 Priority: normal
Severity: normal Version: 4.6
Component: Options, Meta APIs Keywords: has-patch needs-unit-tests
Focuses: rest-api Cc:


Add a default value field to register meta. Meaning that if a metat value isn't set that is returns a default value. This bring the meta register api inline with register_setting, that already has a default value set.

Attachments (1)

meta_default.diff (1.8 KB) - added by spacedmonkey 3 weeks ago.

Download all attachments as: .zip

Change History (2)

#1 @flixos90
7 days ago

  • Focuses rest-api added
  • Keywords needs-unit-tests added; needs-testing dev-feedback removed
  • Milestone changed from Awaiting Review to 5.0

This should be tackled after #38323.

@spacedmonkey For the approach, I suggest we follow how option defaults are handled. Based on the work in the above ticket, we can introduce filters like default_{$object_type}_meta_{$meta_key} and default_{$object_type}_meta_{$meta_key}_for_{$object_subtype}. In register_meta(), when a default is passed, we can hook in a new filter function similar to filter_default_option(), that would take care of what you did in get_metadata_default() in meta_default.diff.

Note: See TracTickets for help on using tickets.