Slug edit fix from nbachiyski. fixes #6072
git-svn-id: http://svn.automattic.com/wordpress/trunk@7139 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
5504c11b58
commit
b1f0a853da
|
@ -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'] );
|
||||
|
|
|
@ -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 '';
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue