mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-04-04 04:34:31 +00:00
Disallow post slugs that will result in permalinks that conflict with date archive URLs.
On certain permalink structures, a numeric post slug will result in a post permalink that conflicts with a date archive URL. For example, with permastruct `/%year%/%monthnum%/%postname%/`, a post published in May 2015 with slug `'15'` will result in a URL (`/2015/05/15/`) that conflicts with the archive for May 15, 2015. To avoid this problem, `wp_unique_post_slug()` rejects a requested slug when it would generate a conflict of this type. Thus, in our example, `'15'` would become `'15-2'`. Props valendesigns, boonebgorges, Denis-de-Bernardy, loushou. See #5305. git-svn-id: https://develop.svn.wordpress.org/trunk@32647 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -313,4 +313,168 @@ class Tests_Admin_includesPost extends WP_UnitTestCase {
|
||||
$wp_rewrite->set_permalink_structure( $old_permalink_structure );
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 5305
|
||||
*/
|
||||
public function test_get_sample_permalink_should_avoid_slugs_that_would_create_clashes_with_year_archives() {
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite->init();
|
||||
$wp_rewrite->set_permalink_structure( '/%postname%/' );
|
||||
$wp_rewrite->flush_rules();
|
||||
|
||||
$p = $this->factory->post->create( array(
|
||||
'post_name' => '2015',
|
||||
) );
|
||||
|
||||
$found = get_sample_permalink( $p );
|
||||
$this->assertEquals( '2015-2', $found[1] );
|
||||
|
||||
$wp_rewrite->set_permalink_structure( '' );
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 5305
|
||||
*/
|
||||
public function test_get_sample_permalink_should_allow_yearlike_slugs_if_permastruct_does_not_cause_an_archive_conflict() {
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite->init();
|
||||
$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
|
||||
$wp_rewrite->flush_rules();
|
||||
|
||||
$p = $this->factory->post->create( array(
|
||||
'post_name' => '2015',
|
||||
) );
|
||||
|
||||
$found = get_sample_permalink( $p );
|
||||
$this->assertEquals( '2015', $found[1] );
|
||||
|
||||
$wp_rewrite->set_permalink_structure( '' );
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 5305
|
||||
*/
|
||||
public function test_get_sample_permalink_should_avoid_slugs_that_would_create_clashes_with_month_archives() {
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite->init();
|
||||
$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
|
||||
$wp_rewrite->flush_rules();
|
||||
|
||||
$p = $this->factory->post->create( array(
|
||||
'post_name' => '11',
|
||||
) );
|
||||
|
||||
$found = get_sample_permalink( $p );
|
||||
$this->assertEquals( '11-2', $found[1] );
|
||||
|
||||
$wp_rewrite->set_permalink_structure( '' );
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 5305
|
||||
*/
|
||||
public function test_get_sample_permalink_should_ignore_potential_month_conflicts_for_invalid_monthnum() {
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite->init();
|
||||
$wp_rewrite->set_permalink_structure( '/%year%/%postname%/' );
|
||||
$wp_rewrite->flush_rules();
|
||||
|
||||
$p = $this->factory->post->create( array(
|
||||
'post_name' => '13',
|
||||
) );
|
||||
|
||||
$found = get_sample_permalink( $p );
|
||||
$this->assertEquals( '13', $found[1] );
|
||||
|
||||
$wp_rewrite->set_permalink_structure( '' );
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 5305
|
||||
*/
|
||||
public function test_get_sample_permalink_should_avoid_slugs_that_would_create_clashes_with_day_archives() {
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite->init();
|
||||
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
|
||||
$wp_rewrite->flush_rules();
|
||||
|
||||
$p = $this->factory->post->create( array(
|
||||
'post_name' => '30',
|
||||
) );
|
||||
|
||||
$found = get_sample_permalink( $p );
|
||||
$this->assertEquals( '30-2', $found[1] );
|
||||
|
||||
$wp_rewrite->set_permalink_structure( '' );
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 5305
|
||||
*/
|
||||
public function test_get_sample_permalink_should_iterate_slug_suffix_when_a_date_conflict_is_found() {
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite->init();
|
||||
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
|
||||
$wp_rewrite->flush_rules();
|
||||
|
||||
$this->factory->post->create( array(
|
||||
'post_name' => '30-2',
|
||||
) );
|
||||
|
||||
$p = $this->factory->post->create( array(
|
||||
'post_name' => '30',
|
||||
) );
|
||||
|
||||
$found = get_sample_permalink( $p );
|
||||
$this->assertEquals( '30-3', $found[1] );
|
||||
|
||||
$wp_rewrite->set_permalink_structure( '' );
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 5305
|
||||
*/
|
||||
public function test_get_sample_permalink_should_ignore_potential_day_conflicts_for_invalid_day() {
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite->init();
|
||||
$wp_rewrite->set_permalink_structure( '/%year%/%monthnum%/%postname%/' );
|
||||
$wp_rewrite->flush_rules();
|
||||
|
||||
$p = $this->factory->post->create( array(
|
||||
'post_name' => '32',
|
||||
) );
|
||||
|
||||
$found = get_sample_permalink( $p );
|
||||
$this->assertEquals( '32', $found[1] );
|
||||
|
||||
$wp_rewrite->set_permalink_structure( '' );
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 5305
|
||||
*/
|
||||
public function test_get_sample_permalink_should_allow_daylike_slugs_if_permastruct_does_not_cause_an_archive_conflict() {
|
||||
global $wp_rewrite;
|
||||
$wp_rewrite->init();
|
||||
$wp_rewrite->set_permalink_structure( '/%year%/%month%/%day%/%postname%/' );
|
||||
$wp_rewrite->flush_rules();
|
||||
|
||||
$p = $this->factory->post->create( array(
|
||||
'post_name' => '30',
|
||||
) );
|
||||
|
||||
$found = get_sample_permalink( $p );
|
||||
$this->assertEquals( '30', $found[1] );
|
||||
|
||||
$wp_rewrite->set_permalink_structure( '' );
|
||||
flush_rewrite_rules();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user