← All changes
|
includes/my-wordpress/integrations/woocommerce.php
+46
-25
1.1.2
→
1.1.10
View file →
| @@ -1899,25 +1899,34 @@ | ||
| 1899 | 1899 | |
| 1900 | 1900 | /** |
| 1901 | 1901 | * Register the integration bundle. |
| 1902 | 1902 | * |
| 1903 | + * Cache-busted by `filemtime`, like the window bundle it rides along | |
| 1904 | + * with (see `openstation_my_wordpress_register_assets()`). The bundle | |
| 1905 | + * is fetched lazily by URL, so a `ver` that only moves on release | |
| 1906 | + * would let a browser's cached copy outlive builds within one — a | |
| 1907 | + * stale companion against a fresh WP Explorer bundle is a contract | |
| 1908 | + * drift no error message points at. | |
| 1909 | + * | |
| 1903 | 1910 | * @return void |
| 1904 | 1911 | */ |
| 1905 | 1912 | function openstation_my_wordpress_woo_register_assets() { |
| 1913 | + $js_path = OPENSTATION_DIR . 'assets/js/my-wordpress-woocommerce' . openstation_asset_suffix() . '.js'; | |
| 1906 | 1914 | wp_register_script( |
| 1907 | 1915 | 'os-my-wordpress-woocommerce', |
| 1908 | - OPENSTATION_URL . 'assets/js/my-wordpress-woocommerce' . ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ) . '.js', | |
| 1916 | + OPENSTATION_URL . 'assets/js/my-wordpress-woocommerce' . openstation_asset_suffix() . '.js', | |
| 1909 | 1917 | array( 'wp-hooks' ), |
| 1910 | - OPENSTATION_VERSION, | |
| 1918 | + file_exists( $js_path ) ? (string) filemtime( $js_path ) : OPENSTATION_VERSION, | |
| 1911 | 1919 | true |
| 1912 | 1920 | ); |
| 1913 | 1921 | wp_set_script_translations( 'os-my-wordpress-woocommerce', 'desktop-mode' ); |
| 1914 | 1922 | |
| 1923 | + $css_path = OPENSTATION_DIR . 'assets/css/my-wordpress-woocommerce.css'; | |
| 1915 | 1924 | wp_register_style( |
| 1916 | 1925 | 'os-my-wordpress-woocommerce', |
| 1917 | 1926 | OPENSTATION_URL . 'assets/css/my-wordpress-woocommerce.css', |
| 1918 | 1927 | array( 'desktop-mode-my-wordpress' ), |
| 1919 | - OPENSTATION_VERSION | |
| 1928 | + file_exists( $css_path ) ? (string) filemtime( $css_path ) : OPENSTATION_VERSION | |
| 1920 | 1929 | ); |
| 1921 | 1930 | } |
| 1922 | 1931 | add_action( 'init', 'openstation_my_wordpress_woo_register_assets', 5 ); |
| 1923 | 1932 | |
| @@ -1923,16 +1932,20 @@ | ||
| 1923 | 1932 | |
| 1924 | 1933 | /** |
| 1925 | 1934 | * Attach the integration's config to its script handle. |
| 1926 | 1935 | * |
| 1927 | - * The bundle itself is NOT enqueued here, and that is the point. It | |
| 1928 | - * subscribes to the WP Explorer window's `preview-extras` / | |
| 1929 | - * `group-extras` actions, so it has to be in the tab before that | |
| 1930 | - * window's bundle paints — but not one moment sooner. It travels as | |
| 1931 | - * a companion of `desktop-mode-my-wordpress` (see the `scripts` arg | |
| 1932 | - * on that window's registration), which means the shell loads it | |
| 1933 | - * when the window first opens and a merchant who never opens WP | |
| 1934 | - * Explorer never downloads it at all. | |
| 1936 | + * NOTHING is enqueued here, and that is the point. The bundle | |
| 1937 | + * subscribes to the WP Explorer app's `preview-extras` / | |
| 1938 | + * `group-extras` actions, so it has to be in the tab before the app's | |
| 1939 | + * client view paints — but not one moment sooner. It travels as a | |
| 1940 | + * companion of the app window (see | |
| 1941 | + * `openstation_my_wordpress_woo_app_window_args()` below), which | |
| 1942 | + * means the shell loads it when the window first opens and a merchant | |
| 1943 | + * who never opens the explorer never downloads it at all. The | |
| 1944 | + * stylesheet travels the same way (the `styles` arg): every selector | |
| 1945 | + * in it is scoped to surfaces inside the explorer or the Customer | |
| 1946 | + * window, so on any document not showing those — | |
| 1947 | + * it was pure parse weight. | |
| 1935 | 1948 | * |
| 1936 | 1949 | * Only for users who can open the site window on a store — everyone |
| 1937 | 1950 | * else pays nothing. |
| 1938 | 1951 | * |
| @@ -1954,12 +1967,8 @@ | ||
| 1954 | 1967 | if ( ! openstation_my_wordpress_user_can_use() ) { |
| 1955 | 1968 | return; |
| 1956 | 1969 | } |
| 1957 | 1970 | |
| 1958 | - // The stylesheet stays eager: it is a few KB, it has no parse | |
| 1959 | - // cost worth deferring, and the window's own CSS is enqueued the | |
| 1960 | - // same way. | |
| 1961 | - wp_enqueue_style( 'os-my-wordpress-woocommerce' ); | |
| 1962 | 1971 | wp_add_inline_script( |
| 1963 | 1972 | 'os-my-wordpress-woocommerce', |
| 1964 | 1973 | sprintf( |
| 1965 | 1974 | 'window.openStationWooConfig=%s;', |
| @@ -1993,21 +2002,29 @@ | ||
| 1993 | 2002 | } |
| 1994 | 2003 | add_action( 'admin_enqueue_scripts', 'openstation_my_wordpress_woo_enqueue', 5 ); |
| 1995 | 2004 | |
| 1996 | 2005 | /** |
| 1997 | - * Attach the bundle to the WP Explorer window as a companion script. | |
| 2006 | + * Attach the bundle and stylesheet to the WP Explorer app. | |
| 1998 | 2007 | * |
| 1999 | - * `scripts` handles load in order immediately before the window's own | |
| 2000 | - * `script`, so the integration is listening to `preview-extras` / | |
| 2001 | - * `group-extras` by the time the window bundle fires them — the same | |
| 2002 | - * guarantee the old boot-time enqueue gave, at the cost of nothing | |
| 2003 | - * until the window opens. | |
| 2008 | + * The app fires the `os.my-wordpress.*` seams this bundle subscribes | |
| 2009 | + * to (`preview-extras`, `group-extras`, `list-tile`, the banding and | |
| 2010 | + * user filters), and its rows carry the `openstation_woo` / | |
| 2011 | + * `openstation_woo_customer` facts. `scripts` handles load in order | |
| 2012 | + * immediately before the window's own script, so the integration is | |
| 2013 | + * listening by the time the app's client view fires the seams — as a | |
| 2014 | + * first-open companion, costing nothing until the window opens. The | |
| 2015 | + * config blob rides the handle (see | |
| 2016 | + * `openstation_my_wordpress_woo_enqueue()`), so it arrives with the | |
| 2017 | + * bundle. The `styles` handle keeps its `wp_register_style` | |
| 2018 | + * dependency on the shared explorer sheet, so its equal-specificity | |
| 2019 | + * overrides (the ribbon and panel chrome) still win by source order. | |
| 2004 | 2020 | * |
| 2005 | - * @param array $window_args Args passed to `openstation_register_window()`. | |
| 2021 | + * @param array $window_args Args passed to `openstation_register_window()`. | |
| 2022 | + * @param string $app_id App id. | |
| 2006 | 2023 | * @return array |
| 2007 | 2024 | */ |
| 2008 | -function openstation_my_wordpress_woo_window_args( $window_args ) { | |
| 2009 | - if ( ! is_array( $window_args ) || ! openstation_my_wordpress_woo_active() ) { | |
| 2025 | +function openstation_my_wordpress_woo_app_window_args( $window_args, $app_id ) { | |
| 2026 | + if ( 'my-wordpress' !== (string) $app_id || ! is_array( $window_args ) || ! openstation_my_wordpress_woo_active() ) { | |
| 2010 | 2027 | return $window_args; |
| 2011 | 2028 | } |
| 2012 | 2029 | |
| 2013 | 2030 | $scripts = isset( $window_args['scripts'] ) ? (array) $window_args['scripts'] : array(); |
| @@ -2012,9 +2029,13 @@ | ||
| 2012 | 2029 | |
| 2013 | 2030 | $scripts = isset( $window_args['scripts'] ) ? (array) $window_args['scripts'] : array(); |
| 2014 | 2031 | $scripts[] = 'os-my-wordpress-woocommerce'; |
| 2015 | 2032 | |
| 2033 | + $styles = isset( $window_args['styles'] ) ? (array) $window_args['styles'] : array(); | |
| 2034 | + $styles[] = 'os-my-wordpress-woocommerce'; | |
| 2035 | + | |
| 2016 | 2036 | $window_args['scripts'] = $scripts; |
| 2037 | + $window_args['styles'] = $styles; | |
| 2017 | 2038 | |
| 2018 | 2039 | return $window_args; |
| 2019 | 2040 | } |
| 2020 | -add_filter( 'openstation_my_wordpress_window_args', 'openstation_my_wordpress_woo_window_args' ); | |
| 2041 | +add_filter( 'openstation_app_window_args', 'openstation_my_wordpress_woo_app_window_args', 10, 2 ); | |