Make WordPress Core

Opened 5 years ago

Last modified 4 months ago

#53425 new enhancement

Allow meta_input to be updated through user input

Reported by: freepius's profile freepius Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 5.8
Component: Editor Keywords: has-patch reporter-feedback
Focuses: Cc:

Description

Hi everyone!
This is my first ticket on WordPress trac!

Since 2 years and this changeset [44295], it's not possible anymore to insert/update metadata through user input using meta_input entry.

Indeed _wp_get_allowed_postdata() remove the meta_input entry from $_POST. Therefore the wp_update_post() function, then the wp_insert_post() one receive data without meta_input.

I check the code a lot, and there is no hooks to re-inject properly the meta_input entry. (all the hooks come too late, after post inserting/updating).

I will finally get to my goal, but in an ugly and heavy way.

I propose to introduce a new hook to filter the not allowed post data fields, changing _wp_get_allowed_postdata() function like that (line 224):

/**
 * Filters the not allowed fields before to remove them from post data.
 *
 * By default, meta_input, file and guid are not allowed in post data.
 *
 * @param array $not_allowed  Default not allowed post data fields.
 * @param array $post_data    Array of post data.
 *
 * @return array Not allowed post data fields.
 */
$not_allowed = (array) apply_filters( 'not_allowed_postdata', array( 'meta_input', 'file', 'guid' ), $post_data );

return array_diff_key( $post_data, array_flip( $not_allowed ) );

Thanks.
Have a nice day :-)

Change History (1)

#1 @SirLouen
4 months ago

  • Component changed from Posts, Post Types to Editor
  • Keywords reporter-feedback added

Hey @freepius it seems that this never moved forward

In [44047] it was first stated that meta_input was never intended to be updated through user input. But it seems that you think that it should

I cannot get enough context of why this decision was taken because I can't see any tickets associated.

Maybe, you have found a specific scenario that you can better explain and maybe meta_input should be removed from that array all around instead of creating such ad-hoc filter

Can you comment or provide more information to get more insight about your requirements?

Note: See TracTickets for help on using tickets.