WordPress.org

Make WordPress Core

Opened 5 months ago

Last modified 4 months ago

#52737 new enhancement

Allow 301 redirect on _wp_old_slug to be filterable

Reported by: brookedot Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Permalinks Keywords: has-patch needs-testing
Focuses: Cc:

Description

While the URL on old_slug_redirect_url is filterable the same should be true for the redirect status. It currently is hardcoded as a 301. Allowing any status code will allow for 302 or other status to be used.

https://core.trac.wordpress.org/browser/trunk/src/wp-includes/query.php#L1082

Attachments (3)

52737.patch (557 bytes) - added by brookedot 5 months ago.
52737.2.patch (557 bytes) - added by brookedot 5 months ago.
52737.3.2.patch (554 bytes) - added by brookedot 5 months ago.

Download all attachments as: .zip

Change History (6)

@brookedot
5 months ago

#1 @mukesh27
5 months ago

  • Keywords needs-refresh added

As per wp_redirect document $status use int parameter. So we have to change the doc block for the filter like below

/**
 * Filters the old slug redirect status.
 *
 * @since 5.8.0
	 *
 * @param int $status The HTTP response status code to use.
 */

@brookedot
5 months ago

#2 @brookedot
5 months ago

  • Keywords needs-refresh removed

As per wp_redirect document $status use int parameter.

Good catch, updated in 52737.3.2.patch. Not sure why my patch naming was off, but the patch itself should be good.

I'll also mention #40032 as a tangentially related ticket that also touches this code. If both are implemented the one that is added second may need an additional be refresh,

Last edited 5 months ago by brookedot (previous) (diff)

#3 @peterwilsoncc
4 months ago

Thanks for the patch, this makes sense:

  • Minor nit pick: the permanent redirect comment next to wp_redirect can be deleted as it may not be permanent.
  • I think it would be handy to include the post ID or post object as a second parameter on the new filter, this will allow developers to use different status codes under different circumstances.

(BTW: Trac's patch renaming can be weird, if you upload files with 52737.patch or 52737.diff trac will do a better job working out if it needs to rename.)

Note: See TracTickets for help on using tickets.