Posts: Preserve updated slugs when restoring trashed posts#11972
Posts: Preserve updated slugs when restoring trashed posts#11972ArkaPrabhaChowdhury wants to merge 2 commits into
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Summary
This updates the trashed-post slug flow so WordPress preserves an explicitly updated slug when a post is restored from rash, and keeps _wp_desired_post_slug in sync when the slug changes while the post remains trashed.
Problem
In Trac ticket #44805, changing a post slug while the post was trashed could be lost on restore/publish. There was also a related case where publishing from rash with a new slug in the same update could incorrectly restore the older stored desired slug.
Trac ticket: https://core.trac.wordpress.org/ticket/44805
Changes
Root cause
wp_update_post() merges the existing database row into the update payload, so simply checking whether post_name is set is not enough to determine whether the slug changed in the current request.
Testing
ode ./tools/local-env/scripts/docker.js run --rm php ./vendor/bin/phpunit tests/phpunit/tests/post/wpInsertPost.php --filter "test_(updating_a_trashed_posts_slug_should_update_the_stored_desired_post_name|publishing_a_trashed_post_should_keep_an_updated_slug|publishing_a_trashed_post_with_a_new_slug_in_the_same_update_should_keep_the_new_slug)"