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 / recycle-bin / window.php

window.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 0.9.8, at includes/recycle-bin/window.php

243 lines 9.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 — Recycle Bin: window + icon registration.
4 *
5 * Native window with id `desktop-mode-recycle-bin`, pinned to the taskbar with a
6 * matching wallpaper icon. Like the code editor, the template body is a
7 * static skeleton that the JS bundle enhances on first open — the table
8 * is populated from the REST list endpoint at render time.
9 *
10 * Both registrations are filterable via the standard
11 * `desktop_mode_recycle_bin_window_args` / `desktop_mode_recycle_bin_icon_args`
12 * filters so a plugin can swap the icon, change the dimensions, or
13 * restrict who sees the bin without touching this file.
14 *
15 * @package WPDesktopMode
16 */
17
18 defined( 'ABSPATH' ) || exit;
19
20 /**
21 * Echoes the recycle bin window's template body.
22 *
23 * The shell wraps this in `<template id="desktop-mode-native-window-desktop-mode-recycle-bin">`
24 * and clones it into the window body BEFORE the JS render callback runs.
25 * The `data-desktop-mode-recycle-bin-*` hooks below are the contract the JS
26 * relies on — keep them intact (or rename via the filter) when
27 * customizing the layout.
28 */
29 function desktop_mode_recycle_bin_render_template() {
30 ob_start();
31 ?>
32 <div class="desktop-mode-recycle-bin" data-desktop-mode-recycle-bin-root>
33 <header class="desktop-mode-recycle-bin__toolbar" data-desktop-mode-recycle-bin-toolbar>
34 <div class="desktop-mode-recycle-bin__toolbar-left">
35 <wpd-segmented data-desktop-mode-recycle-bin-filter>
36 <wpd-segment value="" selected><?php esc_html_e( 'All', 'desktop-mode' ); ?></wpd-segment>
37 <wpd-segment value="post"><?php esc_html_e( 'Posts', 'desktop-mode' ); ?></wpd-segment>
38 <wpd-segment value="page"><?php esc_html_e( 'Pages', 'desktop-mode' ); ?></wpd-segment>
39 <?php
40 // The Media segment is only useful when WP itself routes
41 // attachment deletions through Trash. That gate is the
42 // `MEDIA_TRASH` constant — defaults to false in core, can
43 // be flipped to true from `wp-config.php`. Without it,
44 // attachments permanent-delete on first click and the
45 // Trash bin will never have anything in this bucket, so
46 // the tab would always read "0" and confuse users.
47 if ( defined( 'MEDIA_TRASH' ) && MEDIA_TRASH ) :
48 ?>
49 <wpd-segment value="attachment"><?php esc_html_e( 'Media', 'desktop-mode' ); ?></wpd-segment>
50 <?php
51 endif;
52 ?>
53 <wpd-segment value="comment"><?php esc_html_e( 'Comments', 'desktop-mode' ); ?></wpd-segment>
54 <wpd-segment value="desktop"><?php esc_html_e( 'Desktop', 'desktop-mode' ); ?></wpd-segment>
55 </wpd-segmented>
56 <wpd-text-field
57 data-desktop-mode-recycle-bin-search
58 placeholder="<?php esc_attr_e( 'Search trash…', 'desktop-mode' ); ?>"
59 ></wpd-text-field>
60 </div>
61 <div class="desktop-mode-recycle-bin__toolbar-right" data-desktop-mode-recycle-bin-bulk hidden>
62 <span class="desktop-mode-recycle-bin__count" data-desktop-mode-recycle-bin-count></span>
63 <wpd-button variant="secondary" data-desktop-mode-recycle-bin-restore-selected>
64 <span class="dashicons dashicons-image-rotate" aria-hidden="true"></span>
65 <?php esc_html_e( 'Restore', 'desktop-mode' ); ?>
66 </wpd-button>
67 <wpd-button variant="secondary" data-desktop-mode-recycle-bin-pin-to-desktop>
68 <span class="dashicons dashicons-desktop" aria-hidden="true"></span>
69 <?php esc_html_e( 'Pin to desktop', 'desktop-mode' ); ?>
70 </wpd-button>
71 <wpd-button variant="danger" data-desktop-mode-recycle-bin-purge-selected>
72 <span class="dashicons dashicons-trash" aria-hidden="true"></span>
73 <?php esc_html_e( 'Delete forever', 'desktop-mode' ); ?>
74 </wpd-button>
75 </div>
76 <div class="desktop-mode-recycle-bin__toolbar-trailing">
77 <wpd-button variant="ghost" data-desktop-mode-recycle-bin-refresh title="<?php esc_attr_e( 'Refresh', 'desktop-mode' ); ?>">
78 <span class="dashicons dashicons-update" aria-hidden="true"></span>
79 </wpd-button>
80 <wpd-button variant="danger" data-desktop-mode-recycle-bin-empty>
81 <span class="dashicons dashicons-trash" aria-hidden="true"></span>
82 <?php esc_html_e( 'Empty Trash', 'desktop-mode' ); ?>
83 </wpd-button>
84 </div>
85 </header>
86 <div class="desktop-mode-recycle-bin__body" data-desktop-mode-recycle-bin-body>
87 <wpd-table
88 data-desktop-mode-recycle-bin-table
89 selectable="multi"
90 sticky-header
91 hover
92 striped
93 loading
94 >
95 <div slot="empty" class="desktop-mode-recycle-bin__empty">
96 <span class="dashicons dashicons-trash" aria-hidden="true"></span>
97 <p><?php esc_html_e( 'The Trash is empty.', 'desktop-mode' ); ?></p>
98 <p class="desktop-mode-recycle-bin__empty-hint">
99 <?php esc_html_e( 'Deleted posts, pages, and media show up here. Restoring puts them back where they were.', 'desktop-mode' ); ?>
100 </p>
101 </div>
102 </wpd-table>
103 </div>
104 </div>
105 <?php
106 $html = (string) ob_get_clean();
107
108 /**
109 * Filter the recycle bin window's template HTML.
110 *
111 * Keep the `data-desktop-mode-recycle-bin-*` hooks intact so the JS render
112 * callback can find its mount points, or rename them and update the
113 * matching constants in `src/recycle-bin/index.ts`.
114 *
115 * @param string $html Default template HTML.
116 */
117 $filtered = (string) apply_filters( 'desktop_mode_recycle_bin_template_html', $html );
118 echo wp_kses( $filtered, desktop_mode_native_window_allowed_html() );
119 }
120
121 /**
122 * Whether the current user should see the recycle bin at all.
123 *
124 * Filterable so plugins can hide it from authors/contributors who
125 * don't manage trash, or invert the gate to expose it to a custom
126 * role.
127 *
128 * @return bool
129 */
130 function desktop_mode_recycle_bin_user_can_use() {
131 $can = current_user_can( 'edit_posts' );
132
133 /**
134 * Filter whether the current user can see the recycle bin window.
135 *
136 * @param bool $can Default: edit_posts capability.
137 */
138 return (bool) apply_filters( 'desktop_mode_recycle_bin_user_can_use', $can );
139 }
140
141 /**
142 * Register the recycle bin window + desktop icon on `init`.
143 *
144 * Hooked at priority 20, after `components.php` has bootstrapped the
145 * native-window registry — same timing as the code editor.
146 */
147 function desktop_mode_recycle_bin_register_window() {
148 if ( ! desktop_mode_recycle_bin_user_can_use() ) {
149 return;
150 }
151
152 $window_args = array(
153 'title' => __( 'Trash', 'desktop-mode' ),
154 'icon' => 'dashicons-trash',
155 'template' => 'desktop_mode_recycle_bin_render_template',
156 'script' => 'desktop-mode-recycle-bin',
157 'width' => 880,
158 'height' => 560,
159 'min_width' => 520,
160 'min_height' => 360,
161 'placement' => 'taskbar',
162 );
163
164 /**
165 * Filter the args used to register the recycle bin native window.
166 *
167 * @param array $window_args Args passed to `desktop_mode_register_window()`.
168 */
169 $window_args = (array) apply_filters( 'desktop_mode_recycle_bin_window_args', $window_args );
170
171 $registered = desktop_mode_register_window( 'desktop-mode-recycle-bin', $window_args );
172 if ( is_wp_error( $registered ) ) {
173 // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
174 error_log( '[desktop-mode] Recycle bin window registration failed: ' . $registered->get_error_message() );
175 return;
176 }
177
178 $icon_args = array(
179 'title' => __( 'Trash', 'desktop-mode' ),
180 'icon' => 'dashicons-trash',
181 'window' => 'desktop-mode-recycle-bin',
182 'position' => 80,
183 );
184
185 /**
186 * Filter the args used to register the recycle bin desktop icon.
187 *
188 * @param array $icon_args Args passed to `desktop_mode_register_icon()`.
189 */
190 $icon_args = (array) apply_filters( 'desktop_mode_recycle_bin_icon_args', $icon_args );
191
192 desktop_mode_register_icon( 'desktop-mode-recycle-bin', $icon_args );
193 }
194 add_action( 'init', 'desktop_mode_recycle_bin_register_window', 20 );
195
196 /**
197 * Localize REST endpoints for the JS bundle.
198 *
199 * Same pattern as the code editor: the bundle reads its config off
200 * `window.desktopModeRecycleBinConfig` and never hardcodes URLs.
201 */
202 function desktop_mode_recycle_bin_localize_config() {
203 if ( ! desktop_mode_recycle_bin_user_can_use() ) {
204 return;
205 }
206
207 wp_localize_script(
208 'desktop-mode-recycle-bin',
209 'desktopModeRecycleBinConfig',
210 array(
211 'restNonce' => wp_create_nonce( 'wp_rest' ),
212 'listUrl' => esc_url_raw( rest_url( 'desktop-mode/v1/recycle-bin' ) ),
213 'restoreUrl' => esc_url_raw( rest_url( 'desktop-mode/v1/recycle-bin/restore' ) ),
214 'purgeUrl' => esc_url_raw( rest_url( 'desktop-mode/v1/recycle-bin/purge' ) ),
215 'emptyUrl' => esc_url_raw( rest_url( 'desktop-mode/v1/recycle-bin/empty' ) ),
216 'countUrl' => esc_url_raw( rest_url( 'desktop-mode/v1/recycle-bin/count' ) ),
217 'postTypes' => desktop_mode_recycle_bin_capture_post_types(),
218 )
219 );
220
221 wp_enqueue_style( 'desktop-mode-recycle-bin' );
222 }
223 add_action( 'admin_enqueue_scripts', 'desktop_mode_recycle_bin_localize_config', 30 );
224
225 /**
226 * Inject the initial trash count into the shell config so the
227 * dock/taskbar tile + desktop icon can paint a badge on the very
228 * first paint — before the bin window has ever opened.
229 *
230 * @param array $config Shell config blob.
231 * @return array
232 */
233 function desktop_mode_recycle_bin_inject_shell_config( $config ) {
234 if ( ! is_array( $config ) ) {
235 return $config;
236 }
237 $config['recycleBinCount'] = desktop_mode_recycle_bin_count();
238 $config['recycleBinCountUrl'] = esc_url_raw( rest_url( 'desktop-mode/v1/recycle-bin/count' ) );
239 $config['recycleBinPostTypes'] = desktop_mode_recycle_bin_capture_post_types();
240 return $config;
241 }
242 add_filter( 'desktop_mode_shell_config', 'desktop_mode_recycle_bin_inject_shell_config', 20 );
243