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 / core-notices.php

core-notices.php in OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin 0.9.7, at includes/core-notices.php

257 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Re-derives WordPress Core's *global* admin notices — the ones that would
4 * otherwise repeat in every desktop window — into shell descriptors, so the
5 * shell can surface each once. The update nag is handled separately (see
6 * update-notice.php); this covers the rest.
7 *
8 * @since 0.9.6
9 * @package DesktopMode
10 */
11
12 defined( 'ABSPATH' ) || exit;
13
14 /**
15 * The in-scope global core notices for the current user, as shell
16 * descriptors. Each descriptor is `{ id, title, message, actionLabel?,
17 * actionUrl? }`, re-derived from authoritative state (never scraped) and
18 * capability-gated exactly as Core gates the underlying notice. The shell
19 * renders each as a persistent, dismissible toast.
20 *
21 * @since 0.9.6
22 *
23 * @return array<int,array{id:string,title:string,message:string,actionLabel:string,actionUrl:string}>
24 */
25 function desktop_mode_get_core_notices() {
26 $builders = array(
27 'desktop_mode_core_notice_maintenance',
28 'desktop_mode_core_notice_recovery_mode',
29 'desktop_mode_core_notice_default_password',
30 'desktop_mode_core_notice_deactivated_plugins',
31 'desktop_mode_core_notice_paused_plugins',
32 'desktop_mode_core_notice_paused_themes',
33 );
34
35 $notices = array();
36 foreach ( $builders as $builder ) {
37 $notice = $builder();
38 if ( $notice ) {
39 $notices[] = $notice;
40 }
41 }
42
43 /**
44 * Filters the core notices surfaced once in the desktop shell. Return an
45 * empty array to suppress them all, or unset individual entries by `id`.
46 *
47 * @since 0.9.6
48 *
49 * @param array $notices List of notice descriptors.
50 */
51 return apply_filters( 'desktop_mode_core_notices', $notices );
52 }
53
54 /**
55 * Normalizes a notice descriptor, filling optional fields.
56 *
57 * @since 0.9.6
58 *
59 * @param array $notice Partial descriptor with at least `id` + `message`.
60 * @return array{id:string,title:string,message:string,actionLabel:string,actionUrl:string}
61 */
62 function desktop_mode_core_notice( array $notice ) {
63 return array(
64 'id' => (string) $notice['id'],
65 'title' => isset( $notice['title'] ) ? (string) $notice['title'] : '',
66 'message' => (string) $notice['message'],
67 'actionLabel' => isset( $notice['actionLabel'] ) ? (string) $notice['actionLabel'] : '',
68 'actionUrl' => isset( $notice['actionUrl'] ) ? (string) $notice['actionUrl'] : '',
69 );
70 }
71
72 /**
73 * Interrupted / failed automated core update — mirrors `maintenance_nag()`.
74 *
75 * @since 0.9.6
76 *
77 * @return array|null
78 */
79 function desktop_mode_core_notice_maintenance() {
80 $nag = isset( $GLOBALS['upgrading'] );
81
82 if ( ! $nag ) {
83 $failed = get_site_option( 'auto_core_update_failed' );
84 $comparison = ! empty( $failed['critical'] ) ? '>=' : '>';
85 if ( isset( $failed['attempted'] )
86 && version_compare( $failed['attempted'], get_bloginfo( 'version' ), $comparison )
87 ) {
88 $nag = true;
89 }
90 }
91
92 if ( ! $nag ) {
93 return null;
94 }
95
96 $can = current_user_can( 'update_core' );
97 return desktop_mode_core_notice(
98 array(
99 'id' => 'maintenance',
100 'title' => __( 'WordPress Updates', 'desktop-mode' ),
101 'message' => $can
102 ? __( 'An automated WordPress update failed to complete.', 'desktop-mode' )
103 : __( 'An automated WordPress update failed to complete. Please notify the site administrator.', 'desktop-mode' ),
104 'actionLabel' => $can ? __( 'Retry update', 'desktop-mode' ) : '',
105 'actionUrl' => $can ? self_admin_url( 'update-core.php' ) : '',
106 )
107 );
108 }
109
110 /**
111 * Site is in recovery mode — mirrors `wp_recovery_mode_nag()`.
112 *
113 * @since 0.9.6
114 *
115 * @return array|null
116 */
117 function desktop_mode_core_notice_recovery_mode() {
118 if ( ! function_exists( 'wp_is_recovery_mode' ) || ! wp_is_recovery_mode() ) {
119 return null;
120 }
121
122 $url = wp_login_url();
123 $url = add_query_arg( 'action', WP_Recovery_Mode::EXIT_ACTION, $url );
124 $url = wp_nonce_url( $url, WP_Recovery_Mode::EXIT_ACTION );
125
126 return desktop_mode_core_notice(
127 array(
128 'id' => 'recovery-mode',
129 'title' => __( 'Recovery Mode', 'desktop-mode' ),
130 'message' => __( 'You are in recovery mode. There may be an error with a theme or plugin.', 'desktop-mode' ),
131 'actionLabel' => __( 'Exit recovery mode', 'desktop-mode' ),
132 'actionUrl' => $url,
133 )
134 );
135 }
136
137 /**
138 * User is still on their auto-generated password — mirrors
139 * `default_password_nag()`.
140 *
141 * @since 0.9.6
142 *
143 * @return array|null
144 */
145 function desktop_mode_core_notice_default_password() {
146 if ( ! get_user_option( 'default_password_nag' ) ) {
147 return null;
148 }
149
150 return desktop_mode_core_notice(
151 array(
152 'id' => 'default-password',
153 'title' => __( 'Profile', 'desktop-mode' ),
154 'message' => __( 'You are using an auto-generated password. Would you like to change it?', 'desktop-mode' ),
155 'actionLabel' => __( 'Change password', 'desktop-mode' ),
156 'actionUrl' => self_admin_url( 'profile.php#password' ),
157 )
158 );
159 }
160
161 /**
162 * Plugins force-deactivated on a WordPress upgrade — mirrors
163 * `deactivated_plugins_notice()`.
164 *
165 * @since 0.9.6
166 *
167 * @return array|null
168 */
169 function desktop_mode_core_notice_deactivated_plugins() {
170 if ( ! current_user_can( 'activate_plugins' ) ) {
171 return null;
172 }
173
174 $deactivated = get_option( 'wp_force_deactivated_plugins' );
175 if ( empty( $deactivated ) || ! is_array( $deactivated ) ) {
176 return null;
177 }
178
179 $names = array();
180 foreach ( $deactivated as $plugin ) {
181 if ( ! empty( $plugin['plugin_name'] ) ) {
182 $names[] = $plugin['plugin_name'];
183 }
184 }
185 if ( ! $names ) {
186 return null;
187 }
188
189 return desktop_mode_core_notice(
190 array(
191 'id' => 'deactivated-plugins',
192 'title' => __( 'Plugins', 'desktop-mode' ),
193 'message' => sprintf(
194 /* translators: %s: comma-separated list of plugin names. */
195 __( 'Deactivated during a WordPress upgrade for incompatibility: %s.', 'desktop-mode' ),
196 implode( ', ', $names )
197 ),
198 'actionLabel' => __( 'View plugins', 'desktop-mode' ),
199 'actionUrl' => self_admin_url( 'plugins.php?plugin_status=inactive' ),
200 )
201 );
202 }
203
204 /**
205 * Plugins paused by recovery mode — mirrors `paused_plugins_notice()`.
206 *
207 * @since 0.9.6
208 *
209 * @return array|null
210 */
211 function desktop_mode_core_notice_paused_plugins() {
212 if ( ! current_user_can( 'resume_plugins' ) || ! function_exists( 'wp_paused_plugins' ) ) {
213 return null;
214 }
215
216 if ( empty( wp_paused_plugins()->get_all() ) ) {
217 return null;
218 }
219
220 return desktop_mode_core_notice(
221 array(
222 'id' => 'paused-plugins',
223 'title' => __( 'Plugins', 'desktop-mode' ),
224 'message' => __( 'One or more plugins failed to load properly.', 'desktop-mode' ),
225 'actionLabel' => __( 'Go to Plugins', 'desktop-mode' ),
226 'actionUrl' => self_admin_url( 'plugins.php?plugin_status=paused' ),
227 )
228 );
229 }
230
231 /**
232 * Themes paused by recovery mode — mirrors `paused_themes_notice()`.
233 *
234 * @since 0.9.6
235 *
236 * @return array|null
237 */
238 function desktop_mode_core_notice_paused_themes() {
239 if ( ! current_user_can( 'resume_themes' ) || ! function_exists( 'wp_paused_themes' ) ) {
240 return null;
241 }
242
243 if ( empty( wp_paused_themes()->get_all() ) ) {
244 return null;
245 }
246
247 return desktop_mode_core_notice(
248 array(
249 'id' => 'paused-themes',
250 'title' => __( 'Themes', 'desktop-mode' ),
251 'message' => __( 'One or more themes failed to load properly.', 'desktop-mode' ),
252 'actionLabel' => __( 'Go to Themes', 'desktop-mode' ),
253 'actionUrl' => self_admin_url( 'themes.php' ),
254 )
255 );
256 }
257