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

Pattern overrides: ensure an additional meta capability for override capability #57940

Open
annezazu opened this issue Jan 17, 2024 · 4 comments
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Type] Enhancement A suggestion for improvement.

Comments

@annezazu
Copy link
Contributor

Pulling this question out of yesterday's hallway hangout on WordPress 6.5:

Question from Jorbin: “Do pattern overrides include capability checks so that it is possible for someone to be able to use the pattern and the overrides without editing the pattern as a whole? What I am thinking is having a meta capability for managing the pattern and then a separate meta cap for doing overrides.”

This was underscored by others on the call as important to have. You can listen to the question/discussion starting here. It's only 1-2 minutes! Can someone chime in to clarify? @talldan as we chatted a bit about this. @aaronjorbin so you know this has been followed up on.

@annezazu annezazu added [Type] Enhancement A suggestion for improvement. [Type] Question Questions about the design or development of the editor. [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) labels Jan 17, 2024
@aaronjorbin
Copy link
Member

Thanks so much for kicking this off @annezazu!

To add some additional context around this, one use case that I'm thinking of is a related posts block on a media site. For that you might want:

  1. A set of users who can manage the pattern as a whole.
  2. A set of users who should be able to do the overrides.
  3. A set of users who can only add the block and not add any overrides whatsoever.

@talldan
Copy link
Contributor

talldan commented Jan 18, 2024

Thanks for the question @aaronjorbin!

We're presently using the existing capabilities at the moment:

  1. The users who can edit the original pattern haven't changed, it's still the same requirements for editing the wp_block post type. Anyone that can do that can also define the parts of the pattern can be overridden.
  2. For inserting a pattern block instance and setting override values in that instance, that comes down to the permissions of the post the pattern is inserted into. The overrides are considered content of the post (the data is saved as an attribute of the pattern block, so doesn't affect the original pattern in any way).
  3. This one isn't currently possible. Given the way 1 & 2 are implemented, I think this would mean capabilities that allow inserting blocks but not editing the block content. It could be something to think about for the future, but maybe more as a generic feature (not just patterns) that might apply to any block types in connection with block locking or similar features.

@kraftner
Copy link

Related: #28895 (comment)

@gziolo gziolo removed the [Type] Question Questions about the design or development of the editor. label Sep 9, 2024
@gziolo
Copy link
Member

gziolo commented Sep 9, 2024

I don't think this issue should have the [Type] Question anymore. It contains enough context to validate the idea and start exploring possible solutions. In fact, it's time to establish some best practices for these new power features, as we recently ran into a similar challenge of how to expose the UI for managing Block Bindings in the editor only to user that have proper permissions:

I also learned that so far in the editor, some features are gated through block editor setting, like Block Locking Settings in WordPress 6.0. While it works pretty well, it isn't the simplest thing to discover, see example:

add_filter(
	'block_editor_settings_all',
	function( $settings, $context ) {
		// Allow for the Editor role and above - https://wordpress.org/support/article/roles-and-capabilities/.
		$settings['canLockBlocks'] = current_user_can( 'delete_others_posts' );

		// Only enable for specific user(s).
		$user = wp_get_current_user();
		if ( in_array( $user->user_email, [ '[email protected]' ], true ) ) {
			$settings['canLockBlocks'] = false;
		}

		// Disable for posts/pages.
		if ( $context->post && $context->post->post_type === 'page' ) {
			$settings['canLockBlocks'] = false;
		}

		return $settings;
	},
	10,
	2
);

Interestingly enough, by design, this feature is enabled in the UI through the client-side setting that only gets modified if a different setting is set on the server through this filter:

// Allows to disable block locking interface.
canLockBlocks: true,

This issue is also related to an existing issue for regular patterns:

@gziolo gziolo added the [Feature] Extensibility The ability to extend blocks or the editing experience label Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Feature] Synced Patterns Related to synced patterns (formerly reusable blocks) [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

5 participants