PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.0.0
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.0.0
1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 0.8.7 All 34 releases
desktop-mode / includes / render / body-classes.php

body-classes.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.0.0, at includes/render/body-classes.php

87 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — Body class tagging.
4 *
5 * Adds `os-active` / `os-chromeless` to the
6 * admin body class so the shell CSS and the chromeless overrides
7 * stylesheet can key off it, plus `os-admin-bar-<mode>` for
8 * the admin-bar presentation preference. Per-request
9 * `?desktop_mode_classic=1` suppresses them for the detached-tab
10 * workflow.
11 *
12 * Extracted from the 2,525-LOC `render.php` during the
13 * architecture-0.8.1 PHP slicing (phase 6).
14 *
15 * @package OpenStation
16 */
17
18 defined( 'ABSPATH' ) || exit;
19
20 /**
21 * Adds body classes for OpenStation and chromeless iframes.
22 *
23 * The classes anchor all CSS in the shell and chromeless overrides
24 * stylesheets — `.os-active` hides classic chrome and reveals
25 * the shell, `.os-chromeless` reshapes the page inside iframes.
26 *
27 * @param string $classes Space-separated CSS class string.
28 * @return string
29 */
30 function openstation_admin_body_classes( $classes ) {
31 if ( openstation_is_chromeless_request() ) {
32 return ltrim( $classes . ' os-chromeless' );
33 }
34
35 // Per-request classic override: don't tag the body as desktop-active so
36 // the classic chrome isn't hidden by CSS for this one tab.
37 if ( openstation_is_classic_request() ) {
38 return $classes;
39 }
40
41 if ( openstation_is_enabled() ) {
42 return ltrim(
43 $classes . ' os-active os-admin-bar-'
44 . openstation_get_admin_bar_mode()
45 );
46 }
47
48 return $classes;
49 }
50 add_filter( 'admin_body_class', 'openstation_admin_body_classes' );
51
52 /**
53 * Resolves the current user's admin-bar presentation mode.
54 *
55 * Emitted as a `os-admin-bar-<mode>` body class so the very
56 * first paint already has the right chrome — the shell's JS apply pass
57 * re-writes the same class on every settings change, but it runs after
58 * the admin bar has painted, which would flash a bar the user asked to
59 * hide.
60 *
61 * @return string One of `static`, `dynamic`, `hidden`.
62 */
63 function openstation_get_admin_bar_mode() {
64 $settings = openstation_get_os_settings( get_current_user_id() );
65 $mode = isset( $settings['adminBarMode'] ) ? (string) $settings['adminBarMode'] : 'static';
66
67 /**
68 * Filters the admin-bar presentation mode for the current request.
69 *
70 * Lets a plugin pin the mode regardless of the user's own OS
71 * Settings pick — forcing `static` for users who would otherwise
72 * lose their way out of the shell, say, or `hidden` on a kiosk.
73 *
74 * @param string $mode One of `static`, `dynamic`, `hidden`.
75 */
76 $mode = apply_filters( 'openstation_admin_bar_mode', $mode );
77
78 // Fails closed, and deliberately without a `(string)` cast: a
79 // filter returning an array would make that cast emit an
80 // "Array to string conversion" warning on the way to failing
81 // anyway. `static` is the safe landing — it is the only mode
82 // that can't hide the user's way out of the shell.
83 return is_string( $mode ) && in_array( $mode, OPENSTATION_OS_SETTINGS_ADMIN_BAR_MODES, true )
84 ? $mode
85 : 'static';
86 }
87