From f2ea441ec7bda6dad4fdb43aac509fcee4a56abc Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Sat, 1 Feb 2025 11:53:16 +1100 Subject: [PATCH] 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 https://github.com/WordPress/wordpress-develop/pull/7903 See https://core.trac.wordpress.org/ticket/62585 Co-authored-by: peterwilsoncc Co-authored-by: Mamaduka --- backport-changelog/6.8/7903.md | 2 ++ lib/compat/wordpress-6.8/site-editor.php | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/backport-changelog/6.8/7903.md b/backport-changelog/6.8/7903.md index cb20d8d2dd2b1..60703831a8e39 100644 --- a/backport-changelog/6.8/7903.md +++ b/backport-changelog/6.8/7903.md @@ -1,3 +1,5 @@ https://github.com/WordPress/wordpress-develop/pull/7903 * https://github.com/WordPress/gutenberg/pull/67199 +* https://github.com/WordPress/gutenberg/pull/68971 + diff --git a/lib/compat/wordpress-6.8/site-editor.php b/lib/compat/wordpress-6.8/site-editor.php index 9b2575676047d..82ac118b013c1 100644 --- a/lib/compat/wordpress-6.8/site-editor.php +++ b/lib/compat/wordpress-6.8/site-editor.php @@ -15,6 +15,16 @@ function ( $settings ) { } ); +/** + * Maps old site editor urls to the new updated ones. + * + * @since 6.8.0 + * @access private + * + * @global string $pagenow The filename of the current screen. + * + * @return string|false The new URL to redirect to, or false if no redirection is needed. + */ function gutenberg_get_site_editor_redirection() { global $pagenow; if ( 'site-editor.php' !== $pagenow || isset( $_REQUEST['p'] ) || ! $_SERVER['QUERY_STRING'] ) { @@ -96,10 +106,13 @@ function gutenberg_get_site_editor_redirection() { return add_query_arg( array( 'p' => '/' ) ); } +/** + * Redirect old site editor urls to the new updated ones. + */ function gutenberg_redirect_site_editor_deprecated_urls() { $redirection = gutenberg_get_site_editor_redirection(); if ( false !== $redirection ) { - wp_redirect( $redirection, 301 ); + wp_safe_redirect( $redirection ); exit; } }