Make WordPress Core

Opened 9 years ago

Closed 6 years ago

Last modified 6 years ago

#22338 closed defect (bug) (fixed)

Add filter for the output from `get_sample_permalink`

Reported by: simonwheatley Owned by: SergeyBiryukov
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.4.2
Component: Permalinks Keywords: has-patch 2nd-opinion
Focuses: Cc:


When getting the sample permalink the post_name is not always set in the Post object at this point. The get_sample_permalink gets around this by hacking the post_name into the Post object for the duration of the function, however it is not possible to get this "hacked in" information from the post_type_link filter. I suggest that a filter should be added to the $permalink array (which contains the link and the post name string) and various additional parameters, including the hacked Post object.

The alternative would be to try to detect situations where the data needs to be hacked in, e.g. watching for particular action GET params in an AJAX context, but this seems like a hack too far.

Attachments (5)

22338-sw.diff (974 bytes) - added by simonwheatley 9 years ago.
Adds a filter to get_sample_permalink
22338.2.patch (406 bytes) - added by JustinSainton 9 years ago.
Helping a brother out.
22338.3.diff (401 bytes) - added by JustinSainton 8 years ago.
22338-refreshed.diff (692 bytes) - added by wenthemes 6 years ago.
22338.4.diff (724 bytes) - added by SergeyBiryukov 6 years ago.

Download all attachments as: .zip

Change History (20)

9 years ago

Adds a filter to get_sample_permalink

#1 @simonwheatley
9 years ago

For context, here's where I would hope to use this in my multi-language plugin: https://github.com/simonwheatley/babble/commit/749cd96402a15944a017696282a0e66ee6bb8cfe

#2 @nacin
9 years ago

Your patch is actually your plugin commit. Could you upload a patch that implements this?

#3 @SergeyBiryukov
9 years ago

  • Keywords needs-patch added; has-patch removed

9 years ago

Helping a brother out.

#4 follow-up: @JustinSainton
9 years ago

  • Keywords has-patch added; needs-patch removed

#5 in reply to: ↑ 4 @simonwheatley
9 years ago

Replying to JustinSainton:

Belated thanks, Justin!

#6 @JustinSainton
8 years ago

Refreshed against trunk.

#7 @JustinSainton
8 years ago

Patch still applies cleanly after [25028]

#8 @JustinSainton
8 years ago

Last edited 8 years ago by JustinSainton (previous) (diff)

#9 @chriscct7
6 years ago

  • Keywords needs-refresh added; dev-feedback has-patch removed
  • Milestone changed from Awaiting Review to 4.4
  • Owner set to chriscct7
  • Status changed from new to assigned

Patch needs to be refreshed from src but otherwise it looks fine.

#10 @wenthemes
6 years ago

  • Keywords has-patch 2nd-opinion added; needs-refresh removed

This ticket was mentioned in Slack in #core by sergey. View the logs.

6 years ago

#12 @SergeyBiryukov
6 years ago

  • Owner changed from chriscct7 to SergeyBiryukov
  • Status changed from assigned to reviewing

#13 follow-up: @SergeyBiryukov
6 years ago

Some cleanup in 22338.4.diff.

Since we're going to pass the post object to the filter as the last argument, I think we should explicitly pass $post->ID instead of $id, which can be a post ID or post object.

This is not consistent with 'get_sample_permalink_html' filter, which receives $id and not $post->ID, but it's too late to change that.

#14 @wonderboymusic
6 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 34309:

Add a 'get_sample_permalink' filter.

Props SergeyBiryukov, wenthemes, JustinSainton.
Fixes #22338.

#15 in reply to: ↑ 13 @SergeyBiryukov
6 years ago

Replying to SergeyBiryukov:

This is not consistent with 'get_sample_permalink_html' filter, which receives $id and not $post->ID, but it's too late to change that.

Actually, let's do that: #33927.

Note: See TracTickets for help on using tickets.