PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.1
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.1
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 / user-edit-window / window.php

window.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 1.1.1, at includes/user-edit-window/window.php

189 lines 7.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * OpenStation — Native User Edit (single user) window.
4 *
5 * Singleton native window that opens when an admin clicks an
6 * OTHER user's row in the Users table (or when the URL remap for
7 * `user-edit.php?user_id=N` fires). The Users window's "Profile"
8 * tab handles the **current** user's own profile in-place — this
9 * window is the dedicated surface for editing OTHER users.
10 *
11 * Reuses the same JS render functions
12 * (`mountProfileFormAt`, `mountProfileAsideAt`,
13 * `mountProfileActivityAt`) that power the Profile tab; the only
14 * difference is the wrapper template (no Users tab strip; just
15 * the sidebar layout) and the way the target user id is resolved
16 * (read from the shared store when a row click / URL remap set a
17 * target, falling back to the viewer's own id — which is how
18 * `profile.php` opens).
19 *
20 * @package OpenStation
21 */
22
23 defined( 'ABSPATH' ) || exit;
24
25 /**
26 * Echoes the User Edit window's template body.
27 */
28 function openstation_user_edit_window_render_template() {
29 ob_start();
30 ?>
31 <div class="os-user-edit-window" data-os-user-edit-window-root>
32 <?php
33 /*
34 * The `<os-user-profile>` component reads its target
35 * user id from the `user-id` attribute and mounts the
36 * full profile surface (sidebar + form + activity) on
37 * its own. The render callback in `index.ts` sets the
38 * attribute after reading the shared store; absent that,
39 * the attribute is empty and the component idles until
40 * set.
41 */
42 ?>
43 <os-user-profile data-os-user-profile-host></os-user-profile>
44 </div>
45 <?php
46 $html = (string) ob_get_clean();
47
48 /**
49 * Filter the User Edit window's template HTML.
50 *
51 * @param string $html Default template HTML.
52 */
53 $filtered = (string) apply_filters( 'openstation_user_edit_window_template_html', $html );
54
55 if ( function_exists( 'openstation_kses_native_window_template' ) ) {
56 echo openstation_kses_native_window_template( $filtered ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- helper kses-escapes.
57 } else {
58 echo wp_kses( $filtered, wp_kses_allowed_html( 'post' ) );
59 }
60 }
61
62 /**
63 * Build the admin colour scheme list with full colour tuples for
64 * each scheme. Mirrors what WP core feeds the
65 * `admin_color_scheme_picker` action: each entry carries the
66 * scheme `name` and a `colors` tuple (typically 3-4 hex strings)
67 * used to render mini-swatch previews — not just a slug list.
68 *
69 * @return array<string,array{name:string,colors:array<int,string>,icon_colors?:array<string,string>}>
70 */
71 function openstation_user_edit_window_color_schemes() {
72 $out = array();
73 // Always pull in `wp-admin/includes/admin.php` if needed so the
74 // admin colour scheme registry is available — the user-edit
75 // window may render via REST (where `is_admin()` returns false
76 // but `current_user_can( 'edit_user', … )` is the real gate).
77 // The include is guarded by `is_readable` so a stripped-down
78 // install without admin/ on disk still degrades gracefully.
79 if ( ! function_exists( 'register_admin_color_schemes' ) ) {
80 $admin_inc = ABSPATH . 'wp-admin/includes/admin.php';
81 if ( is_readable( $admin_inc ) ) {
82 require_once $admin_inc;
83 }
84 }
85 if ( function_exists( 'register_admin_color_schemes' ) ) {
86 register_admin_color_schemes();
87 }
88 global $_wp_admin_css_colors;
89 if ( is_array( $_wp_admin_css_colors ) ) {
90 foreach ( $_wp_admin_css_colors as $slug => $info ) {
91 $out[ (string) $slug ] = array(
92 'name' => isset( $info->name )
93 ? (string) $info->name
94 : (string) $slug,
95 // The colors stylesheet URL — required for the live
96 // preview swap on self-edit. Matches what core's
97 // `wp-admin/js/user-profile.js` reads off the
98 // `.css_url` hidden field per scheme tile.
99 'url' => isset( $info->url )
100 ? esc_url_raw( (string) $info->url )
101 : '',
102 'colors' => isset( $info->colors )
103 ? array_values( (array) $info->colors )
104 : array(),
105 'icon_colors' => isset( $info->icon_colors )
106 ? (array) $info->icon_colors
107 : array(),
108 );
109 }
110 }
111 if ( empty( $out ) ) {
112 // Fallback so the picker still shows ONE option even when
113 // $_wp_admin_css_colors hasn't populated.
114 $out['fresh'] = array(
115 'name' => __( 'Default', 'desktop-mode' ),
116 'colors' => array( '#1d2327', '#2c3338', '#2271b1', '#72aee6' ),
117 );
118 }
119 return $out;
120 }
121
122 /**
123 * Register the User Edit native window on `init`.
124 */
125 function openstation_user_edit_window_register_window() {
126 if ( ! openstation_user_edit_window_user_can_register() ) {
127 return;
128 }
129 $viewer_id = (int) get_current_user_id();
130
131 $window_args = array(
132 'title' => __( 'Edit user', 'desktop-mode' ),
133 'icon' => 'dashicons-admin-users',
134 'template' => 'openstation_user_edit_window_render_template',
135 // Reuses the Posts bundle. The render callback for
136 // `desktop-mode-user-edit` lives in `index.ts` and dispatches
137 // to `user-edit-render`'s mount points — same code the Users
138 // window's Profile tab uses.
139 'script' => 'os-posts-window',
140 'style' => 'os-posts-window',
141 'width' => 1100,
142 'height' => 760,
143 'min_width' => 720,
144 'min_height' => 520,
145 'placement' => 'none',
146 'config' => array(
147 'mode' => 'user-edit',
148 'restRoot' => esc_url_raw( rest_url() ),
149 'restNonce' => wp_create_nonce( 'wp_rest' ),
150 'usersUrl' => esc_url_raw( rest_url( 'wp/v2/users' ) ),
151 'currentUserId' => $viewer_id,
152 'insightsUrlBase' => esc_url_raw( rest_url( 'desktop-mode/v1/users/' ) ),
153 'editPostUrlBase' => esc_url_raw( admin_url( 'post.php' ) ),
154 // Capability flag so the JS can hide the role select for
155 // viewers without `promote_users`. Server-side `update_item`
156 // re-checks regardless; this is UX polish.
157 'canPromote' => current_user_can( 'promote_users' ),
158 // Roles the viewer is allowed to assign — the role select
159 // reads this first and falls back to {@see allRoles} for
160 // older configs. Surfacing only assignable roles in the
161 // dropdown prevents a "pick a role, hit save, get rejected"
162 // loop for viewers with `promote_users` but a narrowed
163 // `editable_roles` filter (e.g. site managers who can't
164 // promote anyone to administrator).
165 'assignableRoles' => function_exists( 'openstation_users_window_role_label_map' )
166 ? openstation_users_window_role_label_map( $viewer_id )
167 : array(),
168 'allRoles' => function_exists( 'openstation_users_window_all_roles_map' )
169 ? openstation_users_window_all_roles_map()
170 : array(),
171 'locales' => function_exists( 'openstation_users_window_locales_map' )
172 ? openstation_users_window_locales_map()
173 : array( '' => __( 'Site default', 'desktop-mode' ) ),
174 /** This filter is documented in wp-includes/user.php */
175 'contactMethods' => (array) apply_filters( 'user_contactmethods', array(), null ), // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Core's filter; the window must offer the same contact fields profile.php does.
176 'colorSchemes' => openstation_user_edit_window_color_schemes(),
177 ),
178 );
179
180 $window_args = (array) apply_filters( 'openstation_user_edit_window_args', $window_args );
181
182 $registered = openstation_register_window( 'desktop-mode-user-edit', $window_args );
183 if ( is_wp_error( $registered ) ) {
184 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
185 error_log( '[openstation] User Edit window registration failed: ' . $registered->get_error_message() );
186 }
187 }
188 add_action( 'init', 'openstation_user_edit_window_register_window', 25 );
189