PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 0.9.8
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v0.9.8
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.8, at includes/my-wordpress/window.php

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