WordPress.org

Make WordPress Core

Ticket #20419: 20419.5.diff

File 20419.5.diff, 2.4 KB (added by boonebgorges, 4 years ago)
  • src/wp-admin/includes/post.php

    diff --git src/wp-admin/includes/post.php src/wp-admin/includes/post.php
    index e7c2af1..b222847 100644
    function get_sample_permalink($id, $title = null, $name = null) { 
    12231223
    12241224        // If the user wants to set a new name -- override the current one
    12251225        // Note: if empty name is supplied -- use the title instead, see #6072
    1226         if ( !is_null($name) )
    1227                 $post->post_name = sanitize_title($name ? $name : $title, $post->ID);
     1226        if ( ! is_null( $name ) ) {
     1227                $post->post_name = sanitize_title( $name ? $name : $title, $post->ID );
     1228
     1229        // Otherwise, use our default behavior.
     1230        } elseif ( empty( $post->post_name ) ) {
     1231                $post->post_name = sanitize_title( $post->post_title, $post->ID );
     1232        }
     1233
     1234        $post->filter = 'sample';
    12281235
    12291236        $post->post_name = wp_unique_post_slug( $post->post_name, (object) array(
    12301237                'ID' => $post->ID,
    function get_sample_permalink($id, $title = null, $name = null) { 
    12331240                'post_parent' => $post->post_parent,
    12341241        ) );
    12351242
    1236         $post->filter = 'sample';
    1237 
    12381243        $permalink = get_permalink($post, true);
    12391244
    12401245        // Replace custom post_type Token with generic pagename token for ease of use.
  • src/wp-includes/post.php

    diff --git src/wp-includes/post.php src/wp-includes/post.php
    index 93e973b..985d9f7 100644
    function wp_unique_post_slug( $slug, $post, $deprecated_post_status = null, $dep 
    37413741                $post->post_parent = $deprecated_post_parent;
    37423742        }
    37433743
    3744         if ( in_array( $post->post_status, array( 'draft', 'pending', 'auto-draft' ) ) || ( 'inherit' == $post->post_status && 'revision' == $post->post_type ) ) {
     3744        // There's a few circumstances where we don't want to check for uniqueness: auto-saves and revisions.
     3745        if ( 'auto-draft' === $post->post_status || ( 'inherit' == $post->post_status && 'revision' == $post->post_type ) ) {
    37453746                return $slug;
    37463747        }
    37473748
  • tests/phpunit/tests/post/wpUniquePostSlug.php

    diff --git tests/phpunit/tests/post/wpUniquePostSlug.php tests/phpunit/tests/post/wpUniquePostSlug.php
    index 88dfdcd..51d27f0 100644
    class Tests_Post_WpUniquePostSlug extends WP_UnitTestCase { 
    153153
    154154        public function whitelist_post_statuses() {
    155155                return array(
    156                         array( 'draft' ),
    157                         array( 'pending' ),
     156                //      array( 'draft' ),
     157                //      array( 'pending' ),
    158158                        array( 'auto-draft' ),
    159159                );
    160160        }