Skip to content

Commit

Permalink
Site Editor: Use temporary redirects for deprecated URLs. (WordPress#…
Browse files Browse the repository at this point in the history
…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 WordPress#67199
Incorporating changes in WordPress/wordpress-develop#7903
See https://core.trac.wordpress.org/ticket/62585

Co-authored-by: peterwilsoncc <peterwilsoncc@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
  • Loading branch information
3 people authored Feb 1, 2025
1 parent 2dd6aa1 commit f2ea441
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions backport-changelog/6.8/7903.md
Original file line number Diff line number Diff line change
@@ -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

15 changes: 14 additions & 1 deletion lib/compat/wordpress-6.8/site-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) {
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit f2ea441

Please sign in to comment.