Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backport-changelog/6.9/8063.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ https://github.com/WordPress/wordpress-develop/pull/8063

* https://github.com/WordPress/gutenberg/pull/67125
* https://github.com/WordPress/gutenberg/pull/71811
* https://github.com/WordPress/gutenberg/pull/72003
* https://github.com/WordPress/gutenberg/pull/72029
* https://github.com/WordPress/gutenberg/pull/72049
38 changes: 38 additions & 0 deletions lib/compat/wordpress-6.9/site-editor-redirect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
Copy link
Member Author

Choose a reason for hiding this comment

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

I took this pattern from

function gutenberg_get_site_editor_redirection() {


/**
* Maps old site editor urls to the new updated ones.
*
* @since 6.9.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_6_9() {
global $pagenow;

if ( 'site-editor.php' !== $pagenow ) {
return false;
}

// The following redirects are for the new permalinks in the site editor.
if ( isset( $_GET['p'] ) && preg_match( '/^\/wp_template\/([a-zA-Z0-9-]+\/\/[a-zA-Z0-9-]+)$/', $_GET['p'], $matches ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any point in using $_REQUEST instead? Also, probably a good place to use a different delimiter for the PCRE pattern:

Suggested change
if ( isset( $_GET['p'] ) && preg_match( '/^\/wp_template\/([a-zA-Z0-9-]+\/\/[a-zA-Z0-9-]+)$/', $_GET['p'], $matches ) ) {
if ( isset( $_GET['p'] ) && preg_match( '_^/wp_template/([a-zA-Z0-9-]+//[a-zA-Z0-9-]+)$_', $_GET['p'], $matches ) ) {
}

Copy link
Contributor

Choose a reason for hiding this comment

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

As a friendly bonus, I also suggest adding a comment above with the overall shape of the redirection, to make scanning the code easier. Something like:

// /wp_template/tt5//home -> /wp_registered_template/tt5//home

Copy link
Member Author

Choose a reason for hiding this comment

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

Why should we use $_REQUEST? Sure, we can use a different pattern and add a comment

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, the suggestion introduced an extra }

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, sorry. :)

Why should we use $_REQUEST?

No good reason comes to mind, but the fact that gutenberg_get_site_editor_redirection did made me wonder. Is there any scenario where we could expect a POST request to need redirection? Put differently: could it hurt to use $_REQUEST?

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, the suggested pattern doesn't work 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

I switched it to use #

Copy link
Contributor

Choose a reason for hiding this comment

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

Ooops, I chose poorly: there are obviously underscores in the pattern. But my point still stands:

if ( preg_match( '#^/wp_template/([a-zA-Z0-9-]+//[a-zA-Z0-9-]+)$#', $input, $matches ) ) {

Copy link
Contributor

Choose a reason for hiding this comment

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

I switched it to use #

Jinx :)
(Also, when will GitHub finally properly update comment threads in real time...?)

Copy link
Member Author

@ellatrix ellatrix Oct 8, 2025

Choose a reason for hiding this comment

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

Put differently: could it hurt to use $_REQUEST?

Done, I guess it doesn't

return add_query_arg( array( 'p' => '/wp_registered_template/' . $matches[1] ), remove_query_arg( array( 'p' ) ) );
}

return false;
}

/**
* Redirect old site editor urls to the new updated ones.
*/
function gutenberg_redirect_site_editor_deprecated_urls_6_9() {
$redirection = gutenberg_get_site_editor_redirection_6_9();
if ( false !== $redirection ) {
wp_safe_redirect( $redirection );
exit;
}
}
add_action( 'admin_init', 'gutenberg_redirect_site_editor_deprecated_urls_6_9' );
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/compat/wordpress-6.9/command-palette.php';
require __DIR__ . '/compat/wordpress-6.9/preload.php';
require __DIR__ . '/compat/wordpress-6.9/l10n.php';
require __DIR__ . '/compat/wordpress-6.9/site-editor-redirect.php';

// WordPress 7.0 compat.
require __DIR__ . '/compat/wordpress-7.0/php-only-blocks.php';
Expand Down
Loading