| @@ -38,8 +38,17 @@ | ||
| 38 | 38 | $enabled = ! empty( $_POST['enabled'] ) && '1' === $_POST['enabled'] ? '1' : ''; |
| 39 | 39 | |
| 40 | 40 | update_user_meta( get_current_user_id(), 'desktop_mode_mode', $enabled ); |
| 41 | 41 | |
| 42 | + // The first-run stamps and the enable / disable actions. One helper | |
| 43 | + // shared with the portal's auto-enable so the two writers cannot | |
| 44 | + // drift — see `includes/first-run/stamps.php`. | |
| 45 | + if ( '1' === $enabled ) { | |
| 46 | + openstation_record_user_enabled( get_current_user_id() ); | |
| 47 | + } else { | |
| 48 | + openstation_record_user_disabled( get_current_user_id() ); | |
| 49 | + } | |
| 50 | + | |
| 42 | 51 | // Tell the client where to land. |
| 43 | 52 | // |
| 44 | 53 | // Enabling from classic admin: land on the shell screen with the |
| 45 | 54 | // Dashboard as the page it opens first. The explicit "Switch to |
| @@ -54,11 +63,17 @@ | ||
| 54 | 63 | // Disabling from the shell jumps to a plain admin URL — NOT the |
| 55 | 64 | // portal, which would auto-re-enable the mode via the |
| 56 | 65 | // `openstation_portal_auto_enable` filter and trap the user in a |
| 57 | 66 | // loop. |
| 58 | - $redirect = '1' === $enabled | |
| 59 | - ? openstation_shell_url( admin_url( 'index.php' ) ) | |
| 60 | - : admin_url(); | |
| 67 | + // Which admin to land in. The toggle reports its own context, since | |
| 68 | + // `is_network_admin()` is false on every `admin-ajax.php` request, | |
| 69 | + // and we confirm the capability before honouring it — a client | |
| 70 | + // cannot talk us into a screen the user can't open. | |
| 71 | + $in_network = ! empty( $_POST['network'] ) && current_user_can( 'manage_network' ); | |
| 72 | + $admin = $in_network ? network_admin_url() : admin_url(); | |
| 73 | + $redirect = '1' === $enabled | |
| 74 | + ? openstation_shell_url( $admin . 'index.php', false, $in_network ) | |
| 75 | + : $admin; | |
| 61 | 76 | |
| 62 | 77 | wp_send_json_success( |
| 63 | 78 | array( |
| 64 | 79 | 'enabled' => $enabled, |