diff --git a/wp-admin/admin-ajax.php b/wp-admin/admin-ajax.php
index 8644ae3aca..2e83c1cc20 100644
--- a/wp-admin/admin-ajax.php
+++ b/wp-admin/admin-ajax.php
@@ -573,7 +573,7 @@ break;
case 'sample-permalink':
check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
$post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
- die(get_sample_permalink_html($post_id, $_POST['new_slug']));
+ die(get_sample_permalink_html($post_id, $_POST['new_title'], $_POST['new_slug']));
break;
default :
do_action( 'wp_ajax_' . $_POST['action'] );
diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php
index 455bc5c3a2..c10511ab1a 100644
--- a/wp-admin/includes/post.php
+++ b/wp-admin/includes/post.php
@@ -577,7 +577,7 @@ function postbox_classes( $id, $page ) {
}
}
-function get_sample_permalink($id, $name = null) {
+function get_sample_permalink($id, $title, $name = null) {
$post = &get_post($id);
if (!$post->ID) {
return array('', '');
@@ -585,13 +585,17 @@ function get_sample_permalink($id, $name = null) {
$original_status = $post->post_status;
$original_date = $post->post_date;
$original_name = $post->post_name;
+ $original_title = $post->post_title;
+
+ $post->post_title = $title;
+ $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
+
if (in_array($post->post_status, array('draft', 'pending'))) {
$post->post_status = 'publish';
$post->post_date = date('Y-m-d H:i:s');
- $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
}
if (!is_null($name)) {
- $post->post_name = sanitize_title($name, $post->ID);
+ $post->post_name = sanitize_title($name? $name : $post->post_title, $post->ID);
}
$permalink = get_permalink($post, true);
@@ -610,12 +614,13 @@ function get_sample_permalink($id, $name = null) {
$post->post_status = $original_status;
$post->post_date = $original_date;
$post->post_name = $original_name;
+ $post->post_title = $original_title;
return $permalink;
}
-function get_sample_permalink_html($id, $new_slug=null) {
+function get_sample_permalink_html($id, $new_title=null, $new_slug=null) {
$post = &get_post($id);
- list($permalink, $post_name) = get_sample_permalink($post->ID, $new_slug);
+ list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
return '';
}
diff --git a/wp-admin/js/slug.js b/wp-admin/js/slug.js
index 7da617f9a0..f26a5f202e 100644
--- a/wp-admin/js/slug.js
+++ b/wp-admin/js/slug.js
@@ -10,11 +10,12 @@ function edit_permalink(post_id) {
b.html(''+slugL10n.save+' '+slugL10n.cancel+'');
b.children('.save').click(function() {
- var new_slug = e.children('input').attr('value');
+ var new_slug = e.children('input').val();
jQuery.post(slugL10n.requestFile, {
action: 'sample-permalink',
post_id: post_id,
new_slug: new_slug,
+ new_title: jQuery('#title').val(),
samplepermalinknonce: jQuery('#samplepermalinknonce').val()}, function(data) {
jQuery('#edit-slug-box').html(data);
b.html(revert_b);