Make WordPress Core

Ticket #6072: act-right-on-empty-slug.diff

File act-right-on-empty-slug.diff, 3.1 KB (added by nbachiyski, 17 years ago)
  • wp-admin/admin-ajax.php

     
    568568case 'sample-permalink':
    569569        check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
    570570        $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
    571         die(get_sample_permalink_html($post_id, $_POST['new_slug']));
     571        die(get_sample_permalink_html($post_id, $_POST['new_title'], $_POST['new_slug']));
    572572break;
    573573default :
    574574        do_action( 'wp_ajax_' . $_POST['action'] );
  • wp-admin/includes/post.php

     
    577577        }
    578578}
    579579
    580 function get_sample_permalink($id, $name = null) {
     580function get_sample_permalink($id, $title, $name = null) {
    581581        $post = &get_post($id);
    582582        if (!$post->ID) {
    583583                return array('', '');
     
    585585        $original_status = $post->post_status;
    586586        $original_date = $post->post_date;
    587587        $original_name = $post->post_name;
     588        $original_title = $post->post_title;
     589
     590        $post->post_title = $title;
     591        $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
     592
    588593        if (in_array($post->post_status, array('draft', 'pending'))) {
    589594                $post->post_status = 'publish';
    590595                $post->post_date = date('Y-m-d H:i:s');
    591                 $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
    592596        }
    593597        if (!is_null($name)) {
    594                 $post->post_name = sanitize_title($name, $post->ID);
     598                $post->post_name = sanitize_title($name? $name : $post->post_title, $post->ID);
    595599        }
    596600
    597601        $permalink = get_permalink($post, true);
     
    610614        $post->post_status = $original_status;
    611615        $post->post_date = $original_date;
    612616        $post->post_name = $original_name;
     617        $post->post_title = $original_title;
    613618        return $permalink;
    614619}
    615620
    616 function get_sample_permalink_html($id, $new_slug=null) {
     621function get_sample_permalink_html($id, $new_title=null, $new_slug=null) {
    617622        $post = &get_post($id);
    618         list($permalink, $post_name) = get_sample_permalink($post->ID, $new_slug);
     623        list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
    619624        if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
    620625                return '';
    621626        }
  • wp-admin/js/slug.js

     
    1010
    1111        b.html('<a href="" class="save">'+slugL10n.save+'</a> <a class="cancel" href="">'+slugL10n.cancel+'</a>');
    1212        b.children('.save').click(function() {
    13                 var new_slug = e.children('input').attr('value');
     13                var new_slug = e.children('input').val();
    1414                jQuery.post(slugL10n.requestFile, {
    1515                        action: 'sample-permalink',
    1616                        post_id: post_id,
    1717                        new_slug: new_slug,
     18                        new_title: jQuery('#title').val(),
    1819                        samplepermalinknonce: jQuery('#samplepermalinknonce').val()}, function(data) {
    1920                                jQuery('#edit-slug-box').html(data);
    2021                                b.html(revert_b);