PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 0.9.5
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v0.9.5
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 / window.php

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

251 lines 8.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Desktop Mode — My WordPress: window + pinned icon registration.
4 *
5 * Native window with id `desktop-mode-my-wordpress`, opened from a
6 * pinned desktop icon that always sits in the top-left of the grid
7 * (`pinned: true`, `position: -1`). The bundle renders a two-pane
8 * file-explorer UI with breadcrumb navigation: root shows Posts,
9 * Pages, Users, and Media folder tiles, and clicking one drills into
10 * an infinite-scroll list of entities with a per-kind preview pane.
11 *
12 * Filterable surface (mirrors the recycle-bin / posts-window modules):
13 *
14 * - `desktop_mode_my_wordpress_window_args`
15 * - `desktop_mode_my_wordpress_icon_args`
16 * - `desktop_mode_my_wordpress_user_can_use`
17 * - `desktop_mode_my_wordpress_entities`
18 * - `desktop_mode_my_wordpress_template_html`
19 *
20 * @package WPDesktopMode
21 * @since 0.8.0
22 */
23
24 defined( 'ABSPATH' ) || exit;
25
26 /**
27 * Whether the current user should see My WordPress.
28 *
29 * Mirrors the recycle-bin gate — anyone who can edit posts can
30 * browse posts and pages.
31 *
32 * @since 0.8.0
33 *
34 * @return bool
35 */
36 function desktop_mode_my_wordpress_user_can_use() {
37 $can = current_user_can( 'edit_posts' );
38
39 /**
40 * Filter whether the current user can see the My WordPress
41 * pinned icon and window.
42 *
43 * @since 0.8.0
44 *
45 * @param bool $can Default: edit_posts capability.
46 */
47 return (bool) apply_filters( 'desktop_mode_my_wordpress_user_can_use', $can );
48 }
49
50 /**
51 * Build the entity list shipped to the bundle. Posts, Pages, Users
52 * (since 0.8.2), and Media (since 0.8.6). Future phases add
53 * Comments, Tags, Categories, Themes, and Plugins.
54 *
55 * The optional `kind` field tells the bundle how to render entries
56 * of this entity: `'post'` (default) renders the standard
57 * title/excerpt/featured-image tile and the rendered-HTML preview;
58 * `'user'` renders an avatar + display-name tile and routes to the
59 * user dossier preview; `'media'` renders a thumbnail-grid tile and
60 * routes to the media preview pane. Plugins extending the entity
61 * list with a post-shaped collection can omit the field; user- and
62 * media-shaped collections must set `'user'` / `'media'`.
63 *
64 * @since 0.8.0
65 *
66 * @return array[] Each entry is `array( 'id', 'label', 'icon',
67 * 'restPath', 'kind' )`. `restPath` is appended to
68 * the `restRoot` config to derive the list URL.
69 */
70 function desktop_mode_my_wordpress_entities() {
71 $entities = array(
72 array(
73 'id' => 'posts',
74 'label' => __( 'Posts', 'desktop-mode' ),
75 'icon' => 'dashicons-admin-post',
76 'restPath' => 'wp/v2/posts',
77 'kind' => 'post',
78 ),
79 array(
80 'id' => 'pages',
81 'label' => __( 'Pages', 'desktop-mode' ),
82 'icon' => 'dashicons-admin-page',
83 'restPath' => 'wp/v2/pages',
84 'kind' => 'post',
85 ),
86 array(
87 'id' => 'users',
88 'label' => __( 'Users', 'desktop-mode' ),
89 'icon' => 'dashicons-admin-users',
90 'restPath' => 'wp/v2/users',
91 'kind' => 'user',
92 ),
93 array(
94 'id' => 'media',
95 'label' => __( 'Media', 'desktop-mode' ),
96 'icon' => 'dashicons-admin-media',
97 'restPath' => 'wp/v2/media',
98 'kind' => 'media',
99 ),
100 );
101
102 /**
103 * Filter the list of entity types shown inside the My WordPress
104 * window. Each entry must declare `id`, `label`, `icon`, and
105 * `restPath`. Returning a reordered or extended array shows up
106 * in the bundle on the next render.
107 *
108 * **Status: Experimental** — the entity descriptor shape may
109 * gain fields as new entity kinds land (Comments, Tags,
110 * Categories, Themes, Plugins). Stable id/label/icon/restPath
111 * fields will continue to work; new optional fields will not
112 * break existing consumers. The `kind` field is optional and
113 * defaults to `'post'` for back-compat.
114 *
115 * @since 0.8.0
116 *
117 * @param array[] $entities Default entities.
118 */
119 $filtered = apply_filters( 'desktop_mode_my_wordpress_entities', $entities );
120 return is_array( $filtered ) ? array_values( $filtered ) : $entities;
121 }
122
123 /**
124 * Render the My WordPress window's static template body. The bundle
125 * mounts its UI into `[data-desktop-mode-my-wordpress-root]`.
126 *
127 * @since 0.8.0
128 */
129 function desktop_mode_my_wordpress_render_template() {
130 ob_start();
131 ?>
132 <div class="desktop-mode-my-wordpress" data-desktop-mode-my-wordpress-root>
133 <header data-desktop-mode-my-wordpress-breadcrumbs></header>
134 <div class="desktop-mode-my-wordpress__body" data-desktop-mode-my-wordpress-body>
135 <div class="desktop-mode-my-wordpress__loading" data-desktop-mode-my-wordpress-loading hidden>
136 <wpd-spinner></wpd-spinner>
137 </div>
138 </div>
139 <div class="desktop-mode-folder-status-bar" data-desktop-mode-my-wordpress-status></div>
140 </div>
141 <?php
142 $html = (string) ob_get_clean();
143
144 /**
145 * Filter the My WordPress window's template HTML.
146 *
147 * @since 0.8.0
148 *
149 * @param string $html Default template HTML.
150 */
151 $filtered = (string) apply_filters( 'desktop_mode_my_wordpress_template_html', $html );
152
153 $allowed_html = function_exists( 'desktop_mode_native_window_allowed_html' )
154 ? desktop_mode_native_window_allowed_html()
155 : wp_kses_allowed_html( 'post' );
156
157 echo wp_kses( $filtered, $allowed_html );
158 }
159
160 /**
161 * Register the native window + the pinned wallpaper icon on `init`,
162 * priority 20 — after `components.php` boots the registry.
163 *
164 * @since 0.8.0
165 */
166 function desktop_mode_my_wordpress_register_window() {
167 if ( ! desktop_mode_my_wordpress_user_can_use() ) {
168 return;
169 }
170
171 $window_args = array(
172 'title' => __( 'My WordPress', 'desktop-mode' ),
173 'icon' => 'dashicons-wordpress',
174 'template' => 'desktop_mode_my_wordpress_render_template',
175 'script' => 'desktop-mode-my-wordpress',
176 'style' => 'desktop-mode-my-wordpress',
177 'width' => 960,
178 'height' => 640,
179 'min_width' => 640,
180 'min_height' => 420,
181 'placement' => 'none',
182 'config' => array(
183 'restRoot' => esc_url_raw( rest_url() ),
184 'restNonce' => wp_create_nonce( 'wp_rest' ),
185 'editPostUrlBase' => esc_url_raw( admin_url( 'post.php' ) ),
186 'editUserUrlBase' => esc_url_raw( admin_url( 'user-edit.php' ) ),
187 'entities' => desktop_mode_my_wordpress_entities(),
188 'perPage' => 24,
189 'mediaPerPage' => 48,
190 'previewActions' => function_exists( 'desktop_mode_my_wordpress_collect_preview_actions' )
191 ? desktop_mode_my_wordpress_collect_preview_actions()
192 : array(),
193 ),
194 );
195
196 /**
197 * Filter the args used to register the My WordPress native window.
198 *
199 * @since 0.8.0
200 *
201 * @param array $window_args Args passed to `desktop_mode_register_window()`.
202 */
203 $window_args = (array) apply_filters( 'desktop_mode_my_wordpress_window_args', $window_args );
204
205 $registered = desktop_mode_register_window( 'desktop-mode-my-wordpress', $window_args );
206 if ( is_wp_error( $registered ) ) {
207 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
208 error_log( '[desktop-mode] My WordPress window registration failed: ' . $registered->get_error_message() );
209 return;
210 }
211
212 $icon_args = array(
213 'title' => __( 'My WordPress', 'desktop-mode' ),
214 'icon' => 'dashicons-wordpress',
215 'window' => 'desktop-mode-my-wordpress',
216 'pinned' => true,
217 'position' => -1,
218 );
219
220 /**
221 * Filter the args used to register the My WordPress pinned icon.
222 *
223 * Removing `pinned` here lets the icon participate in normal
224 * sort order — useful for sites that want the shortcut to feel
225 * like any other plugin icon.
226 *
227 * @since 0.8.0
228 *
229 * @param array $icon_args Args passed to `desktop_mode_register_icon()`.
230 */
231 $icon_args = (array) apply_filters( 'desktop_mode_my_wordpress_icon_args', $icon_args );
232
233 desktop_mode_register_icon( 'desktop-mode-my-wordpress', $icon_args );
234 }
235 add_action( 'init', 'desktop_mode_my_wordpress_register_window', 20 );
236
237 /**
238 * Enqueue the bundle's CSS in admin context. The script is lazy-
239 * loaded by the native-window sync and so does not need an
240 * `admin_enqueue_scripts` call.
241 *
242 * @since 0.8.0
243 */
244 function desktop_mode_my_wordpress_enqueue_styles() {
245 if ( ! desktop_mode_my_wordpress_user_can_use() ) {
246 return;
247 }
248 wp_enqueue_style( 'desktop-mode-my-wordpress' );
249 }
250 add_action( 'admin_enqueue_scripts', 'desktop_mode_my_wordpress_enqueue_styles', 30 );
251