-
Notifications
You must be signed in to change notification settings - Fork 6
Description
Discussed in #383
Originally posted by troychaplin July 31, 2025
While the Gutenberg editor provides powerful tools for block development, it does not currently offer a built-in, officially supported mechanism for validating block attributes. That doesn’t mean developers need to reach for third-party libraries like Yup or other schema validation tools just to ensure data integrity.
What if I told you there’s already a lightweight and effective way to validate block attributes—whether from core blocks or custom ones, using just six functions available in the core/editor data store?
In this article, I’ll walk through how to leverage the following functions along with some straightforward JavaScript to create a robust validation system in the block editor, complete with error messaging and user feedback:
lockPostSaving
unlockPostSaving
lockPostAutosaving
unlockPostAutosaving
disablePublishSidebar
enablePublishSidebar
By using these block editor data store actions strategically, you can prevent publishing or autosaving when blocks are in an invalid state, without introducing external dependencies or complex integrations.
--
Note for editorial review: I’m aware that direct links to external repositories under a personal GitHub account are discouraged. I’d like to clarify the policy around referencing plugins: is it acceptable to reference or build the article around a plugin hosted in the WordPress.org Plugin Directory?
For context, I’ve developed a plugin that prevents publishing when accessibility issues are detected. While this article is not intended as a promotional piece, the same underlying validation techniques apply broadly to any block attribute. I’m happy to adjust the angle depending on what’s allowed.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status