| 1 |
<?php |
| 2 |
/** |
| 3 |
* OpenStation — My WordPress: asset registration. |
| 4 |
* |
| 5 |
* Registers the bundle script + CSS handles. The bundle is lazy-loaded |
| 6 |
* by the native-window sync the first time the My WordPress window |
| 7 |
* opens, the same as the recycle-bin and posts-window modules. |
| 8 |
* |
| 9 |
* @package OpenStation |
| 10 |
*/ |
| 11 |
|
| 12 |
defined( 'ABSPATH' ) || exit; |
| 13 |
|
| 14 |
/** |
| 15 |
* Register My WordPress CSS and JS handles. |
| 16 |
*/ |
| 17 |
function openstation_my_wordpress_register_assets() { |
| 18 |
$version = OPENSTATION_VERSION; |
| 19 |
$suffix = openstation_asset_suffix(); |
| 20 |
|
| 21 |
/* |
| 22 |
* `os-files` is a real dependency, not decoration. Every tile in |
| 23 |
* this window is an `<os-tile>` wearing the canonical |
| 24 |
* `.os-file-tile` chrome that `desktop-files.css` declares, and |
| 25 |
* this stylesheet overrides a handful of those declarations at |
| 26 |
* EQUAL specificity — most visibly `.os-my-wordpress__media-tile`, |
| 27 |
* which has to undo `position: absolute` + the fixed 88×104 box so |
| 28 |
* media thumbnails flow inside their CSS Grid. |
| 29 |
* |
| 30 |
* Equal specificity means source order decides, and source order is |
| 31 |
* not ours to assume: any handle depending on this one that is |
| 32 |
* enqueued before `openstation_enqueue_assets()` runs (the |
| 33 |
* WooCommerce integration enqueues its companion stylesheet at |
| 34 |
* `admin_enqueue_scripts` priority 5) pulls this file into |
| 35 |
* `WP_Dependencies::$to_do` ahead of `os-files`. The overrides then |
| 36 |
* lose, every media tile is absolutely positioned with no offsets, |
| 37 |
* and the whole grid stacks in one corner. |
| 38 |
* |
| 39 |
* Declaring the dependency makes the order a fact rather than a |
| 40 |
* coincidence. `Tests_OpenStation_TileStylesheetOrder` holds it. |
| 41 |
*/ |
| 42 |
$css_path = OPENSTATION_DIR . 'assets/css/my-wordpress.css'; |
| 43 |
wp_register_style( |
| 44 |
'desktop-mode-my-wordpress', |
| 45 |
OPENSTATION_URL . 'assets/css/my-wordpress.css', |
| 46 |
array( 'os-variables', 'dashicons', 'os-files' ), |
| 47 |
file_exists( $css_path ) ? (string) filemtime( $css_path ) : $version |
| 48 |
); |
| 49 |
|
| 50 |
$js_path = OPENSTATION_DIR . 'assets/js/my-wordpress' . $suffix . '.js'; |
| 51 |
wp_register_script( |
| 52 |
'desktop-mode-my-wordpress', |
| 53 |
OPENSTATION_URL . 'assets/js/my-wordpress' . $suffix . '.js', |
| 54 |
array( 'wp-i18n' ), |
| 55 |
file_exists( $js_path ) ? (string) filemtime( $js_path ) : $version, |
| 56 |
true |
| 57 |
); |
| 58 |
wp_set_script_translations( |
| 59 |
'desktop-mode-my-wordpress', |
| 60 |
'desktop-mode', |
| 61 |
OPENSTATION_DIR . 'languages' |
| 62 |
); |
| 63 |
} |
| 64 |
add_action( 'init', 'openstation_my_wordpress_register_assets', 5 ); |
| 65 |
|