From e0a0be9579bf00c673f6fa9c68e87d4546271b37 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Sat, 27 Aug 2016 17:25:29 +0000 Subject: [PATCH] Media: Add a `$wp_error` parameter to `wp_insert_attachment()` to give it parity with `wp_insert_post()`. Fixes #37813 Props grapplerulrich, mrahmadawais Built from https://develop.svn.wordpress.org/trunk@38408 git-svn-id: http://core.svn.wordpress.org/trunk@38349 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 16 +++++++++------- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 905a99a320..ced823c320 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -2866,7 +2866,7 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { * @type array $tax_input Array of taxonomy terms keyed by their taxonomy name. Default empty. * @type array $meta_input Array of post meta values keyed by their post meta key. Default empty. * } - * @param bool $wp_error Optional. Whether to allow return of WP_Error on failure. Default false. + * @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false. * @return int|WP_Error The post ID on success. The value 0 or WP_Error on failure. */ function wp_insert_post( $postarr, $wp_error = false ) { @@ -4694,15 +4694,17 @@ function is_local_attachment($url) { * setting the value for the 'comment_status' key. * * @since 2.0.0 + * @since 4.7.0 Added the `$wp_error` parameter to allow a WP_Error to be returned on failure. * * @see wp_insert_post() * - * @param string|array $args Arguments for inserting an attachment. - * @param string $file Optional. Filename. - * @param int $parent Optional. Parent post ID. - * @return int Attachment ID. + * @param string|array $args Arguments for inserting an attachment. + * @param string $file Optional. Filename. + * @param int $parent Optional. Parent post ID. + * @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false. + * @return int|WP_Error The attachment ID on success. The value 0 or WP_Error on failure. */ -function wp_insert_attachment( $args, $file = false, $parent = 0 ) { +function wp_insert_attachment( $args, $file = false, $parent = 0, $wp_error = false ) { $defaults = array( 'file' => $file, 'post_parent' => 0 @@ -4716,7 +4718,7 @@ function wp_insert_attachment( $args, $file = false, $parent = 0 ) { $data['post_type'] = 'attachment'; - return wp_insert_post( $data ); + return wp_insert_post( $data, $wp_error ); } /** diff --git a/wp-includes/version.php b/wp-includes/version.php index d4312587c5..c6b1b0db58 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38407'; +$wp_version = '4.7-alpha-38408'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.