Skip to content

Commit

Permalink
Site Editor: Use temporary redirects for deprecated URLs. (#68971)
Browse files Browse the repository at this point in the history
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]>
  • 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

1 comment on commit f2ea441

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in f2ea441.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/13083347449
📝 Reported issues:

Please sign in to comment.