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