PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.8
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.8
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 0.8.6 All 33 releases
desktop-mode / includes / core-notices.php

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

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