Post slug fixes from nbachiyski. fixes #6072

git-svn-id: http://svn.automattic.com/wordpress/trunk@7162 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2008-03-05 22:09:28 +00:00
parent e6b01542a5
commit 1da923bdfd
3 changed files with 12 additions and 7 deletions

View File

@ -571,7 +571,9 @@ 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_title'], $_POST['new_slug']));
$title = isset($_POST['new_title'])? $_POST['new_title'] : '';
$slug = isset($_POST['new_slug'])? $_POST['new_slug'] : '';
die(get_sample_permalink_html($post_id, $title, $slug));
break;
default :
do_action( 'wp_ajax_' . $_POST['action'] );

View File

@ -581,7 +581,7 @@ function postbox_classes( $id, $page ) {
}
}
function get_sample_permalink($id, $title, $name = null) {
function get_sample_permalink($id, $title=null, $name = null) {
$post = &get_post($id);
if (!$post->ID) {
return array('', '');
@ -589,17 +589,19 @@ function get_sample_permalink($id, $title, $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);
// 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_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 the user wants to set a new name -- override the current one
// Note: if empty name is supplied -- use the title instead, see #6072
if (!is_null($name)) {
$post->post_name = sanitize_title($name? $name : $post->post_title, $post->ID);
$post->post_name = sanitize_title($name? $name : $title, $post->ID);
}
$permalink = get_permalink($post, true);

View File

@ -92,6 +92,7 @@ function autosave_update_slug(post_id) {
{
action: 'sample-permalink',
post_id: post_id,
new_title: jQuery('#title').val(),
samplepermalinknonce: jQuery('#samplepermalinknonce').val()
},
function(data) {