| @@ -1,7 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | /** |
| 3 | - * Desktop Mode — Desktop-theme enqueue + body class + shell config. | |
| 3 | + * OpenStation — Desktop-theme enqueue + body class + shell config. | |
| 4 | 4 | * |
| 5 | 5 | * **Zero cost when no theme is active.** Every entry point here |
| 6 | 6 | * early-returns on an empty selection before it reads an option, |
| 7 | 7 | * touches the filesystem, or registers a handle. A site whose users |
| @@ -7,15 +7,15 @@ | ||
| 7 | 7 | * touches the filesystem, or registers a handle. A site whose users |
| 8 | 8 | * all sit on "System default" pays one user-meta read that the OS |
| 9 | 9 | * settings layer was doing anyway. |
| 10 | 10 | * |
| 11 | - * @package WPDesktopMode | |
| 11 | + * @package OpenStation | |
| 12 | 12 | */ |
| 13 | 13 | |
| 14 | 14 | defined( 'ABSPATH' ) || exit; |
| 15 | 15 | |
| 16 | 16 | /** Style handle for the compiled desktop-theme stylesheet. */ |
| 17 | -const DESKTOP_MODE_DESKTOP_THEME_STYLE_HANDLE = 'desktop-mode-desktop-theme'; | |
| 17 | +const OPENSTATION_DESKTOP_THEME_STYLE_HANDLE = 'os-desktop-theme'; | |
| 18 | 18 | |
| 19 | 19 | /** |
| 20 | 20 | * Resolve the desktop theme a user has selected, if it still exists. |
| 21 | 21 | * |
| @@ -25,9 +25,9 @@ | ||
| 25 | 25 | * |
| 26 | 26 | * @param int $user_id User id. Defaults to the current user. |
| 27 | 27 | * @return string Slug, or `''` for the system default. |
| 28 | 28 | */ |
| 29 | -function desktop_mode_active_desktop_theme_slug( $user_id = 0 ) { | |
| 29 | +function openstation_active_desktop_theme_slug( $user_id = 0 ) { | |
| 30 | 30 | $user_id = (int) $user_id; |
| 31 | 31 | if ( $user_id <= 0 ) { |
| 32 | 32 | $user_id = get_current_user_id(); |
| 33 | 33 | } |
| @@ -34,9 +34,9 @@ | ||
| 34 | 34 | if ( $user_id <= 0 ) { |
| 35 | 35 | return ''; |
| 36 | 36 | } |
| 37 | 37 | |
| 38 | - $settings = desktop_mode_get_os_settings( $user_id ); | |
| 38 | + $settings = openstation_get_os_settings( $user_id ); | |
| 39 | 39 | $slug = isset( $settings['desktopTheme'] ) ? sanitize_key( (string) $settings['desktopTheme'] ) : ''; |
| 40 | 40 | if ( '' === $slug ) { |
| 41 | 41 | return ''; |
| 42 | 42 | } |
| @@ -43,12 +43,12 @@ | ||
| 43 | 43 | |
| 44 | 44 | // Existence check across both sources. This is the safety net |
| 45 | 45 | // that lets the os-settings sanitizer stay a cheap pattern check |
| 46 | 46 | // instead of loading the themes option on every settings write. |
| 47 | - if ( null !== desktop_mode_desktop_theme_get( $slug ) ) { | |
| 47 | + if ( null !== openstation_desktop_theme_get( $slug ) ) { | |
| 48 | 48 | return $slug; |
| 49 | 49 | } |
| 50 | - if ( null !== desktop_mode_desktop_theme_registry( $slug ) ) { | |
| 50 | + if ( null !== openstation_desktop_theme_registry( $slug ) ) { | |
| 51 | 51 | return $slug; |
| 52 | 52 | } |
| 53 | 53 | return ''; |
| 54 | 54 | } |
| @@ -59,28 +59,26 @@ | ||
| 59 | 59 | * @internal |
| 60 | 60 | * |
| 61 | 61 | * @return bool |
| 62 | 62 | */ |
| 63 | -function desktop_mode_desktop_theme_request_is_themable() { | |
| 64 | - return desktop_mode_is_enabled() | |
| 65 | - && ! desktop_mode_is_chromeless_request() | |
| 66 | - && ! desktop_mode_is_classic_request(); | |
| 63 | +function openstation_desktop_theme_request_is_themable() { | |
| 64 | + return openstation_is_shell_request(); | |
| 67 | 65 | } |
| 68 | 66 | |
| 69 | 67 | /** |
| 70 | 68 | * Enqueue the active theme's compiled stylesheet. |
| 71 | 69 | * |
| 72 | - * The `desktop-mode-variables` dependency is load-bearing, not | |
| 70 | + * The `os-variables` dependency is load-bearing, not | |
| 73 | 71 | * decoration: the compiled selectors weigh the same as the |
| 74 | 72 | * per-admin-color-scheme blocks in `variables.css`, and a |
| 75 | 73 | * specificity tie is settled by source order. Drop the dependency |
| 76 | 74 | * and a themed token silently loses to the color scheme. |
| 77 | 75 | */ |
| 78 | -function desktop_mode_enqueue_desktop_theme_style() { | |
| 79 | - if ( ! desktop_mode_desktop_theme_request_is_themable() ) { | |
| 76 | +function openstation_enqueue_desktop_theme_style() { | |
| 77 | + if ( ! openstation_desktop_theme_request_is_themable() ) { | |
| 80 | 78 | return; |
| 81 | 79 | } |
| 82 | - $slug = desktop_mode_active_desktop_theme_slug(); | |
| 80 | + $slug = openstation_active_desktop_theme_slug(); | |
| 83 | 81 | if ( '' === $slug ) { |
| 84 | 82 | // The whole point: nothing registered, nothing enqueued, no |
| 85 | 83 | // extra request, no extra bytes. |
| 86 | 84 | return; |
| @@ -85,43 +83,43 @@ | ||
| 85 | 83 | // extra request, no extra bytes. |
| 86 | 84 | return; |
| 87 | 85 | } |
| 88 | 86 | |
| 89 | - $uploaded = desktop_mode_desktop_theme_get( $slug ); | |
| 87 | + $uploaded = openstation_desktop_theme_get( $slug ); | |
| 90 | 88 | if ( is_array( $uploaded ) ) { |
| 91 | - $version = isset( $uploaded['installedAt'] ) ? (string) (int) $uploaded['installedAt'] : DESKTOP_MODE_VERSION; | |
| 89 | + $version = isset( $uploaded['installedAt'] ) ? (string) (int) $uploaded['installedAt'] : OPENSTATION_VERSION; | |
| 92 | 90 | wp_enqueue_style( |
| 93 | - DESKTOP_MODE_DESKTOP_THEME_STYLE_HANDLE, | |
| 94 | - desktop_mode_desktop_themes_url( $slug ) . '/theme.css', | |
| 95 | - array( 'desktop-mode-variables' ), | |
| 91 | + OPENSTATION_DESKTOP_THEME_STYLE_HANDLE, | |
| 92 | + openstation_desktop_themes_url( $slug ) . '/theme.css', | |
| 93 | + array( 'os-variables' ), | |
| 96 | 94 | $version |
| 97 | 95 | ); |
| 98 | 96 | return; |
| 99 | 97 | } |
| 100 | 98 | |
| 101 | - $code = desktop_mode_desktop_theme_registry( $slug ); | |
| 99 | + $code = openstation_desktop_theme_registry( $slug ); | |
| 102 | 100 | if ( is_array( $code ) && ! empty( $code['cssText'] ) ) { |
| 103 | 101 | // Code themes have no file to link. Register a src-less stub |
| 104 | 102 | // so `wp_add_inline_style()` has a handle to hang off, and |
| 105 | 103 | // keep the same dependency so print order is identical. |
| 106 | 104 | wp_register_style( |
| 107 | - DESKTOP_MODE_DESKTOP_THEME_STYLE_HANDLE, | |
| 105 | + OPENSTATION_DESKTOP_THEME_STYLE_HANDLE, | |
| 108 | 106 | false, |
| 109 | - array( 'desktop-mode-variables' ), | |
| 110 | - DESKTOP_MODE_VERSION | |
| 107 | + array( 'os-variables' ), | |
| 108 | + OPENSTATION_VERSION | |
| 111 | 109 | ); |
| 112 | - wp_enqueue_style( DESKTOP_MODE_DESKTOP_THEME_STYLE_HANDLE ); | |
| 113 | - wp_add_inline_style( DESKTOP_MODE_DESKTOP_THEME_STYLE_HANDLE, (string) $code['cssText'] ); | |
| 110 | + wp_enqueue_style( OPENSTATION_DESKTOP_THEME_STYLE_HANDLE ); | |
| 111 | + wp_add_inline_style( OPENSTATION_DESKTOP_THEME_STYLE_HANDLE, (string) $code['cssText'] ); | |
| 114 | 112 | } |
| 115 | 113 | } |
| 116 | -add_action( 'admin_enqueue_scripts', 'desktop_mode_enqueue_desktop_theme_style', 20 ); | |
| 114 | +add_action( 'admin_enqueue_scripts', 'openstation_enqueue_desktop_theme_style', 20 ); | |
| 117 | 115 | |
| 118 | 116 | /** |
| 119 | - * Add `desktop-mode-desktop-theme-<slug>` to the admin body classes. | |
| 117 | + * Add `os-desktop-theme-<slug>` to the admin body classes. | |
| 120 | 118 | * |
| 121 | 119 | * The compiled stylesheet scopes to this class as well as to the |
| 122 | 120 | * shell root, because toasts / dialogs / tooltips / context menus |
| 123 | - * mount on `document.body`, outside `#desktop-mode-shell`. | |
| 121 | + * mount on `document.body`, outside `#os-shell`. | |
| 124 | 122 | * |
| 125 | 123 | * `admin_body_class` is a STRING filter — concatenate, never |
| 126 | 124 | * array-push. |
| 127 | 125 | * |
| @@ -127,24 +125,24 @@ | ||
| 127 | 125 | * |
| 128 | 126 | * @param string $classes Space-separated class list. |
| 129 | 127 | * @return string |
| 130 | 128 | */ |
| 131 | -function desktop_mode_desktop_theme_body_class( $classes ) { | |
| 132 | - if ( ! desktop_mode_desktop_theme_request_is_themable() ) { | |
| 129 | +function openstation_desktop_theme_body_class( $classes ) { | |
| 130 | + if ( ! openstation_desktop_theme_request_is_themable() ) { | |
| 133 | 131 | return $classes; |
| 134 | 132 | } |
| 135 | - $slug = desktop_mode_active_desktop_theme_slug(); | |
| 133 | + $slug = openstation_active_desktop_theme_slug(); | |
| 136 | 134 | if ( '' === $slug ) { |
| 137 | 135 | return $classes; |
| 138 | 136 | } |
| 139 | - return trim( $classes . ' desktop-mode-desktop-theme-' . $slug ); | |
| 137 | + return trim( $classes . ' os-desktop-theme-' . $slug ); | |
| 140 | 138 | } |
| 141 | -add_filter( 'admin_body_class', 'desktop_mode_desktop_theme_body_class', 20 ); | |
| 139 | +add_filter( 'admin_body_class', 'openstation_desktop_theme_body_class', 20 ); | |
| 142 | 140 | |
| 143 | 141 | /** |
| 144 | 142 | * Inject the desktop-theme bits of the shell config. |
| 145 | 143 | * |
| 146 | - * Uses the public `desktop_mode_shell_config` filter rather than | |
| 144 | + * Uses the public `openstation_shell_config` filter rather than | |
| 147 | 145 | * editing the config literal in `includes/render/assets.php`, the |
| 148 | 146 | * same way the stored-files module contributes `desktopStorage`. |
| 149 | 147 | * |
| 150 | 148 | * @param array $config Shell config. |
| @@ -149,10 +147,10 @@ | ||
| 149 | 147 | * |
| 150 | 148 | * @param array $config Shell config. |
| 151 | 149 | * @return array |
| 152 | 150 | */ |
| 153 | -function desktop_mode_desktop_theme_inject_shell_config( $config ) { | |
| 154 | - $config['canManageDesktopThemes'] = current_user_can( desktop_mode_desktop_theme_upload_capability() ); | |
| 151 | +function openstation_desktop_theme_inject_shell_config( $config ) { | |
| 152 | + $config['canManageDesktopThemes'] = current_user_can( openstation_desktop_theme_upload_capability() ); | |
| 155 | 153 | $config['desktopThemesUrl'] = esc_url_raw( rest_url( 'desktop-mode/v1/desktop-themes' ) ); |
| 156 | 154 | return $config; |
| 157 | 155 | } |
| 158 | -add_filter( 'desktop_mode_shell_config', 'desktop_mode_desktop_theme_inject_shell_config', 20 ); | |
| 156 | +add_filter( 'openstation_shell_config', 'openstation_desktop_theme_inject_shell_config', 20 ); | |