Make WordPress Core

Opened 3 years 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: Posts, Post Types Keywords: has-patch
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 (0)

Note: See TracTickets for help on using tickets.