lib/compat/plugin
edit-site-routes-backwards-compat.php
1.7 KB
3 years ago
fonts.php
1.2 KB
2 years ago
edit-site-routes-backwards-compat.php in Gutenberg 23.2.0, at lib/compat/plugin/edit-site-routes-backwards-compat.php
| 1 | <?php |
| 2 | /** |
| 3 | * Backwards compatibility handling for routes used by the plugin consumers. |
| 4 | * This doesn't need to be back ported to core and will be removed after WP 6.1, |
| 5 | * to ensure that the plugin consumers have enough time to migrate to the core's |
| 6 | * route (`site-editor.php`). |
| 7 | * |
| 8 | * Allows the `theme.php` route and redirects the following routes: |
| 9 | * - `themes.php?page=gutenberg-edit-site` |
| 10 | * - `admin.php?page=gutenberg-edit-site` |
| 11 | * |
| 12 | * To `site-editor.php`. |
| 13 | * |
| 14 | * The old routes have been deprecated and removed in Gutenberg 13.7.0, but third-party |
| 15 | * consumer code might still be referencing them. In order to not break the Site Editor |
| 16 | * flows, we don't fully remove the old routes, but redirect them to the core's one. |
| 17 | * |
| 18 | * @see https://github.com/WordPress/gutenberg/pull/41306 |
| 19 | * |
| 20 | * @package gutenberg |
| 21 | */ |
| 22 | |
| 23 | /** |
| 24 | * Allows the old routes. Without this, trying to access the old Site Editor |
| 25 | * routes results in a HTTP 403 error. |
| 26 | * |
| 27 | * Allowing the route is done by adding an wp-admin submenu page that won't be rendered. |
| 28 | */ |
| 29 | function gutenberg_site_editor_menu() { |
| 30 | if ( wp_is_block_theme() ) { |
| 31 | add_submenu_page( '', '', '', 'edit_theme_options', 'gutenberg-edit-site', '__return_empty_string' ); |
| 32 | } |
| 33 | } |
| 34 | add_action( 'admin_menu', 'gutenberg_site_editor_menu', 9 ); |
| 35 | |
| 36 | /** |
| 37 | * Does the actual redirect to the new route upon triggering of the `load-appearance_page_gutenberg-edit-site` action. |
| 38 | */ |
| 39 | function gutenberg_redirect_deprecated_to_new_site_editor_page() { |
| 40 | wp_safe_redirect( 'site-editor.php' ); |
| 41 | exit; |
| 42 | } |
| 43 | add_action( 'load-appearance_page_gutenberg-edit-site', 'gutenberg_redirect_deprecated_to_new_site_editor_page' ); |
| 44 | add_action( 'load-admin_page_gutenberg-edit-site', 'gutenberg_redirect_deprecated_to_new_site_editor_page' ); |
| 45 |