diff --git src/wp-includes/rewrite.php src/wp-includes/rewrite.php
index 984fbbe..d696325 100644
|
|
class WP_Rewrite { |
895 | 895 | * one is used. If none matches, then the default will be used, which is |
896 | 896 | * year, month, day. |
897 | 897 | * |
898 | | * Prevents post ID and date permalinks from overlapping. In the case of |
899 | | * post_id, the date permalink will be prepended with front permalink with |
900 | | * 'date/' before the actual permalink to form the complete date permalink |
901 | | * structure. |
| 898 | * Prevents post ID or slug and date permalinks from overlapping. In the case of |
| 899 | * post_id or a postname only structure, the date permalink will be prepended |
| 900 | * with front permalink and 'date/' before the actual permalink to form the |
| 901 | * complete date permalink structure. |
902 | 902 | * |
903 | 903 | * @since 1.5.0 |
904 | 904 | * @access public |
… |
… |
class WP_Rewrite { |
930 | 930 | if ( empty($date_endian) ) |
931 | 931 | $date_endian = '%year%/%monthnum%/%day%'; |
932 | 932 | |
933 | | // Do not allow the date tags and %post_id% to overlap in the permalink |
934 | | // structure. If they do, move the date tags to $front/date/. |
| 933 | /* |
| 934 | * Do not allow the date tags and %post_id% or %postname% to overlap in the |
| 935 | * permalink structure. If they do, move the date tags to $front/date/. |
| 936 | */ |
935 | 937 | $front = $this->front; |
936 | 938 | preg_match_all('/%.+?%/', $this->permalink_structure, $tokens); |
937 | 939 | $tok_index = 1; |
938 | 940 | foreach ( (array) $tokens[0] as $token) { |
939 | | if ( '%post_id%' == $token && ($tok_index <= 3) ) { |
| 941 | if ( in_array( $token, array( '%post_id%', '%postname%' ) ) && $tok_index <= 3 ) { |
940 | 942 | $front = $front . 'date/'; |
941 | 943 | break; |
942 | 944 | } |
diff --git tests/phpunit/tests/post.php tests/phpunit/tests/post.php
index ae549e0..2c294a2 100644
|
|
class Tests_Post extends WP_UnitTestCase { |
470 | 470 | } |
471 | 471 | |
472 | 472 | /** |
| 473 | * @ticket 5305 |
| 474 | */ |
| 475 | function test_permalink_with_date_collision() { |
| 476 | global $wp_rewrite; |
| 477 | $wp_rewrite->init(); |
| 478 | $wp_rewrite->set_permalink_structure( '/archive/%postname%/' ); |
| 479 | $wp_rewrite->flush_rules(); |
| 480 | |
| 481 | $id = $this->factory->post->create( array( |
| 482 | 'post_author' => $this->author_id, |
| 483 | 'post_status' => 'publish', |
| 484 | 'post_content' => rand_str(), |
| 485 | 'post_title' => '2015', |
| 486 | 'post_date' => '2015-02-01 01:00:00', |
| 487 | ) ); |
| 488 | |
| 489 | $this->assertEquals( $id, url_to_postid( get_permalink( $id ) ) ); |
| 490 | |
| 491 | $wp_rewrite->set_permalink_structure(''); |
| 492 | } |
| 493 | |
| 494 | /** |
473 | 495 | * @ticket 21013 |
474 | 496 | */ |
475 | 497 | function test_wp_unique_post_slug_with_non_latin_slugs() { |