#20480 closed defect (bug) (fixed)
Can't access original slug with wp_unique_post_slug filter
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Priority: | normal | Milestone: | 3.5 |
| Component: | Permalinks | Version: | 3.3 |
| Severity: | normal | Keywords: | has-patch |
| Cc: |
Description
This is a follow up to #14111.
The slug passed to the 'wp_unique_post_slug' filter may already be suffixed by the time it's accessible. This requires the default suffix algorithm to be reversed if a developer wants access to the original slug in order to apply their own uniqueness algorithm.
It would be great if the original slug was passed as a parameter in the current filter, or if a new filter was added before the default uniqueness algorithms are executed.
Attachments (2)
Change History (9)
comment:1
johnbillion — 12 months ago
- Severity changed from trivial to normal
- Type changed from enhancement to defect (bug)
- Version changed from 3.3.1 to 3.3
johnbillion — 12 months ago
comment:3
bradyvercher — 12 months ago
That should do it. Thanks!
As an enhancement, something like a pre_wp_unique_post_slug filter that operates similar to this patch might also be beneficial so plugins can bypass the default processing.
coffee2code — 11 months ago
Adds wp_unique_post_slug filter as proposed in 20480.patch; adds pre_wp_unique_post_slug filter; adds some phpDoc
comment:4
coffee2code — 11 months ago
+1
As @johnbillion said, the wp_unique_post_slug filter is of limited, or at least diminished, use if the original slug isn't also passed. If passed, then any hooked functions could easily detect if wp_unique_post_slug() modified the incoming slug due to a conflict and could act accordingly (perhaps using different slug renaming logic or for logging).
And as @bradyvercher most recently mentioned, a pre_wp_unique_post_slug filter could be useful and justified here for a few reasons:
- The wp_unique_post_slug() function (and thus the filter) is not high use, so won't impact performance
- wp_unique_post_slug() performs database queries (perhaps repeatedly until a unique slug is found), all of which may be rendered moot if a hooking function's intent is to implement its own slug generation/handling logic. The pre slug could short-circuit that unnecessary effort.
Attached 20480.2.diff which amends original patch to add pre filter and some phpDocs.
- Milestone changed from Awaiting Review to 3.5
Sounds good. Can we consider the pre_* filter in a separate ticket?
- Owner set to nacin
- Resolution set to fixed
- Status changed from new to closed
In [21177]:

I'd class this as a bug. The filter has limited use without passing the original slug.