| @@ -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,12 +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 | |
| 35 | - * @since 0.26.0 | |
| 34 | + * @package OpenStation | |
| 36 | 35 | */ |
| 37 | 36 | |
| 38 | 37 | defined( 'ABSPATH' ) || exit; |
| 39 | 38 | |
| @@ -63,42 +62,50 @@ | ||
| 63 | 62 | * |
| 64 | 63 | * VERSION STRINGS |
| 65 | 64 | * Using filemtime() as the version means the browser cache is busted |
| 66 | 65 | * automatically whenever the file changes on disk — no manual version bumping. |
| 67 | - * 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. | |
| 68 | 67 | * during development before the first build). |
| 69 | 68 | */ |
| 70 | -function desktop_mode_register_starter_widget_assets() { | |
| 71 | - $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; | |
| 72 | - $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'; | |
| 73 | 72 | |
| 74 | - $js_path = DESKTOP_MODE_DIR . 'assets/js/widget-starter' . $suffix . '.js'; | |
| 75 | - $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'; | |
| 76 | 75 | |
| 77 | 76 | wp_register_style( |
| 78 | - 'desktop-mode-starter-widget', // Handle name — referenced in wp_enqueue_style() below. | |
| 79 | - 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', | |
| 80 | 79 | array(), // No CSS dependencies. |
| 81 | 80 | file_exists( $css_path ) ? (string) filemtime( $css_path ) : $version |
| 82 | 81 | ); |
| 83 | 82 | |
| 84 | 83 | wp_register_script( |
| 85 | - 'desktop-mode-starter-widget', // Handle name — passed as 'script' to desktop_mode_register_widget(). | |
| 86 | - 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', | |
| 87 | 86 | array( 'wp-api-fetch' ), // List WordPress script handles your widget depends on. |
| 88 | - // 'wp-api-fetch' is available on every admin page and handles | |
| 89 | - // REST nonces automatically. Remove it if your widget does | |
| 90 | - // 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. | |
| 91 | 98 | file_exists( $js_path ) ? (string) filemtime( $js_path ) : $version, |
| 92 | 99 | true // Load in the footer — always true for widget scripts. |
| 93 | 100 | ); |
| 94 | 101 | } |
| 95 | -add_action( 'init', 'desktop_mode_register_starter_widget_assets', 5 ); | |
| 96 | -// 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 | |
| 97 | 104 | // so the script handle exists when register_widget() looks it up. |
| 98 | 105 | |
| 99 | 106 | /** |
| 100 | - * Eagerly enqueue the CSS on Desktop Mode shell pages. | |
| 107 | + * Eagerly enqueue the CSS on OpenStation shell pages. | |
| 101 | 108 | * |
| 102 | 109 | * The JS loads lazily (server-sync handles it). The CSS must load early |
| 103 | 110 | * so it is in the DOM before the widget's first render — otherwise there |
| 104 | 111 | * is a visible flash of unstyled content while the browser fetches the |
| @@ -104,27 +111,27 @@ | ||
| 104 | 111 | * is a visible flash of unstyled content while the browser fetches the |
| 105 | 112 | * stylesheet after mount. |
| 106 | 113 | * |
| 107 | 114 | * The two guards below prevent the stylesheet loading on pages where |
| 108 | - * Desktop Mode is not active: | |
| 109 | - * desktop_mode_is_enabled() — user has Desktop Mode turned on | |
| 110 | - * 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 | |
| 111 | 118 | */ |
| 112 | -function desktop_mode_enqueue_starter_widget_styles() { | |
| 113 | - 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() ) { | |
| 114 | 121 | return; |
| 115 | 122 | } |
| 116 | - 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() ) { | |
| 117 | 124 | return; |
| 118 | 125 | } |
| 119 | - wp_enqueue_style( 'desktop-mode-starter-widget' ); | |
| 126 | + wp_enqueue_style( 'os-starter-widget' ); | |
| 120 | 127 | } |
| 121 | -add_action( 'admin_enqueue_scripts', 'desktop_mode_enqueue_starter_widget_styles', 20 ); | |
| 128 | +add_action( 'admin_enqueue_scripts', 'openstation_enqueue_starter_widget_styles', 20 ); | |
| 122 | 129 | |
| 123 | 130 | /** |
| 124 | - * Announce the widget to Desktop Mode. | |
| 131 | + * Announce the widget to OpenStation. | |
| 125 | 132 | * |
| 126 | - * 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 | |
| 127 | 134 | * it appears in the widget picker. The shell reads this registry at boot |
| 128 | 135 | * and on every session refresh — adding or removing a widget definition |
| 129 | 136 | * takes effect without a browser reload. |
| 130 | 137 | * |
| @@ -150,24 +157,24 @@ | ||
| 150 | 157 | * capabilities array Optional. ALL listed capabilities must be held by the |
| 151 | 158 | * current user or the widget will not register for them. |
| 152 | 159 | * e.g. array( 'edit_posts', 'publish_posts' ) |
| 153 | 160 | */ |
| 154 | -function desktop_mode_register_starter_widget() { | |
| 155 | - if ( ! function_exists( 'desktop_mode_register_widget' ) ) { | |
| 156 | - // 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. | |
| 157 | 164 | return; |
| 158 | 165 | } |
| 159 | 166 | |
| 160 | - desktop_mode_register_widget( | |
| 167 | + openstation_register_widget( | |
| 161 | 168 | // First argument: widget id. |
| 162 | 169 | // Must exactly match the WIDGET_ID constant in your JS file and the |
| 163 | - // 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. | |
| 164 | 171 | 'desktop-mode/starter', |
| 165 | 172 | array( |
| 166 | 173 | 'label' => __( 'Starter Widget', 'desktop-mode' ), |
| 167 | 174 | 'description' => __( 'A skeleton widget — copy this to build your own.', 'desktop-mode' ), |
| 168 | 175 | 'icon' => 'dashicons-welcome-widgets-menus', |
| 169 | - 'script' => 'desktop-mode-starter-widget', | |
| 176 | + 'script' => 'os-starter-widget', | |
| 170 | 177 | 'movable' => true, |
| 171 | 178 | 'resizable' => true, |
| 172 | 179 | 'min_width' => 200, |
| 173 | 180 | 'min_height' => 140, |
| @@ -175,6 +182,6 @@ | ||
| 175 | 182 | 'default_height' => 200, |
| 176 | 183 | ) |
| 177 | 184 | ); |
| 178 | 185 | } |
| 179 | -add_action( 'init', 'desktop_mode_register_starter_widget', 6 ); | |
| 186 | +add_action( 'init', 'openstation_register_starter_widget', 6 ); | |
| 180 | 187 | // Priority 6 — runs after the asset registration at priority 5. |