Skip to content

Commit

Permalink
Scaffold out preloading
Browse files Browse the repository at this point in the history
  • Loading branch information
getdave committed Mar 2, 2023
1 parent 5a94c56 commit 1fb6fae
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
48 changes: 48 additions & 0 deletions lib/compat/wordpress-6.3/navigation-block-preloading.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

/**
* Adds the preload paths registered in Core (`edit-form-blocks.php`).
*
* @param array $preload_paths Preload paths to be filtered.
* @param WP_Block_Editor_Context $context The current block editor context.
* @return array
*/
function gutenberg_preload_navigation_permissions( $preload_paths, $context ) {

$preload_paths[] = array( rest_get_route_for_post_type_items( 'wp_navigation' ), 'OPTIONS' );

$preload_paths[] = rest_get_route_for_post_type_items( 'wp_navigation' );
// add /wp/v2/navigation?context=edit&per_page=-1&status%5B0%5D=publish&status%5B1%5D=draft to preload paths array
$preload_paths[] = array(
rest_get_route_for_post_type_items(
'wp_navigation',
),
array(
'context' => 'edit',
'per_page' => '-1',
'status' => array( 'publish, draft' ),
),

);

// add /wp/v2/navigation?_locale=user&context=edit&per_page=100&status%5B0%5D=publish&status%5B1%5D=draft to preload paths array
$preload_paths[] = array(
rest_get_route_for_post_type_items(
'wp_navigation',
),
array(
'_locale' => 'user',
'context' => 'edit',
'per_page' => '100',
'status' => array( 'publish, draft' ),
),

);

echo '<pre>';
var_dump( $preload_paths );
echo '</pre>';

return $preload_paths;
}
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_preload_navigation_permissions', 10, 2 );
1 change: 1 addition & 0 deletions lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require_once __DIR__ . '/compat/wordpress-6.3/class-gutenberg-rest-pattern-directory-controller-6-3.php';
require_once __DIR__ . '/compat/wordpress-6.3/class-gutenberg-rest-templates-controller-6-3.php';
require_once __DIR__ . '/compat/wordpress-6.3/rest-api.php';
require_once __DIR__ . '/compat/wordpress-6.3/navigation-block-preloading.php';

// Experimental.
if ( ! class_exists( 'WP_Rest_Customizer_Nonces' ) ) {
Expand Down

0 comments on commit 1fb6fae

Please sign in to comment.