| @@ -26,10 +26,11 @@ | ||
| 26 | 26 | * `desktop_mode_classic=1` flag and the next page falls back to the |
| 27 | 27 | * desktop shell — because the user meta is still `'1'` and the |
| 28 | 28 | * `admin_init` portal redirect kicks in. The JS here re-stamps the flag |
| 29 | 29 | * on every same-origin `/wp-admin/` `<a href>` and `<form action>` so |
| 30 | - * navigations within the tab stay classic. Server-side redirects are | |
| 31 | - * covered by {@see openstation_classic_preserve_redirect}. | |
| 30 | + * navigations within the tab stay classic, and keeps it in the address | |
| 31 | + * bar. Server-side redirects are covered by | |
| 32 | + * {@see openstation_classic_preserve_redirect}. | |
| 32 | 33 | * |
| 33 | 34 | * Narrowly scoped: only runs when the current request itself carries |
| 34 | 35 | * the classic flag. Skips modifier-clicks (cmd/ctrl/shift/alt), targets |
| 35 | 36 | * other than `_self`, downloads, anchors, and non-http schemes so we |
| @@ -105,8 +106,24 @@ | ||
| 105 | 106 | if ( rewritten ) { |
| 106 | 107 | form.setAttribute( 'action', rewritten ); |
| 107 | 108 | } |
| 108 | 109 | }, true ); |
| 110 | + | |
| 111 | + // The block editor rewrites the address bar on load, dropping the | |
| 112 | + // flag; the server reads it off the Referer of script navigations. | |
| 113 | + [ 'pushState', 'replaceState' ].forEach( function ( method ) { | |
| 114 | + var original = window.history[ method ]; | |
| 115 | + if ( typeof original !== 'function' ) { | |
| 116 | + return; | |
| 117 | + } | |
| 118 | + window.history[ method ] = function ( state, title, url ) { | |
| 119 | + var rewritten = null; | |
| 120 | + if ( typeof url === 'string' || url instanceof URL ) { | |
| 121 | + rewritten = rewriteAdminUrl( String( url ), window.location.href ); | |
| 122 | + } | |
| 123 | + return original.call( window.history, state, title, rewritten || url ); | |
| 124 | + }; | |
| 125 | + } ); | |
| 109 | 126 | } )(); |
| 110 | 127 | "; |
| 111 | 128 | |
| 112 | 129 | wp_print_inline_script_tag( $js ); |