WordPress.org

Make WordPress Core

Changeset 33261


Ignore:
Timestamp:
07/14/2015 12:27:03 PM (5 years ago)
Author:
boonebgorges
Message:

When creating a new post with an empty post_name and post_title, don't generate a post_name that conflicts with a date archive permalink.

See #5305.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r33234 r33261  
    34523452
    34533453    if ( empty( $data['post_name'] ) && ! in_array( $data['post_status'], array( 'draft', 'pending', 'auto-draft' ) ) ) {
    3454         $data['post_name'] = sanitize_title( $data['post_title'], $post_ID );
     3454        $data['post_name'] = wp_unique_post_slug( sanitize_title( $data['post_title'], $post_ID ), $post_ID, $data['post_status'], $post_type, $post_parent );
    34553455        $wpdb->update( $wpdb->posts, array( 'post_name' => $data['post_name'] ), $where );
    34563456    }
  • trunk/tests/phpunit/tests/post.php

    r33096 r33261  
    413413
    414414    /**
     415     * @ticket 5305
     416     */
     417    public function test_wp_insert_post_should_not_allow_a_bare_numeric_slug_that_might_conflict_with_a_date_archive_when_generating_from_an_empty_post_title() {
     418        global $wp_rewrite;
     419        $wp_rewrite->init();
     420        $wp_rewrite->set_permalink_structure( '/%postname%/' );
     421        $wp_rewrite->flush_rules();
     422
     423        $p = wp_insert_post( array(
     424            'post_title' => '',
     425            'post_content' => 'test',
     426            'post_status' => 'publish',
     427            'post_type' => 'post',
     428        ) );
     429
     430        $post = get_post( $p );
     431
     432        $wp_rewrite->set_permalink_structure( '' );
     433
     434        $this->assertEquals( "$p-2", $post->post_name );
     435    }
     436
     437    /**
    415438     * @ticket 5364
    416439     */
Note: See TracChangeset for help on using the changeset viewer.