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

Online Workshop - A Beginners Guide to Block Locking in Block Themes #918

Closed
6 tasks done
jonathanbossenger opened this issue Sep 2, 2022 · 7 comments
Closed
6 tasks done
Assignees
Labels
[Content] Needs Co-host Online Workshops in need of a co-host.

Comments

@jonathanbossenger
Copy link
Collaborator

jonathanbossenger commented Sep 2, 2022

Event Details

https://gutenbergtimes.com/how-to-disable-theme-features-and-lock-block-templates-for-full-site-editing-in-wordpress/
https://make.wordpress.org/core/2022/01/08/locking-blocks-in-wordpress-5-9/
https://make.wordpress.org/core/2022/05/05/block-locking-settings-in-wordpress-6-0/
https://developer.wordpress.org/block-editor/reference-guides/block-api/block-templates/#locking

One of the concerns that developers voiced regarding Block Themes and the Site Editor is that it gives users too much freedom to edit the site design, select colors, or modify blocks. More complex websites with many editors and departments who produce content need guardrails to enforce publishing standards and adherence to brand color schemas and design systems.

In this session, we'll be looking at the Block Locking options available in WordPress, and show you how you can restrict your Block Themes from user interference.

Online Workshop Checklist:

@jonathanbossenger
Copy link
Collaborator Author

Live stream #1, attempting to use and think of a use case for locking blocks in template files.

https://www.twitch.tv/videos/1583424561

Question that came out of it, what is the use case for locking blocks in template files.

@jonathanbossenger
Copy link
Collaborator Author

Additional reading that came out of the live stream: WordPress/gutenberg#37489

@jonathanbossenger
Copy link
Collaborator Author

@mrfoxtalbot has kindly offered to co-host.

@jonathanbossenger
Copy link
Collaborator Author

Additional reading: https://make.wordpress.org/core/2022/02/09/core-editor-improvement-curated-experiences-with-locking-apis-theme-json/

@jonathanbossenger
Copy link
Collaborator Author

Prep notes

  • Review how to disable settings
    • Disable the ability to change the post title fontStyle and fontWeight
  • Locking blocks from the editor
    • Edit Home Template
    • Review how locking works
      • Either from the list view
      • Or from the block settings
    • Review the options
      • Lock all = movement and removal
      • Or just movement
      • Or just removal
    • Review the code
  • Lock the Post Title and the Post Featured Image
  • Overwrite the current theme files
  • Show how to limit the block locking capabilities for admins in functions.php
  • Clone the current theme
  • Install the cloned theme on the client site
  • Show how locked blocks cannot be removed or moved

@jonathanbossenger
Copy link
Collaborator Author

Code snippets

"blocks": {
	"core/post-title": {
		"typography": {
			"fontStyle": false,
			"fontWeight": false
		}
	}
}
<?php
// https://wordpress.org/support/article/roles-and-capabilities/

add_filter( 'block_editor_settings_all', 'wp_learn_enable_block_locking', 10 );
function wp_learn_enable_block_locking( $settings ) {
	// Allow for the Administrators
	$settings['canLockBlocks'] = current_user_can( 'install_themes' );

	// Disable for specific Administrators by email.
	$restricted_admins = array( 'content@wordpress.test' );
	$user              = wp_get_current_user();
	if ( in_array( $user->user_email, $restricted_admins, true ) ) {
		$settings['canLockBlocks'] = false;
	}

	return $settings;
}

@jonathanbossenger
Copy link
Collaborator Author

jonathanbossenger commented Sep 13, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Content] Needs Co-host Online Workshops in need of a co-host.
Projects
None yet
Development

No branches or pull requests

1 participant