-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Template activation: redirect theme templates urls to wp_registered_template #72003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
1e007ef
ada2bb0
19bb4d8
4df8165
ba64aa7
cb3ba65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,38 @@ | ||||||||
| <?php | ||||||||
|
|
||||||||
| /** | ||||||||
| * 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 ) ) { | ||||||||
|
||||||||
| 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 ) ) { | |
| } |
There was a problem hiding this comment.
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//homeThere was a problem hiding this comment.
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
There was a problem hiding this comment.
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 }
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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 #
There was a problem hiding this comment.
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 ) ) {There was a problem hiding this comment.
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...?)
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
gutenberg/lib/compat/wordpress-6.8/site-editor.php
Line 28 in 8a4cb31