From 5ee1a961a40b7f1a98d4526a0699bea1f19475a8 Mon Sep 17 00:00:00 2001 From: Mark Jaquith Date: Wed, 8 May 2013 21:26:17 +0000 Subject: [PATCH] Ensure that draft posts cannot be given a non-unique post slug when using Quick Edit. fixes #22902. props SergeyBiryukov. git-svn-id: http://core.svn.wordpress.org/trunk@24206 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/ajax-actions.php | 6 ++++++ wp-admin/includes/post.php | 5 ++--- 2 files changed, 8 insertions(+), 3 deletions(-) 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); }