PluginProbe
Gutenberg / 14.7.0
Gutenberg v14.7.0
24.0.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 All 403 releases
gutenberg / lib / compat / wordpress-6.0 / edit-form-blocks.php

edit-form-blocks.php in Gutenberg 14.7.0, at lib/compat/wordpress-6.0/edit-form-blocks.php

67 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Patches resources loaded by the block editor page.
4 *
5 * @package gutenberg
6 */
7
8 /**
9 * Optimizes the preload paths registered in Core (`edit-form-blocks.php`).
10 *
11 * @param array $preload_paths Preload paths to be filtered.
12 * @return array
13 */
14 function gutenberg_optimize_preload_paths( $preload_paths ) {
15 // remove preload of the `/` route.
16 $root_index = array_search( '/', $preload_paths, true );
17 if ( false !== $root_index ) {
18 array_splice( $preload_paths, $root_index, 1 );
19 }
20
21 // change `/types` context from `edit` to `view` (requested in `loadPostTypeEntities`).
22 $types_index = array_search( '/wp/v2/types?context=edit', $preload_paths, true );
23 if ( false !== $types_index ) {
24 $preload_paths[ $types_index ] = '/wp/v2/types?context=view';
25 }
26
27 // start preloading `/taxonomies` in `view` context (requested in `loadTaxonomyEntities`).
28 $tax_index = array_search( '/wp/v2/taxonomies?per_page=-1&context=edit', $preload_paths, true );
29 if ( false === $tax_index ) {
30 array_push( $preload_paths, '/wp/v2/taxonomies?context=view' );
31 } else {
32 $preload_paths[ $tax_index ] = '/wp/v2/taxonomies?context=view';
33 }
34
35 // start preloading `/settings`.
36 $settings_index = array_search( '/wp/v2/settings', $preload_paths, true );
37 if ( false === $settings_index ) {
38 array_push( $preload_paths, '/wp/v2/settings' );
39 }
40
41 // modify the preload of `/users/me` to match the real request.
42 foreach ( $preload_paths as $user_index => $user_path ) {
43 if ( is_string( $user_path ) && str_starts_with( $user_path, '/wp/v2/users/me' ) ) {
44 $preload_paths[ $user_index ] = '/wp/v2/users/me';
45 break;
46 }
47 }
48
49 return $preload_paths;
50 }
51 add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_optimize_preload_paths' );
52
53 /**
54 * Disables loading remote block patterns from REST while initializing the editor.
55 * Nowadays these loads are done in the `block-patterns/patterns` REST endpoint, and
56 * are undesired when initializing the block editor page, both in post and site editor.
57 *
58 * @param WP_Screen $current_screen WordPress current screen object.
59 */
60 function gutenberg_disable_load_remote_patterns( $current_screen ) {
61 $is_site_editor = ( function_exists( 'gutenberg_is_edit_site_page' ) && gutenberg_is_edit_site_page( $current_screen->id ) );
62 if ( $is_site_editor || $current_screen->is_block_editor() ) {
63 add_filter( 'should_load_remote_block_patterns', '__return_false' );
64 }
65 }
66 add_action( 'current_screen', 'gutenberg_disable_load_remote_patterns' );
67