Skip to content

Commit f2ea441

Browse files
Site Editor: Use temporary redirects for deprecated URLs. (#68971)
Modifies the redirects from deprecated site-editor URLs to use 302 temporary redirects rather than 301 permanent redirects. This prevents the browser from caching the redirect as the destination will differ for logged in and logged out users. This also switches from using `wp_redirect()` to `wp_safe_redirect()` in accordance with best practices when redirecting within a WordPress site. Follow up to #67199 Incorporating changes in WordPress/wordpress-develop#7903 See https://core.trac.wordpress.org/ticket/62585 Co-authored-by: peterwilsoncc <[email protected]> Co-authored-by: Mamaduka <[email protected]>
1 parent 2dd6aa1 commit f2ea441

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

backport-changelog/6.8/7903.md

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
https://github.com/WordPress/wordpress-develop/pull/7903
22

33
* https://github.com/WordPress/gutenberg/pull/67199
4+
* https://github.com/WordPress/gutenberg/pull/68971
5+

lib/compat/wordpress-6.8/site-editor.php

+14-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ function ( $settings ) {
1515
}
1616
);
1717

18+
/**
19+
* Maps old site editor urls to the new updated ones.
20+
*
21+
* @since 6.8.0
22+
* @access private
23+
*
24+
* @global string $pagenow The filename of the current screen.
25+
*
26+
* @return string|false The new URL to redirect to, or false if no redirection is needed.
27+
*/
1828
function gutenberg_get_site_editor_redirection() {
1929
global $pagenow;
2030
if ( 'site-editor.php' !== $pagenow || isset( $_REQUEST['p'] ) || ! $_SERVER['QUERY_STRING'] ) {
@@ -96,10 +106,13 @@ function gutenberg_get_site_editor_redirection() {
96106
return add_query_arg( array( 'p' => '/' ) );
97107
}
98108

109+
/**
110+
* Redirect old site editor urls to the new updated ones.
111+
*/
99112
function gutenberg_redirect_site_editor_deprecated_urls() {
100113
$redirection = gutenberg_get_site_editor_redirection();
101114
if ( false !== $redirection ) {
102-
wp_redirect( $redirection, 301 );
115+
wp_safe_redirect( $redirection );
103116
exit;
104117
}
105118
}

0 commit comments

Comments
 (0)