Slug edit fix from nbachiyski. fixes #6072

git-svn-id: https://develop.svn.wordpress.org/trunk@7139 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2008-03-03 21:02:53 +00:00
parent b093ce1da2
commit 4e4e172045
3 changed files with 13 additions and 7 deletions

View File

@ -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'] );

View File

@ -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 '';
}

View File

@ -10,11 +10,12 @@ function edit_permalink(post_id) {
b.html('<a href="" class="save">'+slugL10n.save+'</a> <a class="cancel" href="">'+slugL10n.cancel+'</a>');
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);