Skip to content

Commit 4bc596c

Browse files
author
gitlost
committed
Add _wp_old_slug on normalizing slugs.
1 parent 5f73551 commit 4bc596c

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

assets/banner-772x250.png

0 Bytes
Loading

includes/class-unfc-normalize.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2216,6 +2216,20 @@ function db_check_normalize_slugs( $checkeds, &$admin_notices ) {
22162216
$admin_notices[] = array( 'error', $this->db_check_error_msg( UNFC_DB_CHECK_DB_ERROR ) );
22172217
return false;
22182218
}
2219+
if ( 'post' === $type ) {
2220+
// Create '_wp_old_slug'.
2221+
$post = get_post( $id );
2222+
if ( $post instanceof WP_Post ) {
2223+
$post_before = clone $post;
2224+
// Allow for post being cached.
2225+
if ( $post->post_name === $obj->post_name ) { // Stale.
2226+
$post->post_name = $data[ 'post_name' ];
2227+
} else {
2228+
$post_before->post_name = $obj->post_name;
2229+
}
2230+
wp_check_for_changed_slugs( $id, $post, $post_before );
2231+
}
2232+
}
22192233
$num_updates++;
22202234
unset( $this->db_check_slugs[ $idx ] );
22212235
$this->db_check_num_slugs--;

tests/db_checkTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1637,7 +1637,7 @@ function test_db_check_normalize_slugs() {
16371637

16381638
$title2 = 'post2-title';
16391639
$content2 = 'post2-content' . $decomposed_str1;
1640-
$post_name2 = "post2-name-%c3%bc";
1640+
$post_name2 = "post2-name-%c3%bc"; // Not decomposed.
16411641

16421642
$post2 = $this->factory->post->create_and_get( array( 'post_title' => $title2, 'post_content' => $content2, 'post_type' => 'post', 'post_name' => $post_name2 ) );
16431643
$this->assertTrue( is_object( $post2 ) );
@@ -1744,6 +1744,7 @@ function test_db_check_normalize_slugs() {
17441744
$die = self::$func_args['wp_die'][0];
17451745
$this->assertSame( count( $items ) - count( $_REQUEST['item'] ), $die['args']['num_slugs'] );
17461746
$this->assertNotContains( $title1, unfc_list_pluck( $die['args']['slugs'], 'title' ) ); // Can't use id as could be same between types.
1747+
$this->assertContains( $post_name1, (array) get_post_meta( $post1->ID, '_wp_old_slug' ) );
17471748

17481749
ob_start();
17491750
do_action( $hook_suffix );
@@ -1781,6 +1782,7 @@ function test_db_check_normalize_slugs() {
17811782
$die = self::$func_args['wp_die'][0];
17821783
$this->assertSame( 2, $die['args']['num_slugs'] );
17831784
$this->assertSame( $unfc_normalize->db_check_error_msg( UNFC_DB_CHECK_SYNC_ERROR ), $die['args'][0][1] );
1785+
$this->assertContains( $post_name3, (array) get_post_meta( $post3->ID, '_wp_old_slug' ) );
17841786

17851787
self::clear_func_args();
17861788

@@ -1798,6 +1800,7 @@ function test_db_check_normalize_slugs() {
17981800
$this->assertTrue( false !== stripos( $die['args'][0][1], 'nothing' ) );
17991801
$this->assertSame( 'warning', $die['args'][1][0] );
18001802
$this->assertTrue( false !== stripos( $die['args'][1][1], '1' ) );
1803+
$this->assertNotContains( $post_name2, (array) get_post_meta( $post2->ID, '_wp_old_slug' ) ); // Slug was normalized (%c3%b2).
18011804

18021805
self::clear_func_args();
18031806

0 commit comments

Comments
 (0)