| @@ -60,11 +60,9 @@ | ||
| 60 | 60 | * |
| 61 | 61 | * @return bool |
| 62 | 62 | */ |
| 63 | 63 | function openstation_desktop_theme_request_is_themable() { |
| 64 | - return openstation_is_enabled() | |
| 65 | - && ! openstation_is_chromeless_request() | |
| 66 | - && ! openstation_is_classic_request(); | |
| 64 | + return openstation_is_shell_request(); | |
| 67 | 65 | } |
| 68 | 66 | |
| 69 | 67 | /** |
| 70 | 68 | * Enqueue the active theme's compiled stylesheet. |
| @@ -135,9 +133,41 @@ | ||
| 135 | 133 | $slug = openstation_active_desktop_theme_slug(); |
| 136 | 134 | if ( '' === $slug ) { |
| 137 | 135 | return $classes; |
| 138 | 136 | } |
| 139 | - return trim( $classes . ' os-desktop-theme-' . $slug ); | |
| 137 | + $classes .= ' os-desktop-theme-' . $slug; | |
| 138 | + | |
| 139 | + // Uploads win a slug collision, the same precedence as the payload. | |
| 140 | + $entry = openstation_desktop_theme_get( $slug ); | |
| 141 | + if ( null === $entry ) { | |
| 142 | + $entry = openstation_desktop_theme_registry( $slug ); | |
| 143 | + } | |
| 144 | + if ( is_array( $entry ) && ! empty( $entry['manifest'] ) && openstation_desktop_theme_manifest_draws_toolbar( $entry['manifest'] ) ) { | |
| 145 | + $classes .= ' os-toolbar-themed'; | |
| 146 | + } | |
| 147 | + return trim( $classes ); | |
| 148 | +} | |
| 149 | + | |
| 150 | +/** | |
| 151 | + * Whether a theme draws the WordPress toolbar. | |
| 152 | + * | |
| 153 | + * The toolbar's colours belong to the user's admin colour scheme until | |
| 154 | + * a theme names an `--os-toolbar-*` token. Only then does the shell | |
| 155 | + * let the theme's values replace the scheme's (`os-toolbar-themed`). | |
| 156 | + * | |
| 157 | + * @param array $manifest Sanitized manifest. | |
| 158 | + * @return bool | |
| 159 | + */ | |
| 160 | +function openstation_desktop_theme_manifest_draws_toolbar( $manifest ) { | |
| 161 | + if ( empty( $manifest['tokens'] ) || ! is_array( $manifest['tokens'] ) ) { | |
| 162 | + return false; | |
| 163 | + } | |
| 164 | + foreach ( array_keys( $manifest['tokens'] ) as $name ) { | |
| 165 | + if ( 0 === strpos( (string) $name, '--os-toolbar-' ) ) { | |
| 166 | + return true; | |
| 167 | + } | |
| 168 | + } | |
| 169 | + return false; | |
| 140 | 170 | } |
| 141 | 171 | add_filter( 'admin_body_class', 'openstation_desktop_theme_body_class', 20 ); |
| 142 | 172 | |
| 143 | 173 | /** |