diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index da00187128..b8ccf4a4a8 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -1352,6 +1352,12 @@ function wp_ajax_inline_save() { if ( empty($data['ping_status']) ) $data['ping_status'] = 'closed'; + // Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published. + if ( ! empty( $data['post_name'] ) && in_array( $post['post_status'], array( 'draft', 'pending' ) ) ) { + $post['post_status'] = 'publish'; + $data['post_name'] = wp_unique_post_slug( $data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent'] ); + } + // update the post edit_post(); diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 40e9fa57f4..aec34d982f 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -995,9 +995,8 @@ function get_sample_permalink($id, $title = null, $name = null) { $original_date = $post->post_date; $original_name = $post->post_name; - // Hack: get_permalink would return ugly permalink for - // drafts, so we will fake, that our post is published - if ( in_array($post->post_status, array('draft', 'pending')) ) { + // Hack: get_permalink() would return ugly permalink for drafts, so we will fake that our post is published. + if ( in_array( $post->post_status, array( 'draft', 'pending' ) ) ) { $post->post_status = 'publish'; $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID); }