Skip to content
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

Redirect old theme_page Site Editor routes to the new site-editor.php page #42643

Merged
merged 7 commits into from
Jul 26, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ structure for its PHP code:
Core in the future X.Y release, or that were previously merged to Core in the
X.Y release and remain in the plugin for backwards compatibility when running
the plugin on older versions of WordPress.
- `lib/compat/plugin` - Features for backwards compatibility for the plugin consumers. These files don't need to be merged to Core and should have a timeline for when they should be removed from the plugin.

## Best practices

### Prefer the `wp` prefix

For features that may be merged to Core, it's best to use a `wp_` prefix for functions or a `WP_` prefix for classes.
For features that may be merged to Core, it's best to use a `wp_` prefix for functions or a `WP_` prefix for classes.

This applies to both experimental and stable features.

Expand Down Expand Up @@ -86,7 +87,7 @@ When writing new functions and classes, it's good practice to use `! function_ex

If Core has defined a symbol once and then Gutenberg defines it a second time, fatal errors will occur.

Wrapping functions and classes avoids such errors if the feature is merged to Core.
Wrapping functions and classes avoids such errors if the feature is merged to Core.

#### Good

Expand Down Expand Up @@ -122,7 +123,7 @@ Furthermore, a quick codebase search will also help you know if your new method

### Note how your feature should look when merged to Core

Developers should write a brief note about how their feature should be merged to Core, for example, which Core file or function should be patched.
Developers should write a brief note about how their feature should be merged to Core, for example, which Core file or function should be patched.

Notes can be included in the doc comment.

Expand All @@ -133,7 +134,7 @@ This helps future developers know what to do when merging Gutenberg features int
```php
/**
* Returns a navigation object for the given slug.
*
*
* Should live in `wp-includes/navigation.php` when merged to Core.
*
* @param string $slug
Expand Down
44 changes: 44 additions & 0 deletions lib/compat/plugin/edit-site-routes-backwards-compat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Backwards compatibility handling for routes used by the plugin consumers.
* This doesn't need to be back ported to core and will be removed after WP 6.1,
* to ensure that the plugin consumers have enough time to migrate to the core's
* route (`site-editor.php`).
*
* Allows the `theme.php` route and redirects the following routes:
* - `themes.php?page=gutenberg-edit-site`
* - `admin.php?page=gutenberg-edit-site`
*
* To `site-editor.php`.
*
* The old routes have been deprecated and removed in Gutenberg 13.7.0, but third-party
* consumer code might still be referencing them. In order to not break the Site Editor
* flows, we don't fully remove the old routes, but redirect them to the core's one.
*
* @see https://github.com/WordPress/gutenberg/pull/41306
*
* @package gutenberg
*/

/**
* Allows the old routes. Without this, trying to access the old Site Editor
* routes results in a HTTP 403 error.
*
* Allowing the route is done by adding an wp-admin submenu page that won't be rendered.
*/
function gutenberg_site_editor_menu() {
if ( wp_is_block_theme() ) {
add_submenu_page( null, null, null, 'edit_theme_options', 'gutenberg-edit-site', '__return_empty_string' );
}
}
add_action( 'admin_menu', 'gutenberg_site_editor_menu', 9 );

/**
* Does the actual redirect to the new route upon triggering of the `load-appearance_page_gutenberg-edit-site` action.
*/
function gutenberg_redirect_deprecated_to_new_site_editor_page() {
wp_safe_redirect( 'site-editor.php' );
ntsekouras marked this conversation as resolved.
Show resolved Hide resolved
exit;
}
add_action( 'load-appearance_page_gutenberg-edit-site', 'gutenberg_redirect_deprecated_to_new_site_editor_page' );
add_action( 'load-admin_page_gutenberg-edit-site', 'gutenberg_redirect_deprecated_to_new_site_editor_page' );
3 changes: 3 additions & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ function gutenberg_is_experiment_enabled( $name ) {

require __DIR__ . '/experimental/editor-settings.php';

// Gutenberg plugin compat.
require __DIR__ . '/compat/plugin/edit-site-routes-backwards-compat.php';

// WordPress 6.0 compat.
require __DIR__ . '/compat/wordpress-6.0/block-gallery.php';
require __DIR__ . '/compat/wordpress-6.0/block-editor-settings.php';
Expand Down