Open bangank36 opened 1 year ago
null
variable at start, it will fail
function gutenberg_get_block_templates( $query_result = null, $query = array(), $template_type = 'wp_template' ) {}
add_filter( 'pre_get_block_templates', 'gutenberg_get_block_templates', 10, 2 );
- Current `$template_type` is always bound to the initial value as wp_template or wp_template_part...
WP_REST_Blocks_Controller
Gutenberg_REST_Blocks_Controller
WP_REST_Templates_Controller
wp_template
and wp_template_part
wp_block
rest_controller_class overriding using filter register_post_type_args
, we can mimic the changes for template postsGutenberg_REST_Template_Revision_Count
has been introduced to override Template REST on 6.3 already, we can take advantage of this insteadwp_pattern_sync_status
origin
, does it mean origin is a post meta for the templates?
templates
and parts
$new_template_item
is createdBlock Templates is queried from database + theme folder with _get_block_templates_files
Absolute paths is retrieved in _get_block_templates_paths
path
prop is assigned in returned template file
title
is provided in _add_block_template_info
Note that _get_block_template_file
is different from _get_block_templates_files
, one for single and one for multi files
But both methods call the _add_block_template_info
(wp_template) and _add_block_template_part_area_info
(wp_template_part) to insert missing meta data for the object
Template file template_slug is the one extracted directly from file path (it will store correct file paths with folder), stripped .html
, we can restore it as meta path
nit: if the templates are modified and saved in database, their slugs will be extracted and skipped query from files $query['slug__not_in'] = wp_list_pluck( $query_result, 'slug' );
We may need to intercept this behavior by check it against the real path not the slug
Rough steps
slug
(slug is correctly parse from template file at this phase) to a post metaslug__not_in
with the path meta, not the slug
Summary
The current template synchronization is not working well with template files in nested folder
Propose solution to create a post meta for storing the path of the template files as post meta
get_items
, use post meta instead of post name in synchronisation process. Which function? Which API endpoint?Code navigation
wp_template_part
custom post type and rest handlerAccording to this, we can modify the Wordpress code directly in Gutenberg repo?
gutenberg/lib/compat/wordpress-5.9
Look at the 2 method in core and Gutenberg
return apply_filters( 'default_template_types', $default_template_types );
add_filter( 'default_template_types', 'gutenberg_get_default_block_template_types', 10 );
Here's a simplified version of what happens:
This allows the Gutenberg plugin to modify the default block template types provided by WordPress.
Reference