Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
15f1913
Site Editor: Use permalinks instead of query args and site-editor.php…
youknowriad Nov 21, 2024
edd3075
Fix some bugs
youknowriad Nov 21, 2024
6a4cc01
Fix dashboard links
youknowriad Nov 21, 2024
937ebf0
Add basic redirection
youknowriad Nov 21, 2024
c3bff73
Add server side permanent redirects for the old urls
youknowriad Nov 21, 2024
2c0b7f7
Fix the posts dataviews
youknowriad Nov 21, 2024
3c9a42c
Small fix
youknowriad Nov 21, 2024
b811a48
Remove url rewrites
youknowriad Nov 21, 2024
5153567
Fix theme previewing
youknowriad Nov 25, 2024
bc404a3
Fix query string argument
youknowriad Nov 25, 2024
b4d15dc
switch middleware to beforeNavigate
youknowriad Nov 25, 2024
e8ec07a
Filter instead of action
youknowriad Nov 25, 2024
a3324ac
Move the code to 6.8 folder
youknowriad Nov 25, 2024
2b9d0bd
Refactor deprecations
youknowriad Nov 25, 2024
5a51c5a
Set the right path to avoid redirections
youknowriad Nov 25, 2024
b03d304
Fix e2e tests
youknowriad Nov 25, 2024
551674f
Fix hybrid themes
youknowriad Nov 25, 2024
0bce3ba
Simplify redirects
youknowriad Nov 26, 2024
29eb798
Add useLocation check
youknowriad Nov 26, 2024
ff1411c
useEvent to avoid memoization
youknowriad Nov 26, 2024
e46b7ef
Return a promise from navigate
youknowriad Nov 27, 2024
544fe66
Memoize route recognizer
youknowriad Nov 27, 2024
97a7ee7
Add a comment
youknowriad Nov 27, 2024
233fa6b
Fix e2e test
youknowriad Nov 27, 2024
7fb975e
Add backport PR
youknowriad Nov 27, 2024
2e4c03d
Remove posts redirectins
youknowriad Nov 27, 2024
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
Prev Previous commit
Next Next commit
Fix query string argument
  • Loading branch information
youknowriad committed Nov 27, 2024
commit bc404a3654ce3cccedd074a9b84f2a2f6fc301a8
18 changes: 9 additions & 9 deletions lib/experimental/site-editor-permalinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function ( $settings ) {
}
);

function gutenberg_remove_query_args( $args ) {
function gutenberg_remove_query_args( $args = array() ) {
$query_string = $_SERVER['QUERY_STRING'];
$query = wp_parse_args( $query_string );
foreach ( $args as $arg_name ) {
Expand All @@ -18,7 +18,7 @@ function gutenberg_remove_query_args( $args ) {
}

function gutenberg_get_site_editor_url( $path = '', $query = array() ) {
$query_string = build_query( array_merge( $query, $path ? array( 'p' => $path ) : array() ) );
$query_string = build_query( array_merge( $query, array( 'p' => $path ) ) );
$base_url = admin_url( 'site-editor.php' );
return $query_string ? $base_url . '?' . $query_string : $base_url;
}
Expand All @@ -39,7 +39,7 @@ function gutenberg_get_posts_dataviews_url( $path = '', $query = array() ) {

function gutenberg_redirect_site_editor_to_design() {
global $pagenow;
if ( 'site-editor.php' !== $pagenow || isset( $_REQUEST['p'] ) || ! isset( $_SERVER['querystring'] ) ) {
if ( 'site-editor.php' !== $pagenow || isset( $_REQUEST['p'] ) || ! $_SERVER['QUERY_STRING'] ) {
return;
}

Expand Down Expand Up @@ -101,31 +101,31 @@ function gutenberg_redirect_site_editor_to_design() {

// The following redirects are for backward compatibility with the old site editor URLs.
if ( isset( $_REQUEST['path'] ) && '/wp_template_part/all' === $_REQUEST['path'] ) {
wp_redirect( gutenberg_get_site_editor_url( '/pattern?postType=wp_template_part' ), 301 );
wp_redirect( gutenberg_get_site_editor_url( '/pattern?postType=wp_template_part', gutenberg_remove_query_args( 'path' ) ), 301 );
exit;
}

if ( isset( $_REQUEST['path'] ) && '/page' === $_REQUEST['path'] ) {
wp_redirect( gutenberg_get_site_editor_url( '/page' ), 301 );
wp_redirect( gutenberg_get_site_editor_url( '/page', gutenberg_remove_query_args( 'path' ) ), 301 );
exit;
}

if ( isset( $_REQUEST['path'] ) && '/wp_template' === $_REQUEST['path'] ) {
wp_redirect( gutenberg_get_site_editor_url( '/template' ), 301 );
wp_redirect( gutenberg_get_site_editor_url( '/template', gutenberg_remove_query_args( 'path' ) ), 301 );
exit;
}

if ( isset( $_REQUEST['path'] ) && '/patterns' === $_REQUEST['path'] ) {
wp_redirect( gutenberg_get_site_editor_url( '/pattern' ), 301 );
wp_redirect( gutenberg_get_site_editor_url( '/pattern', gutenberg_remove_query_args( 'path' ) ), 301 );
exit;
}

if ( isset( $_REQUEST['path'] ) && '/navigation' === $_REQUEST['path'] ) {
wp_redirect( gutenberg_get_site_editor_url( '/navigation' ), 301 );
wp_redirect( gutenberg_get_site_editor_url( '/navigation', gutenberg_remove_query_args( 'path' ) ), 301 );
exit;
}

wp_redirect( gutenberg_get_site_editor_url(), 301 );
wp_redirect( gutenberg_get_site_editor_url( '', gutenberg_remove_query_args()), 301 );
exit;
}
add_action( 'admin_init', 'gutenberg_redirect_site_editor_to_design' );
Expand Down