-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix: Post_type template is not used when creating a page in site editor. #62488
Changes from all commits
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 |
---|---|---|
|
@@ -30,3 +30,49 @@ function gutenberg_register_edit_site_export_controller_endpoints() { | |
} | ||
|
||
add_action( 'rest_api_init', 'gutenberg_register_edit_site_export_controller_endpoints' ); | ||
|
||
if ( ! function_exists( 'gutenberg_register_wp_rest_post_types_controller_fields' ) ) { | ||
/** | ||
* Adds `template` and `template_lock` fields to WP_REST_Post_Types_Controller class. | ||
*/ | ||
function gutenberg_register_wp_rest_post_types_controller_fields() { | ||
register_rest_field( | ||
'type', | ||
'template', | ||
array( | ||
'get_callback' => function ( $item ) { | ||
$post_type = get_post_type_object( $item['slug'] ); | ||
if ( ! empty( $post_type ) && ! empty( $post_type->template ) ) { | ||
return $post_type->template; | ||
} | ||
}, | ||
'schema' => array( | ||
'type' => 'array', | ||
'description' => __( 'The template associated with the post type.', 'gutenberg' ), | ||
'readonly' => true, | ||
'context' => array( 'view', 'edit', 'embed' ), | ||
), | ||
) | ||
); | ||
register_rest_field( | ||
'type', | ||
'template_lock', | ||
array( | ||
'get_callback' => function ( $item ) { | ||
$post_type = get_post_type_object( $item['slug'] ); | ||
if ( ! empty( $post_type ) && ! empty( $post_type->template_lock ) && false !== $post_type->template_lock ) { | ||
return $post_type->template_lock; | ||
} | ||
}, | ||
'schema' => array( | ||
'type' => 'string', | ||
'enum' => array( 'all', 'insert', 'contentOnly' ), | ||
'description' => __( 'The template_lock specified for the post type.', 'gutenberg' ), | ||
'readonly' => true, | ||
'context' => array( 'view', 'edit', 'embed' ), | ||
), | ||
) | ||
); | ||
} | ||
} | ||
add_action( 'rest_api_init', 'gutenberg_register_wp_rest_post_types_controller_fields' ); | ||
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. Should we be worried about changes to the REST API this late in the release cycle? This PR will need a backport PR asap. 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 are only adding two fields that will for sure be required, so I don't think we have back-compatibility problems or unexpected issues. I'm preparing a backport PR, but I don't have a strong option. we can opt for not include this fix in WP 6.6 if you think it is safer. |
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.
Should the phrasing reflect that the template is optional and refers to block templates as opposed to a
wp_template
? For example: