Skip to content

Posts: Preserve updated slugs when restoring trashed posts#11972

Open
ArkaPrabhaChowdhury wants to merge 2 commits into
WordPress:trunkfrom
ArkaPrabhaChowdhury:trac-44805-trash-slug-restore
Open

Posts: Preserve updated slugs when restoring trashed posts#11972
ArkaPrabhaChowdhury wants to merge 2 commits into
WordPress:trunkfrom
ArkaPrabhaChowdhury:trac-44805-trash-slug-restore

Conversation

@ArkaPrabhaChowdhury
Copy link
Copy Markdown

@ArkaPrabhaChowdhury ArkaPrabhaChowdhury commented May 26, 2026

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

  • Only restore _wp_desired_post_slug when the slug was not actually changed in the current update.
  • When a trashed post's slug is updated while it remains in rash, store that updated desired slug and keep the persisted trashed slug suffixed.
  • Add regression tests for:
    • updating the slug while trashed
    • publishing after updating the slug while trashed
    • publishing with a new slug in the same update

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

  • phpcbf --standard=phpcs.xml.dist src/wp-includes/post.php tests/phpunit/tests/post/wpInsertPost.php
  • phpcs --standard=phpcs.xml.dist src/wp-includes/post.php tests/phpunit/tests/post/wpInsertPost.php

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)"


@github-actions
Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@ArkaPrabhaChowdhury ArkaPrabhaChowdhury marked this pull request as ready for review May 27, 2026 09:38
@github-actions
Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props arkaprabhachowdhury.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant