diff --git a/lib/class-wp-theme-json-resolver.php b/lib/class-wp-theme-json-resolver.php index 86c3708b111032..c0e6b1ef548308 100644 --- a/lib/class-wp-theme-json-resolver.php +++ b/lib/class-wp-theme-json-resolver.php @@ -422,15 +422,7 @@ public static function register_user_custom_post_type() { 'show_ui' => false, 'show_in_rest' => true, 'rest_base' => '__experimental/global-styles', - 'capabilities' => array( - 'read' => 'edit_theme_options', - 'create_posts' => 'edit_theme_options', - 'edit_posts' => 'edit_theme_options', - 'edit_published_posts' => 'edit_theme_options', - 'delete_published_posts' => 'edit_theme_options', - 'edit_others_posts' => 'edit_theme_options', - 'delete_others_posts' => 'edit_theme_options', - ), + 'capabilities' => _gutenberg_get_default_capabilities_for_fse_post_types(), 'map_meta_cap' => true, 'supports' => array( 'title', diff --git a/lib/full-site-editing/full-site-editing.php b/lib/full-site-editing/full-site-editing.php index 564332bbf6896f..1c8d0d3158560e 100644 --- a/lib/full-site-editing/full-site-editing.php +++ b/lib/full-site-editing/full-site-editing.php @@ -143,3 +143,28 @@ function gutenberg_site_editor_load_block_editor_scripts_and_styles( $is_block_e : $is_block_editor_screen; } add_filter( 'should_load_block_editor_scripts_and_styles', 'gutenberg_site_editor_load_block_editor_scripts_and_styles' ); + +/** + * Used by wp_template, wp_template_part and wp_global_styles to map post type capabilities to edit_theme_options. + * + * @access private + * @internal + * + * @return array Default capabilities. + */ +function _gutenberg_get_default_capabilities_for_fse_post_types() { + return array( + 'create_posts' => 'edit_theme_options', + 'delete_posts' => 'edit_theme_options', + 'delete_others_posts' => 'edit_theme_options', + 'delete_private_posts' => 'edit_theme_options', + 'delete_published_posts' => 'edit_theme_options', + 'edit_posts' => 'edit_theme_options', + 'edit_others_posts' => 'edit_theme_options', + 'edit_private_posts' => 'edit_theme_options', + 'edit_published_posts' => 'edit_theme_options', + 'publish_posts' => 'edit_theme_options', + 'read' => 'edit_theme_options', + 'read_private_posts' => 'edit_theme_options', + ); +} diff --git a/lib/full-site-editing/template-parts.php b/lib/full-site-editing/template-parts.php index e3e0609a997109..d90172bb16cecc 100644 --- a/lib/full-site-editing/template-parts.php +++ b/lib/full-site-editing/template-parts.php @@ -46,6 +46,7 @@ function gutenberg_register_template_part_post_type() { 'show_in_rest' => true, 'rest_base' => 'template-parts', 'rest_controller_class' => 'WP_REST_Templates_Controller', + 'capabilities' => _gutenberg_get_default_capabilities_for_fse_post_types(), 'map_meta_cap' => true, 'supports' => array( 'title', diff --git a/lib/full-site-editing/templates.php b/lib/full-site-editing/templates.php index 0ecfcc9a68d8e6..9b155fe2ec3ee7 100644 --- a/lib/full-site-editing/templates.php +++ b/lib/full-site-editing/templates.php @@ -65,7 +65,7 @@ function gutenberg_register_template_post_type() { 'show_in_rest' => true, 'rest_base' => 'templates', 'rest_controller_class' => 'WP_REST_Templates_Controller', - 'capability_type' => array( 'template', 'templates' ), + 'capabilities' => _gutenberg_get_default_capabilities_for_fse_post_types(), 'map_meta_cap' => true, 'supports' => array( 'title', @@ -109,32 +109,6 @@ function gutenberg_register_wp_theme_taxonomy() { } add_action( 'init', 'gutenberg_register_wp_theme_taxonomy' ); -/** - * Filters the capabilities of a user to conditionally grant them capabilities for managing 'wp_template' posts. - * - * Any user who can 'edit_theme_options' will have access. - * - * @param array $allcaps A user's capabilities. - * @return array Filtered $allcaps. - */ -function gutenberg_grant_template_caps( array $allcaps ) { - if ( isset( $allcaps['edit_theme_options'] ) ) { - $allcaps['edit_templates'] = $allcaps['edit_theme_options']; - $allcaps['edit_others_templates'] = $allcaps['edit_theme_options']; - $allcaps['edit_published_templates'] = $allcaps['edit_theme_options']; - $allcaps['edit_private_templates'] = $allcaps['edit_theme_options']; - $allcaps['delete_templates'] = $allcaps['edit_theme_options']; - $allcaps['delete_others_templates'] = $allcaps['edit_theme_options']; - $allcaps['delete_published_templates'] = $allcaps['edit_theme_options']; - $allcaps['delete_private_templates'] = $allcaps['edit_theme_options']; - $allcaps['publish_templates'] = $allcaps['edit_theme_options']; - $allcaps['read_private_templates'] = $allcaps['edit_theme_options']; - } - - return $allcaps; -} -add_filter( 'user_has_cap', 'gutenberg_grant_template_caps' ); - /** * Fixes the label of the 'wp_template' admin menu entry. */