From 8930d00db07a8930eb2ca58f3209491718409aca Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Thu, 6 Nov 2014 08:15:30 +0000 Subject: [PATCH] Make sure the $parent argument of wp_insert_attachment() still works as expected after [28579]. Merges [29745] to the 4.0 branch. props jesin, dikiy_forester. fixes #29646. Built from https://develop.svn.wordpress.org/branches/4.0@30258 git-svn-id: http://core.svn.wordpress.org/branches/4.0@30258 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/post.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index d9d48a56fe..94ec8f2c50 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -4719,10 +4719,15 @@ function is_local_attachment($url) { function wp_insert_attachment( $args, $file = false, $parent = 0 ) { $defaults = array( 'file' => $file, - 'post_parent' => $parent + 'post_parent' => 0 ); + $data = wp_parse_args( $args, $defaults ); + if ( ! empty( $parent ) ) { + $data['post_parent'] = $parent; + } + $data['post_type'] = 'attachment'; return wp_insert_post( $data );