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

Snippet: How to lock blocks and prevent your users from unlocking them #344

Closed
bph opened this issue Nov 21, 2024 · 6 comments
Closed

Snippet: How to lock blocks and prevent your users from unlocking them #344

bph opened this issue Nov 21, 2024 · 6 comments

Comments

@bph
Copy link
Collaborator

bph commented Nov 21, 2024

Discussed in #342

Originally posted by ndiego November 18, 2024
This snippet would provide a very brief overview of the Block Locking API and then show developers how to prevent unlocking in specific contexts:

Post types:

add_filter( 'block_editor_settings_all', function( $settings, $context ) {
    if ( $context->post && 'page' === $context->post->post_type ) {
        $settings['canLockBlocks'] = false;
    }

    return $settings;
}, 10, 2 );

User permissions:

add_filter( 'block_editor_settings_all', function( $settings ) {
    $settings['canLockBlocks'] = current_user_can( 'edit_theme_options' );

    return $settings;
} );

The snippet will also show how to disable access to the Code Editor, so users cannot manipulate the attributes directly.

@ndiego
Copy link
Member

ndiego commented Dec 7, 2024

This snippet is ready for its first review. Here's the draft: https://docs.google.com/document/d/1ok6K0cvpCSMwkOgs_lFWC0xCTjyCgMPZaMuocF9C87o/edit?tab=t.0

@ndiego ndiego moved this from In Progress to Needs 1st review in Developer Blog Content Board Dec 7, 2024
@bph
Copy link
Collaborator Author

bph commented Dec 9, 2024

A nice, conscise 360° on Block locking and how to control it. Made an editing suggestion and also suggested another link to shorted the UI paragraph, to keep it even more conscise :-)

@bph bph moved this from Needs 1st review to Done w/ 1st Review in Developer Blog Content Board Dec 9, 2024
@ndiego
Copy link
Member

ndiego commented Dec 9, 2024

A nice, conscise 360° on Block locking and how to control it. Made an editing suggestion and also suggested another link to shorted the UI paragraph, to keep it even more conscise :-)

Perfect, thanks. This allowed me to trim the majority of that paragraph.

@ndiego ndiego moved this from Done w/ 1st Review to Needs 2nd review in Developer Blog Content Board Dec 9, 2024
@ryanwelcher
Copy link

Second review done. Ready to go!

@ryanwelcher ryanwelcher moved this from Needs 2nd review to Done w/ 2nd review in Developer Blog Content Board Dec 9, 2024
@bph
Copy link
Collaborator Author

bph commented Dec 9, 2024

Pre-publishing checklist: (updated 1/29/2024)

  • Post Title and subheaders in sentence case
  • Are Category or Categories selected?
  • Are Tags identifies?
  • Is there an explicit Excerpt?
  • Are all images files uploaded to the media library
  • Do all images have an alt-text?
  • For TOC us the Pattern under Developer Blog > Table of contents
  • Assign or upload a featured image
  • Props added? (See Guidelines)
  • add copy for a social post as comment to this issue (example)
    🙌 Publish! 📗

Post-publishing checklist

  • add Props for reviews to #props channel in WP Slack (Example) (use Slack handles)
  • Add the label "post to social" to the issue
  • close the issue with a comment to link to the published post
  • close the accompanying discussion with the link to the published post.

@ndiego
Copy link
Member

ndiego commented Dec 9, 2024

The snippet has been published: https://developer.wordpress.org/news/snippets/how-to-lock-wordpress-blocks-and-prevent-unlocking/

Social Copy:

In this article on the Developer Blog, Learn how to lock blocks in WordPress and prevent your users from unlocking them. The code snippets provided are great for maintaining design consistency.

@ndiego ndiego closed this as completed Dec 9, 2024
@github-project-automation github-project-automation bot moved this from Done w/ 2nd review to Ready to publish in Developer Blog Content Board Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Ready to publish
Development

No branches or pull requests

3 participants