-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add templates list page for site editor #36379
Changes from all commits
4a078a9
e4d6072
a3affd2
4d00bfe
4c8a145
7e362f9
bd51447
744e636
5476b36
0533972
b900246
84878b5
28e7eb3
035f2bf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,15 @@ function gutenberg_is_edit_site_page( $page ) { | |
return 'appearance_page_gutenberg-edit-site' === $page; | ||
} | ||
|
||
/** | ||
* Checks whether the provided page is the templates list page. | ||
* | ||
* @return bool True for Site Editor pages, false otherwise. | ||
*/ | ||
function gutenberg_is_edit_site_list_page() { | ||
return isset( $_GET['postType'] ) && ! isset( $_GET['postId'] ); | ||
} | ||
|
||
/** | ||
* Load editor styles (this is copied from edit-form-blocks.php). | ||
* Ideally the code is extracted into a reusable function. | ||
|
@@ -68,7 +77,50 @@ function gutenberg_get_editor_styles() { | |
} | ||
|
||
/** | ||
* Initialize the Gutenberg Edit Site Page. | ||
* Initialize the Gutenberg Templates List Page. | ||
*/ | ||
function gutenberg_edit_site_list_init() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed the word 'list' is used throughout, and wonder if it's a bit too vague. Something more descriptive like 'entity list' might be an option? |
||
wp_enqueue_script( 'wp-edit-site' ); | ||
wp_enqueue_style( 'wp-edit-site' ); | ||
wp_enqueue_media(); | ||
|
||
$template_type = $_GET['postType']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to bail here if an invalid Fix: #36706 |
||
$post_type = get_post_type_object( $template_type ); | ||
|
||
$preload_data = array_reduce( | ||
array( | ||
'/', | ||
"/wp/v2/types/$template_type?context=edit", | ||
'/wp/v2/types?context=edit', | ||
"/wp/v2/$post_type->rest_base?context=edit", | ||
), | ||
'rest_preload_api_request', | ||
array() | ||
); | ||
|
||
wp_add_inline_script( | ||
'wp-api-fetch', | ||
sprintf( | ||
'wp.apiFetch.use( wp.apiFetch.createPreloadingMiddleware( %s ) );', | ||
wp_json_encode( $preload_data ) | ||
), | ||
'after' | ||
); | ||
|
||
wp_add_inline_script( | ||
'wp-edit-site', | ||
sprintf( | ||
'wp.domReady( function() { | ||
wp.editSite.initializeList( "%s", "%s" ); | ||
} );', | ||
'edit-site-editor', | ||
$template_type | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Initialize the Gutenberg Site Editor. | ||
* | ||
* @since 7.2.0 | ||
* | ||
|
@@ -90,6 +142,10 @@ static function( $classes ) { | |
} | ||
); | ||
|
||
if ( gutenberg_is_edit_site_list_page() ) { | ||
return gutenberg_edit_site_list_init(); | ||
} | ||
|
||
/** | ||
* Make the WP Screen object aware that this is a block editor page. | ||
* Since custom blocks check whether the screen is_block_editor, | ||
|
@@ -135,7 +191,7 @@ static function( $classes ) { | |
'/wp/v2/themes/' . $active_theme . '/global-styles', | ||
) | ||
), | ||
'initializer_name' => 'initialize', | ||
'initializer_name' => 'initializeEditor', | ||
'editor_settings' => $settings, | ||
) | ||
); | ||
|
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you not use get_screen or similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean here? Sorry I'm not really familiar with PHP 😅 .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we can. These are query arguments on the Site Editor page.