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

File act-right-on-empty-slug.diff, 3.1 KB (added by nbachiyski, 5 years ago)
Line 
1Index: wp-admin/admin-ajax.php
2===================================================================
3--- wp-admin/admin-ajax.php     (revision 7135)
4+++ wp-admin/admin-ajax.php     (working copy)
5@@ -568,7 +568,7 @@
6 case 'sample-permalink':
7        check_ajax_referer( 'samplepermalink', 'samplepermalinknonce' );
8        $post_id = isset($_POST['post_id'])? intval($_POST['post_id']) : 0;
9-       die(get_sample_permalink_html($post_id, $_POST['new_slug']));
10+       die(get_sample_permalink_html($post_id, $_POST['new_title'], $_POST['new_slug']));
11 break;
12 default :
13        do_action( 'wp_ajax_' . $_POST['action'] );
14Index: wp-admin/includes/post.php
15===================================================================
16--- wp-admin/includes/post.php  (revision 7135)
17+++ wp-admin/includes/post.php  (working copy)
18@@ -577,7 +577,7 @@
19        }
20 }
21 
22-function get_sample_permalink($id, $name = null) {
23+function get_sample_permalink($id, $title, $name = null) {
24        $post = &get_post($id);
25        if (!$post->ID) {
26                return array('', '');
27@@ -585,13 +585,17 @@
28        $original_status = $post->post_status;
29        $original_date = $post->post_date;
30        $original_name = $post->post_name;
31+       $original_title = $post->post_title;
32+
33+       $post->post_title = $title;
34+       $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
35+
36        if (in_array($post->post_status, array('draft', 'pending'))) {
37                $post->post_status = 'publish';
38                $post->post_date = date('Y-m-d H:i:s');
39-               $post->post_name = sanitize_title($post->post_name? $post->post_name : $post->post_title, $post->ID);
40        }
41        if (!is_null($name)) {
42-               $post->post_name = sanitize_title($name, $post->ID);
43+               $post->post_name = sanitize_title($name? $name : $post->post_title, $post->ID);
44        }
45 
46        $permalink = get_permalink($post, true);
47@@ -610,12 +614,13 @@
48        $post->post_status = $original_status;
49        $post->post_date = $original_date;
50        $post->post_name = $original_name;
51+       $post->post_title = $original_title;
52        return $permalink;
53 }
54 
55-function get_sample_permalink_html($id, $new_slug=null) {
56+function get_sample_permalink_html($id, $new_title=null, $new_slug=null) {
57        $post = &get_post($id);
58-       list($permalink, $post_name) = get_sample_permalink($post->ID, $new_slug);
59+       list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
60        if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
61                return '';
62        }
63Index: wp-admin/js/slug.js
64===================================================================
65--- wp-admin/js/slug.js (revision 7135)
66+++ wp-admin/js/slug.js (working copy)
67@@ -10,11 +10,12 @@
68 
69        b.html('<a href="" class="save">'+slugL10n.save+'</a> <a class="cancel" href="">'+slugL10n.cancel+'</a>');
70        b.children('.save').click(function() {
71-               var new_slug = e.children('input').attr('value');
72+               var new_slug = e.children('input').val();
73                jQuery.post(slugL10n.requestFile, {
74                        action: 'sample-permalink',
75                        post_id: post_id,
76                        new_slug: new_slug,
77+                       new_title: jQuery('#title').val(),
78                        samplepermalinknonce: jQuery('#samplepermalinknonce').val()}, function(data) {
79                                jQuery('#edit-slug-box').html(data);
80                                b.html(revert_b);