Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Inline all api requests
  • Loading branch information
kevin940726 committed Dec 6, 2021
commit 1070ca6f908a33be06ef4090069cb6636067b667
39 changes: 12 additions & 27 deletions lib/full-site-editing/edit-site-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,28 +76,6 @@ function gutenberg_get_editor_styles() {
return $styles;
}

/**
* Get the Gutenberg Templates List Page preload paths.
*/
function gutenberg_edit_site_list_preload_paths() {
if ( ! gutenberg_is_edit_site_list_page() ) {
return array();
}

$post_type = get_post_type_object( $_GET['postType'] );

if ( ! $post_type ) {
wp_die( __( 'Invalid post type.', 'gutenberg' ) );
}

return array(
'/',
"/wp/v2/types/$post_type->name?context=edit",
'/wp/v2/types?context=edit',
"/wp/v2/$post_type->rest_base?context=edit&per_page=-1",
);
}

/**
* Initialize the Gutenberg Site Editor.
*
Expand All @@ -112,6 +90,14 @@ function gutenberg_edit_site_init( $hook ) {
return;
}

if ( gutenberg_is_edit_site_list_page() ) {
$post_type = get_post_type_object( $_GET['postType'] );

if ( ! $post_type ) {
wp_die( __( 'Invalid post type.', 'gutenberg' ) );
}
}

// Default to is-fullscreen-mode to avoid rendering wp-admin navigation menu while loading and
// having jumps in the UI.
add_filter(
Expand All @@ -131,8 +117,6 @@ static function( $classes ) {
'__experimentalBlockPatternCategories' => WP_Block_Pattern_Categories_Registry::get_instance()->get_all_registered(),
);

$list_page_preload_paths = gutenberg_edit_site_list_preload_paths();

/**
* Make the WP Screen object aware that this is a block editor page.
* Since custom blocks check whether the screen is_block_editor,
Expand All @@ -154,20 +138,21 @@ static function( $classes ) {
array( '/wp/v2/media', 'OPTIONS' ),
'/',
'/wp/v2/types?context=edit',
'/wp/v2/types/wp_template?context=edit',
'/wp/v2/types/wp_template-part?context=edit',
'/wp/v2/taxonomies?context=edit',
'/wp/v2/pages?context=edit',
'/wp/v2/categories?context=edit',
'/wp/v2/posts?context=edit',
'/wp/v2/tags?context=edit',
'/wp/v2/templates?context=edit',
'/wp/v2/template-parts?context=edit',
'/wp/v2/templates?context=edit&per_page=-1',
'/wp/v2/template-parts?context=edit&per_page=-1',
'/wp/v2/settings',
'/wp/v2/themes?context=edit&status=active',
'/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit',
'/wp/v2/global-styles/' . $active_global_styles_id,
'/wp/v2/global-styles/themes/' . $active_theme,
),
$list_page_preload_paths
),
'initializer_name' => 'initializeEditor',
'editor_settings' => $settings,
Expand Down
10 changes: 3 additions & 7 deletions packages/edit-site/src/components/url-query-controller/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
*/
import { useEffect } from '@wordpress/element';
import { useDispatch, useSelect } from '@wordpress/data';
import { addQueryArgs, removeQueryArgs } from '@wordpress/url';

/**
* Internal dependencies
*/
import { useLocation } from '../routes';
import { useLocation, useHistory } from '../routes';
import { store as editSiteStore } from '../../store';

export default function URLQueryController() {
const { setTemplate, setTemplatePart, showHomepage, setPage } = useDispatch(
editSiteStore
);
const history = useHistory();
const {
params: { postId, postType },
} = useLocation();
Expand All @@ -40,11 +40,7 @@ export default function URLQueryController() {
// Update page URL when context changes.
const pageContext = useCurrentPageContext();
useEffect( () => {
const newUrl = pageContext
? addQueryArgs( window.location.href, pageContext )
: removeQueryArgs( window.location.href, 'postType', 'postId' );

window.history.replaceState( {}, '', newUrl );
history.replace( pageContext );
}, [ pageContext ] );

return null;
Expand Down