Skip to content

Commit

Permalink
Map manage_block_bindings to manage_options
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed Sep 6, 2024
1 parent 6403b32 commit 322766e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion lib/compat/wordpress-6.7/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ function gutenberg_add_server_block_bindings_sources_to_editor_settings( $editor

add_filter( 'block_editor_settings_all', 'gutenberg_add_server_block_bindings_sources_to_editor_settings', 10 );

/**
* Map the `manage_block_bindings` capability to `manage_options`.
*/
function gutenberg_add_manage_block_bindings_capability() {
global $wp_roles;
foreach ( $wp_roles->roles as $role_name => $role_info ) {
$role = get_role( $role_name );
// Map the capability to `manage_options`.
if ( $role->has_cap( 'manage_options' ) ) {
$role->add_cap( 'manage_block_bindings' );
}
}
}
add_action( 'init', 'gutenberg_add_manage_block_bindings_capability' );

/**
* Initialize `canUpdateBlockBindings` editor setting if it doesn't exist. By default, it is `true` only for admin users.
*
Expand All @@ -47,7 +62,7 @@ function gutenberg_add_server_block_bindings_sources_to_editor_settings( $editor
*/
function gutenberg_add_can_update_block_bindings_editor_setting( $editor_settings ) {
if ( empty( $editor_settings['canUpdateBlockBindings'] ) ) {
$editor_settings['canUpdateBlockBindings'] = current_user_can( 'manage_options' );
$editor_settings['canUpdateBlockBindings'] = current_user_can( 'manage_block_bindings' );
}
return $editor_settings;
}
Expand Down

0 comments on commit 322766e

Please sign in to comment.