Description
Using saveEntityRecord() to save a template stopped working in a recent update of Gutenberg.
I believe the issue was introduced in #67125 (cc @ellatrix), specifically where the wp_template rest_base is modified:
|
// How does this work? |
|
// 1. For wp_template, we remove the custom templates controller, so it becomes |
|
// a normal posts endpoint, modified slightly to allow auto-drafts. |
|
add_filter( 'register_post_type_args', 'gutenberg_modify_wp_template_post_type_args', 10, 2 ); |
|
function gutenberg_modify_wp_template_post_type_args( $args, $post_type ) { |
|
if ( 'wp_template' === $post_type ) { |
|
$args['rest_base'] = 'wp_template'; |
|
$args['rest_controller_class'] = 'Gutenberg_REST_Templates_Controller'; |
|
$args['autosave_rest_controller_class'] = null; |
|
$args['revisions_rest_controller_class'] = null; |
|
} |
|
return $args; |
|
} |
Step-by-step reproduction instructions
- Switch your theme to TT4.
- Add this code snippet somewhere in your site/plugin:
const { saveEntityRecord } = dispatch( coreStore );
saveEntityRecord(
'postType',
'wp_template',
{
id: 'twentytwentyfour//home',
content: 'test',
},
{
throwOnError: true,
}
);
- With Gutenberg disabled, notice a query to
/wp-json/wp/v2/templates/twentytwentyfour//home is done, and it works. With Gutenberg enabled, the query is done to /wp-json/wp/v2/wp_template/twentytwentyfour//home and it returns this error: No route was found matching the URL and request method..
Screenshots, screen recording, code snippet
No response
Environment info
- Gutenberg
nightly or trunk.
- WP 6.8.2.
Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.
Description
Using
saveEntityRecord()to save a template stopped working in a recent update of Gutenberg.I believe the issue was introduced in #67125 (cc @ellatrix), specifically where the
wp_templaterest_baseis modified:gutenberg/lib/compat/wordpress-6.9/template-activate.php
Lines 3 to 15 in 99d25fb
Step-by-step reproduction instructions
/wp-json/wp/v2/templates/twentytwentyfour//homeis done, and it works. With Gutenberg enabled, the query is done to/wp-json/wp/v2/wp_template/twentytwentyfour//homeand it returns this error:No route was found matching the URL and request method..Screenshots, screen recording, code snippet
No response
Environment info
nightlyortrunk.Please confirm that you have searched existing issues in the repo.
Please confirm that you have tested with all plugins deactivated except Gutenberg.
Please confirm which theme type you used for testing.