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

Site Editor: Redirect old urls to the new path based ones #7903

Open
wants to merge 8 commits into
base: trunk
Choose a base branch
from
107 changes: 95 additions & 12 deletions src/wp-admin/site-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,102 @@
);
}

$is_template_part = isset( $_GET['postType'] ) && 'wp_template_part' === sanitize_key( $_GET['postType'] );
$is_template_part_path = isset( $_GET['path'] ) && 'wp_template_partall' === sanitize_key( $_GET['path'] );
$is_template_part_editor = $is_template_part || $is_template_part_path;
$is_patterns = isset( $_GET['postType'] ) && 'wp_block' === sanitize_key( $_GET['postType'] );
$is_patterns_path = isset( $_GET['path'] ) && 'patterns' === sanitize_key( $_GET['path'] );
$is_patterns_editor = $is_patterns || $is_patterns_path;

if ( ! wp_is_block_theme() ) {
if ( ! current_theme_supports( 'block-template-parts' ) && $is_template_part_editor ) {
wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) );
} elseif ( ! $is_patterns_editor && ! $is_template_part_editor ) {
wp_die( __( 'The theme you are currently using is not compatible with the Site Editor.' ) );
/**
* 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 _get_site_editor_redirection_url() {
global $pagenow;
peterwilsoncc marked this conversation as resolved.
Show resolved Hide resolved
if ( 'site-editor.php' !== $pagenow || isset( $_REQUEST['p'] ) || ! $_SERVER['QUERY_STRING'] ) {
return false;
}

// The following redirects are for the new permalinks in the site editor.
if ( isset( $_REQUEST['postType'] ) && 'wp_navigation' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) {
return add_query_arg( array( 'p' => '/wp_navigation/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) );
}

if ( isset( $_REQUEST['postType'] ) && 'wp_navigation' === $_REQUEST['postType'] && empty( $_REQUEST['postId'] ) ) {
return add_query_arg( array( 'p' => '/navigation' ), remove_query_arg( 'postType' ) );
}

if ( isset( $_REQUEST['path'] ) && '/wp_global_styles' === $_REQUEST['path'] ) {
return add_query_arg( array( 'p' => '/styles' ), remove_query_arg( 'path' ) );
}

if ( isset( $_REQUEST['postType'] ) && 'page' === $_REQUEST['postType'] && ( empty( $_REQUEST['canvas'] ) || empty( $_REQUEST['postId'] ) ) ) {
return add_query_arg( array( 'p' => '/page' ), remove_query_arg( 'postType' ) );
}

if ( isset( $_REQUEST['postType'] ) && 'page' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) {
return add_query_arg( array( 'p' => '/page/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) );
}

if ( isset( $_REQUEST['postType'] ) && 'wp_template' === $_REQUEST['postType'] && ( empty( $_REQUEST['canvas'] ) || empty( $_REQUEST['postId'] ) ) ) {
return add_query_arg( array( 'p' => '/template' ), remove_query_arg( 'postType' ) );
}

if ( isset( $_REQUEST['postType'] ) && 'wp_template' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) {
return add_query_arg( array( 'p' => '/wp_template/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) );
}

if ( isset( $_REQUEST['postType'] ) && 'wp_block' === $_REQUEST['postType'] && ( empty( $_REQUEST['canvas'] ) || empty( $_REQUEST['postId'] ) ) ) {
return add_query_arg( array( 'p' => '/pattern' ), remove_query_arg( 'postType' ) );
}

if ( isset( $_REQUEST['postType'] ) && 'wp_block' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) {
return add_query_arg( array( 'p' => '/wp_block/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) );
}

if ( isset( $_REQUEST['postType'] ) && 'wp_template_part' === $_REQUEST['postType'] && ( empty( $_REQUEST['canvas'] ) || empty( $_REQUEST['postId'] ) ) ) {
return add_query_arg( array( 'p' => '/pattern' ) );
}

if ( isset( $_REQUEST['postType'] ) && 'wp_template_part' === $_REQUEST['postType'] && ! empty( $_REQUEST['postId'] ) ) {
return add_query_arg( array( 'p' => '/wp_template_part/' . $_REQUEST['postId'] ), remove_query_arg( array( 'postType', 'postId' ) ) );
}

// The following redirects are for backward compatibility with the old site editor URLs.
if ( isset( $_REQUEST['path'] ) && '/wp_template_part/all' === $_REQUEST['path'] ) {
return add_query_arg(
array(
'p' => '/pattern',
'postType' => 'wp_template_part',
),
remove_query_arg( 'path' )
);
}

if ( isset( $_REQUEST['path'] ) && '/page' === $_REQUEST['path'] ) {
return add_query_arg( array( 'p' => '/page' ), remove_query_arg( 'path' ) );
}

if ( isset( $_REQUEST['path'] ) && '/wp_template' === $_REQUEST['path'] ) {
return add_query_arg( array( 'p' => '/template' ), remove_query_arg( 'path' ) );
}

if ( isset( $_REQUEST['path'] ) && '/patterns' === $_REQUEST['path'] ) {
return add_query_arg( array( 'p' => '/pattern' ), remove_query_arg( 'path' ) );
}

if ( isset( $_REQUEST['path'] ) && '/navigation' === $_REQUEST['path'] ) {
return add_query_arg( array( 'p' => '/navigation' ), remove_query_arg( 'path' ) );
}

return add_query_arg( array( 'p' => '/' ) );
}

// Redirect to the site editor to the new URLs if needed.
$redirection = _get_site_editor_redirection_url();
if ( false !== $redirection ) {
wp_safe_redirect( $redirection, 301 );
exit;
}

// Used in the HTML title tag.
Expand Down
1 change: 1 addition & 0 deletions src/wp-includes/block-editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ function get_default_block_editor_settings() {
'imageEditing' => true,
'imageSizes' => $available_image_sizes,
'maxUploadFileSize' => $max_upload_size,
'__experimentalDashboardLink' => admin_url( '/' ),
joemcgill marked this conversation as resolved.
Show resolved Hide resolved
// The following flag is required to enable the new Gallery block format on the mobile apps in 5.9.
'__unstableGalleryWithImageBlocks' => true,
);
Expand Down
Loading