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

Block Bindings: Map edit_block_binding capability #65116

Open
wants to merge 6 commits into
base: trunk
Choose a base branch
from

Conversation

SantosGuillamot
Copy link
Contributor

@SantosGuillamot SantosGuillamot commented Sep 6, 2024

What?

This pull requests add compatibility to create a edit_block_binding capability that will be mapped to what was decided here.

Why?

The compatibility filters should work the same way as core.

How?

Adding a new edit_block_binding capability through an init hook.

Testing Instructions

  1. Register some meta fields in your site.
	register_meta(
		'post',
		'my_custom_field',
		array(
			'show_in_rest'      => true,
			'single'            => true,
			'type'              => 'string',
			'default'           => 'Default',
			'revisions_enabled' => true,
		)
	);
  1. Go to a page as an admin and check you can connect a paragraph to the custom field.
  2. Insert a filter to modify the manage_block_bindings capability and disable it:
function restrict_edit_block_binding_cap( $caps, $cap ) {
	if ( 'edit_block_binding' === $cap ) {
		return array( 'do_not_allow' );
	}
	return $caps;
}

add_filter( 'map_meta_cap', 'restrict_edit_block_binding_cap', 10, 4 );
  1. Go to the page and check you can't create the connections anymore.

@SantosGuillamot SantosGuillamot changed the title Block Bindings: Map manage_block_bindings capability Block Bindings: Map edit_block_binding capability Oct 15, 2024
@SantosGuillamot SantosGuillamot force-pushed the update/bindings-capability-filter-mapping branch from 322766e to bd0b904 Compare October 15, 2024 11:20
if ( empty( $editor_settings['canUpdateBlockBindings'] ) ) {
$editor_settings['canUpdateBlockBindings'] = current_user_can( 'manage_options' );
function gutenberg_add_can_update_block_bindings_editor_setting( $editor_settings, $block_editor_context ) {
if ( ! isset( $editor_settings['canUpdateBlockBindings'] ) ) {
Copy link
Contributor Author

@SantosGuillamot SantosGuillamot Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using empty was wrong because it could be false and that is a valid value. This means we were overriding the setting from core even if it was defined there.

@SantosGuillamot
Copy link
Contributor Author

Migrating the code triggered a bug where the attributes panel is not shown in custom post types when Gutenberg plugin is not active. This is because the mapping capabilities logic wasn't correct. e2e tests passed because that logic was being overridden in Gutenberg.

I've started a PR in core trying to address that: link.

@SantosGuillamot SantosGuillamot marked this pull request as ready for review October 15, 2024 12:40
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: SantosGuillamot <santosguillamot@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant