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

How to disable specific heading levels in the Editor #338

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

How to disable specific heading levels in the Editor #338

bph opened this issue Nov 14, 2024 · 6 comments
Assignees
Labels

Comments

@bph
Copy link
Collaborator

bph commented Nov 14, 2024

Discussed in #323

Originally posted by ndiego October 22, 2024
This would be a snippet that provides an example of the heading-level curation options available in WordPress 6.7.

The snippet will show you how to disable H1, H5, and H6 in the Heading block for all users who are not administrators using PHP.

function example_modify_heading_levels_globally( $args, $block_type ) {

    $is_administrator = current_user_can( 'edit_theme_options' );

    if ( 'core/heading' !== $block_type || $is_administrator ) {
        return $args;
    }

    // Remove H1, H5, and H6.
    $args['attributes']['levelOptions']['default'] = [ 2, 3, 4 ];

    return $args;
}
add_filter( 'register_block_type_args', 'example_modify_heading_levels_globally', 10, 2 );
```</div>
@ndiego
Copy link
Member

ndiego commented Nov 14, 2024

The snippet is ready for a first review here: https://docs.google.com/document/d/1BOuO8eqqMfVae-wBzfItBOr5MMuuO0heY7_kJG07_OM/edit

@ndiego ndiego moved this from In Progress to Needs 1st review in Developer Blog Content Board Nov 14, 2024
@troychaplin
Copy link

@ndiego I reviewed this, had one minor comment. Great article, I upgraded to 6.7 today and remove an older block check in lieu of this function and it's working great!

@ndiego ndiego moved this from Needs 1st review to Needs 2nd review in Developer Blog Content Board Nov 15, 2024
@ndiego
Copy link
Member

ndiego commented Nov 15, 2024

This snippet is ready for a second review. The public preview is available here: https://developer.wordpress.org/news/?p=4727&post_type=snippets&preview=1&_ppp=a9ca7ab3d2

@bph
Copy link
Collaborator Author

bph commented Nov 15, 2024

Just reviewed and it's great. You can certainly publish it.

I added the checklistz here so we can evaluate if we need all the steps for snippets, too.

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 Nov 15, 2024

The post has been published here: https://developer.wordpress.org/news/snippets/how-to-disable-heading-levels-in-the-editor/

Social copy

WordPress 6.7 allows developers to restrict the heading levels that are available to users in Core blocks. Learn how in this code snippet on the WordPress Developer Blog.

@ndiego ndiego closed this as completed Nov 15, 2024
@github-project-automation github-project-automation bot moved this from Needs 2nd review to Ready to publish in Developer Blog Content Board Nov 15, 2024
@ndiego ndiego moved this from Ready to publish to Published (Done) in Developer Blog Content Board Nov 15, 2024
@ryanwelcher
Copy link

Social schedule for Nov 26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Published (Done)
Development

No branches or pull requests

4 participants