PluginProbe
Gutenberg / 23.3.1
Gutenberg v23.3.1
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / lib / compat / wordpress-6.9 / preload.php

preload.php in Gutenberg 23.3.1, at lib/compat/wordpress-6.9/preload.php

36 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Preload path adjustments for the WordPress 6.9 block editor.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Append the user global styles preload entries for classic themes.
10 *
11 * Core's `edit-form-blocks.php` derives the user global styles post id from
12 * `WP_Theme_JSON_Resolver::get_user_global_styles_post_id()`. On WP 6.9 that
13 * short-circuits to `null` for themes without a `theme.json`, leaving the two
14 * derived preload entries with an empty id (see the early-return removed by
15 * https://github.com/WordPress/wordpress-develop/commit/fd2693d9 for the WP 7.0
16 * fix). The Gutenberg-shipped resolver has no such early-return, so use it to
17 * append the correctly-id'd entries — the malformed core ones go unused.
18 *
19 * @param array $paths REST API paths to preload.
20 * @return array Filtered preload paths.
21 */
22 function gutenberg_block_editor_preload_paths_user_global_styles_6_9( $paths ) {
23 if ( ! class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' ) ) {
24 return $paths;
25 }
26 $id = WP_Theme_JSON_Resolver_Gutenberg::get_user_global_styles_post_id();
27 if ( ! $id ) {
28 return $paths;
29 }
30 $context = current_user_can( 'edit_theme_options' ) ? 'edit' : 'view';
31 $paths[] = '/wp/v2/global-styles/' . $id . '?context=' . $context;
32 $paths[] = array( '/wp/v2/global-styles/' . $id, 'OPTIONS' );
33 return $paths;
34 }
35 add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_user_global_styles_6_9' );
36