Version: 1.0
Prevent the slug of a trashed page or post from conflicting with the slug desired for a new page or post.
FAQ
What happens if I trash a post and then restore it?
The post retains its original slug, as was always the case.
What happens if I trash a post, publish a new post with that same slug, then restore the original post?
Because the trashed post’s original slug is in use by a new post at the time it gets restored from the trash, the original post would use a reassigned slug. Once an untrashed post is given a reassigned slug, it will no longer have the ability to return to its original slug without manual intervention.
What happens if I trash a post, publish a new post with that same slug, then trash the second post and restore the original post?
Upon restoration, the original post will retain its original slug. The plugin keeps track when a trashed post’s slug gets changed. It tries to restore the post’s original slug if it isn’t in use at the time the post gets untrashed.
What slug gets assigned to a trashed post when a newer post wants to have the same slug?
When a new post gets created, WordPress tries to determine if a conflict exists. If one does, WordPress appends “-” and then a number to the slug until a unique slug is found. Therefore, if “about” is taken, then it tries “about-2”. If that’s taken, then it tries “about-3” and so on. Rather than let WP assign the “about-2” to the new post, this plugin flips things and gives the new post “about” and the trashed post “about-2”.
Why doesn’t WordPress do what this plugin does by default?
It should! There is an ages-old, still open Trac ticket (ticket #11863) concerning how to handle slug conflicts with trashed posts. No consensus to change existing behavior has been reached. Feel free to chime in to the discussion there and advocate the plugin’s approach if you agree with how the plugin handles things.
UPDATE: The aforementioned Trac ticket has been resolved as of WordPress 4.5. Therefore, this plugin is no longer necessary.
As a user of this plugin, what happens now that WordPress 4.5 and beyond now natively supports this functionality?
If v1.2 of the plugin is run under WP 4.5 or later, it migrates any previously stored original slugs for trashed posts to the postmeta name recognized by WordPress. Then the plugin deactivates itself since it has no further use. At this point, feel free to delete the plugin from your site.
v1.2 of the plugin will continue to work as expected for sites running a version of WP earlier than 4.5.
Does this plugin include unit tests?
Yes.
ChangeLog
1.2 (2016-05-07)
Highlights: WordPress 4.5 has effectively implemented the functionality provided by this plugin, thus it is no longer needed.
- New: Self-deactivate and show deprecation notice if plugin is active under WP 4.5+ and don’t do anything else.
- New: Migrate existing meta keys that stored original post slugs to the meta key used by WP.
- New: Add unit tests that only run under versions of WP equal to or greater than 4.5.
- Change: Prevent existing tests from running under versions of WP older than 4.5.
- Change: Prevent web invocation of unit test bootstrap.php.
- Change: Prevent direct loading of test file.
- Change: Add ‘Text Domain’ plugin header.
- New: Create empty index.php to prevent files from being listed if web server has enabled directory listings.
- New: Add LICENSE file.
1.1 (2015-12-08)
Highlights:
- This minor release sync’s the plugin’s checks with those recently added/changed in core and enhances the unit tests.
Details:
- Change: Re-sync
get_trashed_post()
with changes to wp_unique_post_slug()
- Check for slugs that could result in URLs that conflict with date archives
- Simplify post hierarchy checking for hierarchical post types
- Change: Modify many unit tests to use a dataProvider to allow testing for both posts and pages
1.0.4 (2015-12-07)
Highlights:
- This is a very minor update primarily consisting of documentation improvements, including an addition that provides an overview of the plugin’s approach to the problem it solves and documentation for all unit tests.
Details:
- Add: Create new section in readme explaining the implemented solution to the trash slug conflict problem
- Add: Document the purpose and expectations of each unit test
- Change: Improvements to existing documentation
- Change: Switch a majority of unit tests to work with posts rather than pages (though it doesn’t really matter)
- Change: Minor code formatting changes (braces)
- Change: Explicitly declare methods in unit tests as public
- Change: Minor improvements to inline docs and test docs
- Change: Note compatibility through WP 4.4+
- Change: Update copyright date (2016)
1.0.3 (2015-02-11)
- Note compatibility through WP 4.1+
- Update copyright date (2015)
1.0.2 (2014-08-25)
- Add an FAQ question regarding why WP core doesn’t do things the way the plugin does things
- Minor code reformatting (bracing)
- Change documentation links to wp.org to be https
- Change donate link
- Note compatibility through WP 4.0+
- Add plugin icon
1.0.1
- Add
c2c_No_Slug_Conflicts_With_Trash::version()
to return version number for plugin (with unit test)
- Note compatibility through WP 3.8+
- Update copyright date (2014)
- Change donate link
1.0