Opened 9 years ago
Last modified 4 days ago
#39442 new defect (bug)
Custom rewrite endpoints and wp_old_slug_redirect
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | Awaiting Review | Priority: | normal |
| Severity: | normal | Version: | 4.7 |
| Component: | Rewrite Rules | Keywords: | has-patch has-unit-tests |
| Focuses: | Cc: |
Description
Previously: #33920
wp_old_slug_redirect currently only handles core rewrite endpoints (like feed and embed). If you have a custom rewrite endpoint, you end up redirected back to the new permalink.
You can use the [old_slug_redirect_url https://developer.wordpress.org/reference/hooks/old_slug_redirect_url/] filter to redirect correctly but the filter does not pass the post id, which makes things a bit challenging (especially if you need to do any processing beyond just appending the endpoint).
It would be nice if the post id was passed into the old_slug_redirect_url filter:
$link = apply_filters( 'old_slug_redirect_url', $link, $id );
It would be even nicer if the redirect handled custom endpoints automatically as well.
Attachments (1)
Change History (3)
This ticket was mentioned in Slack in #core by noisysocks. View the logs.
6 years ago
This ticket was mentioned in PR #12051 on WordPress/wordpress-develop by @deepakprajapati.
4 days ago
#2
- Keywords has-patch has-unit-tests added
## Summary
This updates wp_old_slug_redirect() to pass the resolved redirect post ID to the old_slug_redirect_url filter.
## Why
Callbacks filtering the old slug redirect URL currently receive only the generated redirect URL. Passing the post ID gives callbacks enough context to inspect the matched post before changing or disabling the redirect.
## Use of AI Tools
AI assistance: Yes
Tool(s): ChatGPT, Codex
Model(s): GPT-5.5
Used for: Initial code review, and test suggestions; final implementation and tests were reviewed and edited by me.
## Testing
Ran:
npm run test:php -- --filter Tests_Rewrite_OldSlugRedirect
## Trac Ticket
Patch to include $id as a parameter