| 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 |
|