From 102a8aecf814920a4cffb3304efef48821ca9ba5 Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sat, 5 Sep 2015 19:50:24 +0000 Subject: [PATCH] Allow `wp_insert_post()` to accept a `meta_input` argument. Devs should use `register_meta()` to ensure that specific values specified by key are sanitized properly. Adds unit test. Props CoenJacobs, swissspidy. Fixes #20451. Built from https://develop.svn.wordpress.org/trunk@33910 git-svn-id: http://core.svn.wordpress.org/trunk@33879 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post-functions.php | 7 +++++++ wp-includes/version.php | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/wp-includes/post-functions.php b/wp-includes/post-functions.php index fdd01eed0c..147c3a4c05 100644 --- a/wp-includes/post-functions.php +++ b/wp-includes/post-functions.php @@ -2775,6 +2775,7 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { * * @since 1.0.0 * @since 4.2.0 Support was added for encoding emoji in the post title, content, and excerpt. + * @since 4.4.0 A 'meta_input' array can now be passed to $postarr to add post meta data. * * @see sanitize_post() * @global wpdb $wpdb WordPress database abstraction object. @@ -3172,6 +3173,12 @@ function wp_insert_post( $postarr, $wp_error = false ) { } } + if ( ! empty( $postarr['meta_input'] ) ) { + foreach ( $postarr['meta_input'] as $field => $value ) { + update_post_meta( $post_ID, $field, $value ); + } + } + $current_guid = get_post_field( 'guid', $post_ID ); // Set GUID. diff --git a/wp-includes/version.php b/wp-includes/version.php index 7d1d25bcb3..0a0247ae69 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.4-alpha-33909'; +$wp_version = '4.4-alpha-33910'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.