Ticket #23222: new-permalink.diff

File new-permalink.diff, 2.4 KB (added by MikeHansenMe, 4 months ago)
Line 
1Index: wp-admin/includes/post.php
2===================================================================
3--- wp-admin/includes/post.php  (revision 23301)
4+++ wp-admin/includes/post.php  (working copy)
5@@ -981,6 +981,7 @@
6  * @return array With two entries of type string
7  */
8 function get_sample_permalink($id, $title = null, $name = null) {
9+       //wp_die( $id."|".$title."|".$name );
10        $post = get_post($id);
11        if ( !$post->ID )
12                return array('', '');
13@@ -995,14 +996,18 @@
14        // drafts, so we will fake, that our post is published
15        if ( in_array($post->post_status, array('draft', 'pending')) ) {
16                $post->post_status = 'publish';
17-               $post->post_name = sanitize_title($post->post_name ? $post->post_name : $post->post_title, $post->ID);
18+               $use_for_permalink = $post->post_name ? $post->post_name : $post->post_title;
19+               $use_for_permalink = str_replace( '%', '', $use_for_permalink );
20+               $post->post_name = sanitize_title( $use_for_permalink, $post->ID );
21        }
22 
23        // If the user wants to set a new name -- override the current one
24        // Note: if empty name is supplied -- use the title instead, see #6072
25-       if ( !is_null($name) )
26-               $post->post_name = sanitize_title($name ? $name : $title, $post->ID);
27-
28+       if ( !is_null($name) ) {
29+               $use_for_permalink = $name ? $name : $title;
30+               $use_for_permalink = str_replace( '%', '', $use_for_permalink );
31+               $post->post_name = sanitize_title( $use_for_permalink, $post->ID );
32+       }
33        $post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent);
34 
35        $post->filter = 'sample';
36Index: wp-includes/post.php
37===================================================================
38--- wp-includes/post.php        (revision 23301)
39+++ wp-includes/post.php        (working copy)
40@@ -2770,10 +2770,12 @@
41        // Create a valid post name. Drafts and pending posts are allowed to have an empty
42        // post name.
43        if ( empty($post_name) ) {
44-               if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) )
45-                       $post_name = sanitize_title($post_title);
46-               else
47+               if ( !in_array( $post_status, array( 'draft', 'pending', 'auto-draft' ) ) ) {
48+                       $post_name = str_replace( '%', '', $post_title );
49+                       $post_name = sanitize_title( $post_name );
50+               } else {
51                        $post_name = '';
52+               }
53        } else {
54                // On updates, we need to check to see if it's using the old, fixed sanitization context.
55                $check_name = sanitize_title( $post_name, '', 'old-save' );