PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 0.9.7
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v0.9.7
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 0.9.7, at includes/user-edit-window/window.php

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