Skip to content
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

Standardise capabilities for wp_template, wp_template_part and wp_global_styles #30893

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions lib/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
25 changes: 25 additions & 0 deletions lib/full-site-editing/full-site-editing.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
);
}
1 change: 1 addition & 0 deletions lib/full-site-editing/template-parts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
28 changes: 1 addition & 27 deletions lib/full-site-editing/templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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.
*/
Expand Down