| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Desktop Mode — Classic-tab link interceptor. | |
| 3 | + * OpenStation — Classic-tab link interceptor. | |
| 4 | 4 | * |
| 5 | 5 | * Runs only inside detached "classic override" tabs (the ones |
| 6 | 6 | * opened by the Detach window-chrome action with |
| 7 | 7 | * `?desktop_mode_classic=1`). Re-stamps the flag onto every |
| @@ -7,14 +7,14 @@ | ||
| 7 | 7 | * `?desktop_mode_classic=1`). Re-stamps the flag onto every |
| 8 | 8 | * same-origin `/wp-admin/` `<a href>` and `<form action>` so |
| 9 | 9 | * navigations within the tab stay classic — server-side |
| 10 | 10 | * redirects are handled by |
| 11 | - * `desktop_mode_classic_preserve_redirect()` in routing.php. | |
| 11 | + * `openstation_classic_preserve_redirect()` in routing.php. | |
| 12 | 12 | * |
| 13 | 13 | * Extracted from `render.php` during the architecture-0.8.1 PHP |
| 14 | 14 | * slicing (phase 6). |
| 15 | 15 | * |
| 16 | - * @package Desktop_Mode | |
| 16 | + * @package OpenStation | |
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | defined( 'ABSPATH' ) || exit; |
| 20 | 20 | |
| @@ -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 desktop_mode_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 |
| @@ -34,14 +35,14 @@ | ||
| 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 |
| 36 | 37 | * don't break "open in new tab" or mailto links. |
| 37 | 38 | */ |
| 38 | -function desktop_mode_classic_link_interceptor() { | |
| 39 | - if ( ! desktop_mode_is_classic_request() ) { | |
| 39 | +function openstation_classic_link_interceptor() { | |
| 40 | + if ( ! openstation_is_classic_request() ) { | |
| 40 | 41 | return; |
| 41 | 42 | } |
| 42 | 43 | |
| 43 | - $flag_literal = wp_json_encode( DESKTOP_MODE_CLASSIC_FLAG ); | |
| 44 | + $flag_literal = wp_json_encode( OPENSTATION_CLASSIC_FLAG ); | |
| 44 | 45 | |
| 45 | 46 | $js = " |
| 46 | 47 | ( function () { |
| 47 | 48 | var FLAG = {$flag_literal}; |
| @@ -105,10 +106,26 @@ | ||
| 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 ); |
| 113 | 130 | } |
| 114 | -add_action( 'admin_footer', 'desktop_mode_classic_link_interceptor' ); | |
| 131 | +add_action( 'admin_footer', 'openstation_classic_link_interceptor' ); | |