PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.10
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.10
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
← All changes | includes/widgets/widget-starter.php +47 -39 0.9.81.1.10 View file →
@@ -1,17 +1,17 @@
1 1 <?php
2 2 /**
3 3 * =============================================================================
4 - * Desktop Mode — Starter Widget PHP registration
4 + * OpenStation — Starter Widget PHP registration
5 5 * =============================================================================
6 6 *
7 7 * WHAT THIS FILE DOES
8 8 * -------------------
9 - * This is the PHP side of a Desktop Mode widget. It has three jobs:
9 + * This is the PHP side of a OpenStation widget. It has three jobs:
10 10 *
11 11 * 1. Register the JS bundle and CSS with WordPress so they can be loaded.
12 12 * 2. Enqueue the CSS eagerly on shell pages (prevents flash of unstyled content).
13 - * 3. Announce the widget to Desktop Mode via desktop_mode_register_widget()
13 + * 3. Announce the widget to OpenStation via openstation_register_widget()
14 14 * so it appears in the widget picker.
15 15 *
16 16 * The PHP side does NOT contain any widget logic. All the rendering, data
17 17 * fetching, and interactivity lives in the JS file (index.ts). PHP just
@@ -21,9 +21,9 @@
21 21 * HOW TO USE THIS AS A TEMPLATE
22 22 * ------------------------------
23 23 * 1. Copy this file to includes/widgets/widget-my.php
24 24 * 2. Replace every "starter" in function names with your widget name
25 - * e.g. desktop_mode_register_starter_* → desktop_mode_register_my_*
25 + * e.g. openstation_register_starter_* → openstation_register_my_*
26 26 * 3. Replace "widget-starter" in asset filenames with "widget-my"
27 27 * 4. Replace 'desktop-mode/starter' with your widget id — must match
28 28 * the WIDGET_ID constant in your JS file exactly
29 29 * 5. Update label, description, icon, and size constraints
@@ -28,11 +28,11 @@
28 28 * the WIDGET_ID constant in your JS file exactly
29 29 * 5. Update label, description, icon, and size constraints
30 30 * 6. Add a require_once line for this file in desktop-mode.php
31 31 *
32 - * Requires: Desktop Mode 0.18.0+ (desktop_mode_register_widget).
32 + * Requires: OpenStation 0.18.0+ (openstation_register_widget).
33 33 *
34 - * @package WPDesktopMode
34 + * @package OpenStation
35 35 */
36 36
37 37 defined( 'ABSPATH' ) || exit;
38 38
@@ -62,42 +62,50 @@
62 62 *
63 63 * VERSION STRINGS
64 64 * Using filemtime() as the version means the browser cache is busted
65 65 * automatically whenever the file changes on disk — no manual version bumping.
66 - * Falls back to DESKTOP_MODE_VERSION if the file does not exist yet (e.g.
66 + * Falls back to OPENSTATION_VERSION if the file does not exist yet (e.g.
67 67 * during development before the first build).
68 68 */
69 -function desktop_mode_register_starter_widget_assets() {
70 - $suffix = desktop_mode_asset_suffix();
71 - $version = defined( 'DESKTOP_MODE_VERSION' ) ? DESKTOP_MODE_VERSION : '0';
69 +function openstation_register_starter_widget_assets() {
70 + $suffix = openstation_asset_suffix();
71 + $version = defined( 'OPENSTATION_VERSION' ) ? OPENSTATION_VERSION : '0';
72 72
73 - $js_path = DESKTOP_MODE_DIR . 'assets/js/widget-starter' . $suffix . '.js';
74 - $css_path = DESKTOP_MODE_DIR . 'assets/js/widget-starter' . $suffix . '.css';
73 + $js_path = OPENSTATION_DIR . 'assets/js/widget-starter' . $suffix . '.js';
74 + $css_path = OPENSTATION_DIR . 'assets/js/widget-starter' . $suffix . '.css';
75 75
76 76 wp_register_style(
77 - 'desktop-mode-starter-widget', // Handle name — referenced in wp_enqueue_style() below.
78 - DESKTOP_MODE_URL . 'assets/js/widget-starter' . $suffix . '.css',
77 + 'os-starter-widget', // Handle name — referenced in wp_enqueue_style() below.
78 + OPENSTATION_URL . 'assets/js/widget-starter' . $suffix . '.css',
79 79 array(), // No CSS dependencies.
80 80 file_exists( $css_path ) ? (string) filemtime( $css_path ) : $version
81 81 );
82 82
83 83 wp_register_script(
84 - 'desktop-mode-starter-widget', // Handle name — passed as 'script' to desktop_mode_register_widget().
85 - DESKTOP_MODE_URL . 'assets/js/widget-starter' . $suffix . '.js',
84 + 'os-starter-widget', // Handle name — passed as 'script' to openstation_register_widget().
85 + OPENSTATION_URL . 'assets/js/widget-starter' . $suffix . '.js',
86 86 array( 'wp-api-fetch' ), // List WordPress script handles your widget depends on.
87 - // 'wp-api-fetch' is available on every admin page and handles
88 - // REST nonces automatically. Remove it if your widget does
89 - // not make REST API calls.
87 + // Declare every WordPress package you use, and do not assume any
88 + // of them are already on the page. They used to be: Core's ⌘K
89 + // palette pulled the whole Gutenberg runtime onto every admin
90 + // screen, so `wp.apiFetch`, `wp.element` and friends happened to
91 + // be globals by the time any widget mounted. Deferring that
92 + // runtime to the first ⌘K took the accident away — on a fresh
93 + // boot they are undefined until the palette is opened, and a
94 + // widget that reached for one at mount threw. A declared
95 + // dependency is resolved by WordPress when the script is
96 + // enqueued, which is why this line is the fix and not a
97 + // workaround. See docs/migration-wp-package-globals.md.
90 98 file_exists( $js_path ) ? (string) filemtime( $js_path ) : $version,
91 99 true // Load in the footer — always true for widget scripts.
92 100 );
93 101 }
94 -add_action( 'init', 'desktop_mode_register_starter_widget_assets', 5 );
95 -// Priority 5 — must run before desktop_mode_register_starter_widget() at priority 6
102 +add_action( 'init', 'openstation_register_starter_widget_assets', 5 );
103 +// Priority 5 — must run before openstation_register_starter_widget() at priority 6
96 104 // so the script handle exists when register_widget() looks it up.
97 105
98 106 /**
99 - * Eagerly enqueue the CSS on Desktop Mode shell pages.
107 + * Eagerly enqueue the CSS on OpenStation shell pages.
100 108 *
101 109 * The JS loads lazily (server-sync handles it). The CSS must load early
102 110 * so it is in the DOM before the widget's first render — otherwise there
103 111 * is a visible flash of unstyled content while the browser fetches the
@@ -103,27 +111,27 @@
103 111 * is a visible flash of unstyled content while the browser fetches the
104 112 * stylesheet after mount.
105 113 *
106 114 * The two guards below prevent the stylesheet loading on pages where
107 - * Desktop Mode is not active:
108 - * desktop_mode_is_enabled() — user has Desktop Mode turned on
109 - * desktop_mode_is_chromeless_request() — not an iframe content request
115 + * OpenStation is not active:
116 + * openstation_is_enabled() — user has OpenStation turned on
117 + * openstation_is_chromeless_request() — not an iframe content request
110 118 */
111 -function desktop_mode_enqueue_starter_widget_styles() {
112 - if ( function_exists( 'desktop_mode_is_enabled' ) && ! desktop_mode_is_enabled() ) {
119 +function openstation_enqueue_starter_widget_styles() {
120 + if ( function_exists( 'openstation_is_enabled' ) && ! openstation_is_enabled() ) {
113 121 return;
114 122 }
115 - if ( function_exists( 'desktop_mode_is_chromeless_request' ) && desktop_mode_is_chromeless_request() ) {
123 + if ( function_exists( 'openstation_is_chromeless_request' ) && openstation_is_chromeless_request() ) {
116 124 return;
117 125 }
118 - wp_enqueue_style( 'desktop-mode-starter-widget' );
126 + wp_enqueue_style( 'os-starter-widget' );
119 127 }
120 -add_action( 'admin_enqueue_scripts', 'desktop_mode_enqueue_starter_widget_styles', 20 );
128 +add_action( 'admin_enqueue_scripts', 'openstation_enqueue_starter_widget_styles', 20 );
121 129
122 130 /**
123 - * Announce the widget to Desktop Mode.
131 + * Announce the widget to OpenStation.
124 132 *
125 - * This call stores the widget's metadata in Desktop Mode's registry so
133 + * This call stores the widget's metadata in OpenStation's registry so
126 134 * it appears in the widget picker. The shell reads this registry at boot
127 135 * and on every session refresh — adding or removing a widget definition
128 136 * takes effect without a browser reload.
129 137 *
@@ -149,24 +157,24 @@
149 157 * capabilities array Optional. ALL listed capabilities must be held by the
150 158 * current user or the widget will not register for them.
151 159 * e.g. array( 'edit_posts', 'publish_posts' )
152 160 */
153 -function desktop_mode_register_starter_widget() {
154 - if ( ! function_exists( 'desktop_mode_register_widget' ) ) {
155 - // Desktop Mode is not active — bail gracefully.
161 +function openstation_register_starter_widget() {
162 + if ( ! function_exists( 'openstation_register_widget' ) ) {
163 + // OpenStation is not active — bail gracefully.
156 164 return;
157 165 }
158 166
159 - desktop_mode_register_widget(
167 + openstation_register_widget(
160 168 // First argument: widget id.
161 169 // Must exactly match the WIDGET_ID constant in your JS file and the
162 - // key used in window.desktopModeWidgets[ id ] at the bottom of index.ts.
170 + // key used in window.openStationWidgets[ id ] at the bottom of index.ts.
163 171 'desktop-mode/starter',
164 172 array(
165 173 'label' => __( 'Starter Widget', 'desktop-mode' ),
166 174 'description' => __( 'A skeleton widget — copy this to build your own.', 'desktop-mode' ),
167 175 'icon' => 'dashicons-welcome-widgets-menus',
168 - 'script' => 'desktop-mode-starter-widget',
176 + 'script' => 'os-starter-widget',
169 177 'movable' => true,
170 178 'resizable' => true,
171 179 'min_width' => 200,
172 180 'min_height' => 140,
@@ -174,6 +182,6 @@
174 182 'default_height' => 200,
175 183 )
176 184 );
177 185 }
178 -add_action( 'init', 'desktop_mode_register_starter_widget', 6 );
186 +add_action( 'init', 'openstation_register_starter_widget', 6 );
179 187 // Priority 6 — runs after the asset registration at priority 5.