Make WordPress Core

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

File really-act-right-on-empty-slug.diff, 2.5 KB (added by nbachiyski, 17 years ago)
  • wp-includes/js/autosave.js

     
    9292                        {
    9393                                action: 'sample-permalink',
    9494                                post_id: post_id,
     95                                new_title: jQuery('#title').val(),
    9596                                samplepermalinknonce: jQuery('#samplepermalinknonce').val()
    9697                        },
    9798                        function(data) {
  • wp-admin/admin-ajax.php

     
    571571case 'sample-permalink':
    572572        check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
    573573        $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
    574         die(get_sample_permalink_html($post_id, $_POST['new_title'], $_POST['new_slug']));
     574        $title = isset($_POST['new_title'])? $_POST['new_title'] : '';
     575        $slug = isset($_POST['new_slug'])? $_POST['new_slug'] : '';
     576        die(get_sample_permalink_html($post_id, $title, $slug));
    575577break;
    576578default :
    577579        do_action( 'wp_ajax_' . $_POST['action'] );
  • wp-admin/includes/post.php

     
    581581        }
    582582}
    583583
    584 function get_sample_permalink($id, $title, $name = null) {
     584function get_sample_permalink($id, $title=null, $name = null) {
    585585        $post = &get_post($id);
    586586        if (!$post->ID) {
    587587                return array('', '');
     
    589589        $original_status = $post->post_status;
    590590        $original_date = $post->post_date;
    591591        $original_name = $post->post_name;
    592         $original_title = $post->post_title;
    593592
    594         $post->post_title = $title;
    595         $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
    596 
     593        // Hack: get_permalink would return ugly permalink for
     594        // drafts, so we will fake, that our post is published
    597595        if (in_array($post->post_status, array('draft', 'pending'))) {
    598596                $post->post_status = 'publish';
    599597                $post->post_date = date('Y-m-d H:i:s');
     598                $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
    600599        }
     600
     601        // If the user wants to set a new name -- override the current one
     602        // Note: if empty name is supplied -- use the title instead, see #6072
    601603        if (!is_null($name)) {
    602                 $post->post_name = sanitize_title($name? $name : $post->post_title, $post->ID);
     604                $post->post_name = sanitize_title($name? $name : $title, $post->ID);
    603605        }
    604606
    605607        $permalink = get_permalink($post, true);