Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#31225 closed defect (bug) (worksforme)

wp.newPost doesn't save custom fields starting with an underscore

Reported by: pcfreak30's profile pcfreak30 Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.1
Component: XML-RPC Keywords:
Focuses: Cc:

Description

Based on testing it seems the API does not like saving or possibly (untested) editing posts and having a custom field starting with an underscore.

This is required for when editing plugin postmeta data that saves with an underscore.

Change History (5)

#1 @redsweater
9 years ago

Hi pcfreak30 - This is not an issue with the API per se but reflects the underlying, built-in protection mechanism for metadata fields in WordPress. By default, any meta field with an underscore prefix is considered "protected" unless otherwise configured as unprotected.

So for example, a plugin that relies upon underscore-prefixed custom fields for its data should register a metadata callback with register_meta() or else e.g. install a filter on the is_protected_meta filter to enable editing of the specified field.

Daniel

Last edited 9 years ago by redsweater (previous) (diff)

#2 @pcfreak30
9 years ago

I get that, but I still think there should be an api option to disable that on a per-request basis. Some plugins use a _ and I may need to update them even if they don't expose a public way to do so. For those that know what we are doing this should be optional/overridable.

#3 @redsweater
9 years ago

It seems like that would defeat the purpose of the metadata being "protected." But I'm sure a more experienced WordPress developer will be able to chime in on this!

This ticket was mentioned in Slack in #core by drew. View the logs.


9 years ago

#5 @markoheijnen
9 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

redsweater is correct here. It's up to a plugin to know what to use where. and if you want to make it overridable then [register_meta()?] would be the way to go. No need for WordPress to do something here.

Note: See TracTickets for help on using tickets.