Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Site Editor: preload always required settings #61088

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/compat/wordpress-6.6/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,16 @@ function wp_api_template_access_controller( $args, $post_type ) {
}
}
add_filter( 'register_post_type_args', 'wp_api_template_access_controller', 10, 2 );

function gutenberg_block_editor_preload_paths_6_6( $paths, $context ) {
if ( 'core/edit-site' === $context->name ) {
// When merging back to core, these should be added here:
// https://github.com/WordPress/wordpress-develop/blob/7159243c090e429a7d2a1fd2a9509e323f67a39d/src/wp-admin/site-editor.php#L90-L117
$paths[] = array( '/wp/v2/settings', 'OPTIONS' );
$paths[] = '/wp/v2/settings';
$paths[] = array( '/wp/v2/templates', 'OPTIONS' );
$paths[] = '/wp/v2/types?context=edit';
}
return $paths;
}
add_filter( 'block_editor_rest_api_preload_paths', 'gutenberg_block_editor_preload_paths_6_6', 10, 2 );
1 change: 1 addition & 0 deletions packages/core-commands/src/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';

export function useIsTemplatesAccessible() {
// This resource is preloaded.
return useSelect(
( select ) => select( coreStore ).canUser( 'read', 'templates' ),
[]
Expand Down
1 change: 1 addition & 0 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ export default function Editor( { isLoading, onClick } ) {
isDistractionFree: get( 'core', 'distractionFree' ),
showBlockBreadcrumbs: get( 'core', 'showBlockBreadcrumbs' ),
showIconLabels: get( 'core', 'showIconLabels' ),
// This resource is preloaded.
postTypeLabel: getPostTypeLabel(),
};
}, [] );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ function useResolveEditedEntityAndContext( { path, postId, postType } ) {
url,
frontPageTemplateId,
} = useSelect( ( select ) => {
const { getSite, getUnstableBase, getEntityRecords } =
select( coreDataStore );
const { getSite, getEntityRecords } = select( coreDataStore );
// This resource is preloaded.
const siteData = getSite();
const base = getUnstableBase();
// This resource is preloaded.
const templates = getEntityRecords( 'postType', TEMPLATE_POST_TYPE, {
per_page: -1,
} );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this resource was already preloaded before this PR.

Expand All @@ -63,10 +63,10 @@ function useResolveEditedEntityAndContext( { path, postId, postType } ) {
: false;
}
return {
hasLoadedAllDependencies: !! base && !! siteData,
hasLoadedAllDependencies: !! siteData,
homepageId: _homepageId,
postsPageId: _postsPageId,
url: base?.home,
url: siteData?.home,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're in the site editor, which is only accessible to admins, so we can use the normal settings.

frontPageTemplateId: _frontPageTemplateId,
};
}, [] );
Expand Down
Loading