PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3-a.5
Jetpack – WP Security, Backup, Speed, & Growth v16.3-a.5
16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 All 506 releases
jetpack / build / pages / jetpack-settings-dashboard / page-wp-admin.php

page-wp-admin.php in Jetpack – WP Security, Backup, Speed, & Growth 16.3-a.5, at build/pages/jetpack-settings-dashboard/page-wp-admin.php

361 lines 12.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Page: jetpack-settings-dashboard (wp-admin integrated)
4 * Auto-generated by build process.
5 * Do not edit this file manually.
6 *
7 * This version integrates with the standard WordPress admin interface,
8 * keeping the wp-admin sidebar and scripts/styles intact.
9 *
10 * @package jetpack_plugin
11 */
12
13 // Global storage for jetpack-settings-dashboard routes and menu items
14 global $jetpack_plugin_jetpack_settings_dashboard_wp_admin_routes, $jetpack_plugin_jetpack_settings_dashboard_wp_admin_menu_items;
15 $jetpack_plugin_jetpack_settings_dashboard_wp_admin_routes = array();
16 $jetpack_plugin_jetpack_settings_dashboard_wp_admin_menu_items = array();
17
18 /**
19 * Register a route for the jetpack-settings-dashboard-wp-admin page.
20 *
21 * @param string $path Route path (e.g., '/types/$type/edit/$id').
22 * @param string|null $content_module Script module ID for content (stage/inspector).
23 * @param string|null $route_module Script module ID for route lifecycle hooks.
24 */
25 function jetpack_plugin_register_jetpack_settings_dashboard_wp_admin_route( $path, $content_module = null, $route_module = null ) {
26 global $jetpack_plugin_jetpack_settings_dashboard_wp_admin_routes;
27
28 $route = array( 'path' => $path );
29 if ( ! empty( $content_module ) ) {
30 $route['content_module'] = $content_module;
31 }
32 if ( ! empty( $route_module ) ) {
33 $route['route_module'] = $route_module;
34 }
35
36 $jetpack_plugin_jetpack_settings_dashboard_wp_admin_routes[] = $route;
37 }
38
39 /**
40 * Register a menu item for the jetpack-settings-dashboard-wp-admin page.
41 * Note: Menu items are registered but not displayed in single-page mode.
42 *
43 * @param string $id Menu item ID.
44 * @param string $label Display label.
45 * @param string $to Route path to navigate to.
46 * @param string $parent_id Optional. Parent menu item ID.
47 */
48 function jetpack_plugin_register_jetpack_settings_dashboard_wp_admin_menu_item( $id, $label, $to, $parent_id = '' ) {
49 global $jetpack_plugin_jetpack_settings_dashboard_wp_admin_menu_items;
50
51 $menu_item = array(
52 'id' => $id,
53 'label' => $label,
54 'to' => $to,
55 );
56
57 if ( ! empty( $parent_id ) ) {
58 $menu_item['parent'] = $parent_id;
59 }
60
61 $jetpack_plugin_jetpack_settings_dashboard_wp_admin_menu_items[] = $menu_item;
62 }
63
64 /**
65 * Get all registered routes for the jetpack-settings-dashboard-wp-admin page.
66 *
67 * @return array Array of route objects.
68 */
69 function jetpack_plugin_get_jetpack_settings_dashboard_wp_admin_routes() {
70 global $jetpack_plugin_jetpack_settings_dashboard_wp_admin_routes;
71 return $jetpack_plugin_jetpack_settings_dashboard_wp_admin_routes ?? array();
72 }
73
74 /**
75 * Get all registered menu items for the jetpack-settings-dashboard-wp-admin page.
76 *
77 * @return array Array of menu item objects.
78 */
79 function jetpack_plugin_get_jetpack_settings_dashboard_wp_admin_menu_items() {
80 global $jetpack_plugin_jetpack_settings_dashboard_wp_admin_menu_items;
81 return $jetpack_plugin_jetpack_settings_dashboard_wp_admin_menu_items ?? array();
82 }
83
84 /**
85 * Preload REST API data for the jetpack-settings-dashboard-wp-admin page.
86 * Automatically called during page rendering.
87 */
88 function jetpack_plugin_jetpack_settings_dashboard_wp_admin_preload_data() {
89 // Define paths to preload - same for all pages
90 // This must exactly match the _fields list in packages/core-data/src/entities.js,
91 // same fields in the same order, or the preload is never consumed.
92 $preload_paths = array(
93 '/?_fields=description,gmt_offset,home,image_max_bit_depth,image_sizes,image_size_threshold,image_strip_meta,name,site_icon,site_icon_url,site_logo,timezone_string,url,page_for_posts,page_on_front,show_on_front',
94 array( '/wp/v2/settings', 'OPTIONS' ),
95 );
96
97 // Use rest_preload_api_request to gather the preloaded data
98 $preload_data = array_reduce(
99 $preload_paths,
100 'rest_preload_api_request',
101 array()
102 );
103
104 // Register the preloading middleware with wp-api-fetch
105 wp_add_inline_script(
106 'wp-api-fetch',
107 sprintf(
108 'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );',
109 wp_json_encode( $preload_data )
110 ),
111 'after'
112 );
113 }
114
115 /**
116 * Enqueue scripts and styles for the jetpack-settings-dashboard-wp-admin page.
117 * Hooked to admin_enqueue_scripts.
118 *
119 * @param string $hook_suffix The current admin page.
120 */
121 function jetpack_plugin_jetpack_settings_dashboard_wp_admin_enqueue_scripts( $hook_suffix ) {
122 // Check all possible ways this page can be accessed:
123 // 1. Menu page via admin.php?page=jetpack-settings-dashboard-wp-admin (plugin)
124 // 2. Direct file via jetpack-settings-dashboard.php (Core) - screen ID will be 'jetpack-settings-dashboard'
125 $current_screen = get_current_screen();
126 $is_our_page = (
127 ( isset( $_GET['page'] ) && 'jetpack-settings-dashboard-wp-admin' === $_GET['page'] ) || // phpcs:ignore WordPress.Security.NonceVerification.Recommended
128 ( $current_screen && 'jetpack-settings-dashboard' === $current_screen->id )
129 );
130
131 if ( ! $is_our_page ) {
132 return;
133 }
134
135 // Load build constants
136 $build_constants = require __DIR__ . '/../../constants.php';
137
138 /**
139 * Fires when the jetpack-settings-dashboard admin page is initialized so extensions can register routes and menu items.
140 */
141 do_action( 'jetpack-settings-dashboard-wp-admin_init' );
142
143 // Preload REST API data
144 jetpack_plugin_jetpack_settings_dashboard_wp_admin_preload_data();
145
146 // Get all registered routes
147 $routes = jetpack_plugin_get_jetpack_settings_dashboard_wp_admin_routes();
148
149 // Get boot module asset file for dependencies. Plugins that build their own
150 // boot module use it; everyone else falls back to the copy bundled with Core.
151 $asset_file = __DIR__ . '/../../modules/boot/index.min.asset.php';
152 if ( ! file_exists( $asset_file ) ) {
153 $asset_file = ABSPATH . WPINC . '/js/dist/script-modules/boot/index.min.asset.php';
154 }
155 if ( file_exists( $asset_file ) ) {
156 $asset = require $asset_file;
157
158 // This script serves two purposes:
159 // 1. It ensures all the globals that are made available to the modules are loaded.
160 // 2. It initializes the boot module as an inline script.
161 wp_register_script( 'jetpack-settings-dashboard-wp-admin-prerequisites', '', $asset['dependencies'], $asset['version'], true );
162
163 $init_modules = ["@jetpack-plugin/init"];
164
165 /*
166 * Add inline script to initialize the app using initSinglePage (no menuItems).
167 * The dynamic import is deferred until DOMContentLoaded so that all classic
168 * script dependencies of @wordpress/boot (wp-private-apis, wp-components,
169 * wp-theme, etc.) have finished parsing and executing before the boot module
170 * evaluates. Otherwise, a modulepreloaded @wordpress/boot can win the race
171 * against the classic-script-printing pass on fast CDN-fronted hosts in
172 * Chrome, evaluating before wp.theme.privateApis is defined and throwing
173 * "Cannot unlock an undefined object". See <https://core.trac.wordpress.org/ticket/65103>.
174 */
175 $init_js_function = <<<'JS'
176 ( mountId, routes, initModules ) => {
177 const run = async () => {
178 const mod = await import( "@wordpress/boot" );
179 /*
180 * Run the init modules here instead of delegating to
181 * initSinglePage(): WordPress cores that bundle an older
182 * @wordpress/boot (initModules support postdates WP 7.0's copy,
183 * and the import map resolves @wordpress/boot to core's bundle
184 * when core provides one) silently ignore the option, so init
185 * modules would never execute. Running them before
186 * initSinglePage() gives identical behavior on every core.
187 */
188 for ( const id of initModules ?? [] ) {
189 try {
190 const initModule = await import( id );
191 if ( typeof initModule.init === "function" ) {
192 await initModule.init();
193 }
194 } catch ( error ) {
195 console.warn( "Failed to run boot init module:", id, error );
196 }
197 }
198 mod.initSinglePage( { mountId, routes } );
199 };
200 if ( document.readyState === "loading" ) {
201 document.addEventListener( "DOMContentLoaded", run );
202 } else {
203 run();
204 }
205 }
206 JS;
207 wp_add_inline_script(
208 'jetpack-settings-dashboard-wp-admin-prerequisites',
209 sprintf(
210 '( %s )( %s, %s, %s );',
211 $init_js_function,
212 wp_json_encode( 'jetpack-settings-dashboard-wp-admin-app', JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
213 wp_json_encode( $routes, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES ),
214 wp_json_encode( $init_modules, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES )
215 )
216 );
217
218 // Register prerequisites style by filtering script dependencies to find registered styles
219 $style_dependencies = array_filter(
220 $asset['dependencies'],
221 function ( $handle ) {
222 return wp_style_is( $handle, 'registered' );
223 }
224 );
225 wp_register_style( 'jetpack-settings-dashboard-wp-admin-prerequisites', false, $style_dependencies, $asset['version'] );
226
227 // Build dependencies for jetpack-settings-dashboard-wp-admin module
228 $boot_dependencies = array(
229 array(
230 'import' => 'static',
231 'id' => '@wordpress/boot',
232 ),
233 );
234
235 // Add init modules as static dependencies
236 $boot_dependencies[] = array( 'import' => 'static', 'id' => '@jetpack-plugin/init' );
237
238 // Add all registered routes as dependencies
239 foreach ( $routes as $route ) {
240 if ( isset( $route['route_module'] ) ) {
241 $boot_dependencies[] = array(
242 'import' => 'static',
243 'id' => $route['route_module'],
244 );
245 }
246 if ( isset( $route['content_module'] ) ) {
247 $boot_dependencies[] = array(
248 'import' => 'dynamic',
249 'id' => $route['content_module'],
250 );
251 }
252 }
253
254 /**
255 * Filters the boot script-module dependencies for the
256 * jetpack-settings-dashboard-wp-admin page.
257 *
258 * Surfaces extending this page can append entries to the boot
259 * dependency list. Each entry is an array with 'import' (string
260 * 'static' or 'dynamic') and 'id' (script-module handle) keys.
261 *
262 * @param array $boot_dependencies Boot dependencies for the page.
263 */
264 $boot_dependencies = apply_filters(
265 'jetpack-settings-dashboard-wp-admin_boot_dependencies',
266 $boot_dependencies
267 );
268
269 // Dummy script module to ensure dependencies are loaded
270 wp_register_script_module(
271 'jetpack-settings-dashboard-wp-admin',
272 $build_constants['build_url'] . 'pages/jetpack-settings-dashboard/loader.js',
273 $boot_dependencies
274 );
275
276 // Enqueue the boot scripts and styles
277 wp_enqueue_script( 'jetpack-settings-dashboard-wp-admin-prerequisites' );
278 wp_enqueue_script_module( 'jetpack-settings-dashboard-wp-admin' );
279 wp_enqueue_style( 'jetpack-settings-dashboard-wp-admin-prerequisites' );
280 }
281 }
282
283 /**
284 * Render the jetpack-settings-dashboard-wp-admin page.
285 * Call this function from add_menu_page or add_submenu_page.
286 * This renders within the normal WordPress admin interface.
287 */
288 function jetpack_plugin_jetpack_settings_dashboard_wp_admin_render_page() {
289 ?>
290 <style>
291 /* Critical styles to prevent layout shifts - inlined for immediate application */
292
293 #wpwrap {
294 overflow-y: auto;
295 }
296 body.js {
297 background: #fff;
298 }
299
300 /* Reset wp-admin padding */
301 body.js #wpcontent {
302 padding-inline-start: 0;
303 }
304 body.js #wpbody-content {
305 padding-bottom: 0;
306 }
307
308 /* Hide legacy admin elements */
309 body.js #wpbody-content > div:not(#jetpack-settings-dashboard-wp-admin-app):not(#screen-meta) {
310 display: none;
311 }
312 body.js #wpfooter {
313 display: none;
314 }
315
316 /* Accessibility regions */
317 .a11y-speak-region {
318 inset-inline-start: -1px;
319 top: -1px;
320 }
321
322 /* Admin menu indicators */
323 ul#adminmenu a.wp-has-current-submenu::after,
324 ul#adminmenu > li.current > a.current::after {
325 border-inline-end-color: #fff;
326 }
327
328 /* Media frame fix */
329 .media-frame select.attachment-filters:last-of-type {
330 width: auto;
331 max-width: 100%;
332 }
333
334 /* Responsive overflow fix for #wpwrap */
335 @media (min-width: 782px) {
336 #wpwrap {
337 overflow-y: initial;
338 }
339 }
340 </style>
341 <div class="wrap hide-if-js">
342 <h1 class="wp-heading-inline"><?php echo esc_html( get_admin_page_title() ); ?></h1>
343 <?php
344 wp_admin_notice(
345 __( 'This screen requires JavaScript. Enable JavaScript in your browser settings and reload the page.' ),
346 array( 'type' => 'error' )
347 );
348 ?>
349 </div>
350 <?php
351 // Core's pre-CSS Modules Boot layout uses this class for viewport sizing.
352 // Remove it when the minimum supported WordPress version includes the Boot
353 // changes from Gutenberg #81756.
354 ?>
355 <div id="jetpack-settings-dashboard-wp-admin-app" class="boot-layout-container"></div>
356 <?php
357 }
358
359 // Hook the enqueue function to admin_enqueue_scripts
360 add_action( 'admin_enqueue_scripts', 'jetpack_plugin_jetpack_settings_dashboard_wp_admin_enqueue_scripts' );
361