WordPress.org

Make WordPress Core

Opened 8 years ago

Closed 7 years ago

Last modified 7 years ago

#20480 closed defect (bug) (fixed)

Can't access original slug with wp_unique_post_slug filter

Reported by: bradyvercher Owned by: nacin
Milestone: 3.5 Priority: normal
Severity: normal Version: 3.3
Component: Permalinks Keywords: has-patch
Focuses: Cc:
PR Number:

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)

20480.patch (620 bytes) - added by johnbillion 8 years ago.
20480.2.diff (1.3 KB) - added by coffee2code 7 years ago.
Adds wp_unique_post_slug filter as proposed in 20480.patch; adds pre_wp_unique_post_slug filter; adds some phpDoc

Download all attachments as: .zip

Change History (9)

#1 @johnbillion
8 years ago

  • Severity changed from trivial to normal
  • Type changed from enhancement to defect (bug)
  • Version changed from 3.3.1 to 3.3

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

@johnbillion
8 years ago

#2 @johnbillion
8 years ago

  • Keywords has-patch added

Patch

#3 @bradyvercher
8 years 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
7 years ago

Adds wp_unique_post_slug filter as proposed in 20480.patch; adds pre_wp_unique_post_slug filter; adds some phpDoc

#4 @coffee2code
7 years 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.

#5 follow-up: @nacin
7 years ago

  • Milestone changed from Awaiting Review to 3.5

Sounds good. Can we consider the pre_* filter in a separate ticket?

#6 @nacin
7 years ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [21177]:

Take the original slug passed into wp_unique_post_slug() and pass it to the wp_unique_post_slug filter. props johnbillion. fixes #20480.

#7 in reply to: ↑ 5 @coffee2code
7 years ago

Replying to nacin:

Sounds good. Can we consider the pre_* filter in a separate ticket?

Opened as #21112.

Note: See TracTickets for help on using tickets.