WordPress plugin intelligence profile

No Slug Conflicts with Trash

NOTE: WordPress 4.5 incorporated the functionality of this plugin and thus it is no longer needed unless you're still running an older version of …

WP PlugIndex snapshot

Current directory snapshot

Tested up to WordPress 4.4
Current version1.2
WordPress coverageTested up to WordPress 4.4
Minimum stackWP 3.5 · PHP —
Directory statusactive
Last directory update26 Jun 201610y ago
Active installations10Adoption metric — not a quality score
WordPress.org rating5.0 / 5 from 2 ratings
Official packageDirect from WordPress.org

Repository metrics are context, not quality scores. Active installations measure adoption and can strongly reflect a plugin’s age and historical popularity. Ratings, recent updates and “Tested up to” metadata also do not guarantee modern code, error-free operation, security, feature completeness or suitability for a particular site. Why active installs don’t tell the whole story →

WP PlugIndex currently records No Slug Conflicts with Trash version 1.2 as active, updated 10y ago and tested up to WordPress 4.4.

Overview

About this plugin

5 incorporated the functionality of this plugin and thus it is no longer needed unless you’re still running an older version of WP.

This plugin implements the belief that a trashed page or post should not in any way conflict with a new page or post when it comes to slugs. In essence, a new page or post should take precedence over anything in the trash. After all, the page/post is in the trash for a reason.

By default, WordPress takes into consideration posts and pages that have been trashed when deciding if the slug for a new post is already in use. Obviously, in general, WordPress should not allow duplicate slugs because that could interfere with permalinks. The thinking behind WordPress’s handling of the situation is that trashed posts/pages are still technically present, just inaccessible.

It is possible that an author or admin would choose to restore a post from the trash, which WordPress feels should then occupy that same permalink as before it was trashed.

If what WordPress does is unclear, here’s an example to help clarify things:

  • WordPress ships with a page called “About” with the slug of “about”. The page’s URL would be http://yoursite/about/
  • Let’s say you trash that page and start a new page with the name “About”.
  • Due to a trashed page having the slug that would normally have been assigned to the new page (“about”), the new page gets the slug of “about-2”, resulting in the page’s URL being http://yoursite/about-2/

With this plugin, for this example, the new “About” page would get the slug “about” as one would hope.

That said, the plugin tries its best to restore untrashed posts to their original slug. The only time it fails to do so is if a new page or post has claimed the trashed post’s original slug, in which case the untrashed post is assigned a new slug.

See other sections of the documentation for more insight into the plugin’s functionality. See WP core ticket #11863 for discussion on the matter.

Links: Plugin Homepage | Plugin Directory Page | Author Homepage

The Solution Explained

An overview of the approach employed by the plugin to resolve the issue of slugs potentially conflicting with posts in the trash.

What WordPress does

In order to understand the crux of the implemented solution, a quick refresher on unique slug handling by WP:

Before published use, a desired slug is passed to wp_unique_post_slug() and a safe slug is returned. The safe slug may differ from the desired slug if any existing post (including a trashed post) has that slug (or, less likely, is invalid for permalink reasons such as feeds or date archives).

In order to prevent a trashed post’s slug from conflicting with a new post, this plugin takes an approach that is comprised of two primary tasks:

1. Permit a post to use a slug that conflicts with a trashed post.

The plugin hooks the ‘wp_unique_post_slug’ filter. If the desired slug matches the safe slug, the desired slug is unique and nothing needs to be done.

When the two slugs don’t match, it has to determine if the conflict is due to a trashed post or not, so it attempts to find a trashed post with the desired slug.

  • If no such trashed post is found, the conflict is with a live post (or was an otherwise unsuitable slug) so the safe slug must be used by the new post (so, again, nothing needs to be done).
  • If such a trashed post is found, then the plugin simply inverses the traditional behavior of wp_unique_post_slug(): give the trashed post the safe slug and return the desired slug for use by the new post (rather than having the trashed post retain its slug and forcing the new post to use the safe slug). In order to be able to restore a trashed post to its original slug, the trashed post’s original slug is stored in postmeta.

2. Restore a trashed post to its original slug, if necessary and possible.

For a post transitioning away from the ‘trash’ post status, check to see if its slug was rewritten (denoted by the presence of the postmeta field only assigned if the original slug was changed due to a conflict while the post was in the trash).

If there was no original slug, the slug was never changed and nothing more needs to happen.

When there is an original slug, check to see if that slug is still in use by a non-trashed post.

  • If not, restore the post slug to the original value.
  • If so, there is no recourse but to leave the post slug as-is (it is guaranteed to be unique already).

In either case, the postmeta field for the original slug value gets deleted since the now untrashed post is exposed in some fashion with its current slug and should abide by it going forward.

WordPress.org metadata

Plugin tags

Topics listed for this plugin in the WordPress.org directory.

  • post name
  • coffee2code
  • slug
  • trash
Compatibility & maintenance

Compatibility & maintenance

Tested up to WordPress 4.4

Not yet marked as tested with WordPress 7.1. WordPress.org currently lists Tested up to 4.4.

Current WordPress releaseWordPress 7.1
WordPress.org Tested up to4.4
Minimum requirementsWordPress 3.5 · PHP not listed
Update activity26 Jun 201610y ago

“Tested up to” is directory metadata supplied by the plugin author. WP PlugIndex does not turn an older declaration into a claim that the plugin is incompatible.

Changes recorded by WP PlugIndex

Recent tracked changes

No tracked version or compatibility changes have been recorded by WP PlugIndex yet.

Tracking & source

WP PlugIndex tracks public WordPress.org directory metadata and records selected version, compatibility and availability changes as they are detected.

Plugin watchlist

Watch this plugin

Sign in to your WP PlugIndex account or create a free account. Free accounts can watch up to 5 plugins and see what changed.

Watch limit

Watchlist limit reached

You have reached your current active watch limit.