PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.3
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.3
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 / my-wordpress / integrations / woocommerce-customer-window.php

woocommerce-customer-window.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.3, at includes/my-wordpress/integrations/woocommerce-customer-window.php

133 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — the Customer window.
4 *
5 * A native window that opens on one customer: who they are, what they
6 * are worth, what they bought, and where it ships. Double-clicking a
7 * customer tile lands here.
8 *
9 * It exists because the two things WordPress offers instead are both
10 * the wrong screen. The activity footprint answers "what has this
11 * person published", which for someone who came to buy a hat is an
12 * empty page. `user-edit.php` is a settings form — the place you go to
13 * change someone's role, not to understand them.
14 *
15 * Singleton and retargeting, like the profile window: the id is
16 * "the customer window", and *which* customer is an open-time param
17 * (`{ customerId }`). Params ride the session, so a reload brings the
18 * window back on the same person rather than on a default.
19 *
20 * Everything here is inert unless WooCommerce is active and the
21 * viewer may see customer money.
22 *
23 * @package OpenStation
24 */
25
26 defined( 'ABSPATH' ) || exit;
27
28 /**
29 * The window's template body.
30 *
31 * Deliberately a bare mount point rather than a markup skeleton: the
32 * whole surface is data-driven, so a static shell would only be a
33 * second place for the layout to live and drift.
34 *
35 * @return void
36 */
37 function openstation_my_wordpress_woo_customer_window_template() {
38 ob_start();
39 ?>
40 <div class="os-woo-customer-window" data-os-woo-customer-root>
41 <div class="os-woo-customer-window__loading" data-os-woo-customer-loading>
42 <os-spinner></os-spinner>
43 </div>
44 </div>
45 <?php
46 $html = (string) ob_get_clean();
47
48 /**
49 * Filter the Customer window's template HTML.
50 *
51 * Keep `data-os-woo-customer-root` intact — the render callback
52 * mounts into it.
53 *
54 * **Status: Experimental**
55 *
56 * @param string $html Default template HTML.
57 */
58 $filtered = (string) apply_filters( 'openstation_my_wordpress_woo_customer_window_template_html', $html );
59
60 if ( function_exists( 'openstation_kses_native_window_template' ) ) {
61 echo openstation_kses_native_window_template( $filtered ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- helper kses-escapes.
62 } else {
63 echo wp_kses( $filtered, wp_kses_allowed_html( 'post' ) );
64 }
65 }
66
67 /**
68 * Register the Customer window.
69 *
70 * `placement => 'none'`: it is never opened from a dock tile, because
71 * "the customer window" with no customer means nothing. It is always
72 * opened with a `customerId` param from a tile, a menu, or a session
73 * restore.
74 *
75 * @return void
76 */
77 function openstation_my_wordpress_woo_customer_window_register() {
78 if ( ! openstation_my_wordpress_woo_active() ) {
79 return;
80 }
81 if ( ! function_exists( 'openstation_register_window' ) ) {
82 return;
83 }
84 if ( true !== openstation_my_wordpress_woo_customers_permission() ) {
85 return;
86 }
87
88 $args = array(
89 'title' => __( 'Customer', 'desktop-mode' ),
90 'icon' => 'dashicons-businessperson',
91 'template' => 'openstation_my_wordpress_woo_customer_window_template',
92 // Rides the integration bundle that already ships the
93 // summary transport and the panel renderers — one more
94 // window, no second bundle.
95 'script' => 'os-my-wordpress-woocommerce',
96 // `styles` (companion), NOT `style`: a window's own style
97 // injects when the window REGISTERS, which for this one means
98 // every shell boot on a store — exactly the eager cost the
99 // integration is built to avoid. As a companion it lands on
100 // first open, and since the Explorer declares the same handle,
101 // whichever window opens first pays it once for both.
102 'styles' => array( 'os-my-wordpress-woocommerce' ),
103 'width' => 880,
104 'height' => 700,
105 'min_width' => 520,
106 'min_height' => 420,
107 'placement' => 'none',
108 'config' => array(
109 'restRoot' => esc_url_raw( rest_url( 'desktop-mode/v1/woocommerce/' ) ),
110 'restNonce' => wp_create_nonce( 'wp_rest' ),
111 ),
112 );
113
114 /**
115 * Filter the Customer window's registration args.
116 *
117 * **Status: Experimental**
118 *
119 * @param array $args `openstation_register_window()` args.
120 */
121 $args = (array) apply_filters( 'openstation_my_wordpress_woo_customer_window_args', $args );
122
123 $registered = openstation_register_window( 'desktop-mode-woo-customer', $args );
124 if ( is_wp_error( $registered ) ) {
125 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
126 error_log(
127 '[openstation] Customer window registration failed: '
128 . $registered->get_error_message()
129 );
130 }
131 }
132 add_action( 'init', 'openstation_my_wordpress_woo_customer_window_register', 25 );
133