PluginProbe
Gutenberg / 23.4.0
Gutenberg v23.4.0
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-7.0 / preload.php

preload.php in Gutenberg 23.4.0, at lib/compat/wordpress-7.0/preload.php

57 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Preload necessary resources for the editors.
5 *
6 * @param array $paths REST API paths to preload.
7 * @param WP_Block_Editor_Context $context Current block editor context
8 *
9 * @return array Filtered preload paths.
10 */
11 function gutenberg_block_editor_preload_paths_6_9( $paths, $context ) {
12 if ( 'core/edit-site' === $context->name ) {
13 // Only prefetch for the root. If we preload it for all pages and it's not used
14 // it won't be possible to invalidate.
15 // To do: perhaps purge all preloaded paths when client side navigating.
16 if ( isset( $_GET['p'] ) && '/' !== $_GET['p'] ) {
17 $paths = array_filter(
18 $paths,
19 static function ( $path ) {
20 return '/wp/v2/templates/lookup?slug=front-page' !== $path && '/wp/v2/templates/lookup?slug=home' !== $path;
21 }
22 );
23 }
24 }
25
26 return $paths;
27 }
28 add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_6_9', 10, 2 );
29
30 /**
31 * Preload bound single-resource GETs the post editor would otherwise
32 * fetch post-mount.
33 *
34 * @param array $paths REST API paths.
35 * @param WP_Block_Editor_Context $context Block editor context.
36 * @return array
37 */
38 function gutenberg_block_editor_preload_paths_post_editor_bound_gets( $paths, $context ) {
39 if ( 'core/edit-post' !== $context->name || ! isset( $context->post ) ) {
40 return $paths;
41 }
42 $paths[] = '/wp/v2/templates/lookup?slug=front-page';
43 $paths[] = '/wp/v2/taxonomies?context=edit';
44 $paths[] = array( '/wp/v2/posts', 'OPTIONS' );
45
46 $author_id = (int) get_post_field( 'post_author', $context->post->ID );
47 if ( $author_id ) {
48 $paths[] = sprintf(
49 '/wp/v2/users/%d?context=view&_fields=id,name',
50 $author_id
51 );
52 }
53
54 return $paths;
55 }
56 add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_post_editor_bound_gets', 10, 2 );
57