Site icon Hip-Hop Website Design and Development

Add pre-publish situations to the block editor

The introduction of the Block Editor killed all plugins which provided publishing situations, reminiscent of minimal phrase counts, featured picture necessities and so forth.

However the Block Editor did introduce the pre-publish checks:

Lovely. How can we disable the Publish button till a set quantity of situations have been fulfilled?

Examples of 4 (very) totally different situations:

  1. Minimal phrase rely (instance: 500 phrases)
  2. Min/max tags (instance: 3-5 tags)
  3. Min class (that is not uncategorized)
  4. Featured picture is assigned

What we’ve thus far

As anticipated, the documentation is non-existent. However leads are scattered throughout the net.

In core/editor, we will use .lockPostSaving() to disabled the Publish button, and unlock it through .unlockPostSaving().

We will add a panel to the pre-publish display screen through PluginPrePublishPanel. Instance (by MadMaardigan):

var PluginPrePublishPanel = wp.editPost.PluginPrePublishPanel;
var registerPlugin = wp.plugins.registerPlugin;

perform Element() {
    // lock submit saving
    wp.knowledge.dispatch('core/editor').lockPostSaving()

    // unlock submit saving
    // wp.knowledge.dispatch('core/editor').unlockPostSaving()

    return wp.aspect.createElement(
        PluginPrePublishPanel,
        {   
            className: 'my-plugin-publish-panel',
            title: 'Panel title',
            initialOpen: true,
        },  
        'Panel content material'
    );  
}

registerPlugin( 'my-plugin', {
  render: Element,
});

It really works:

And we’ve nice discussions on GitHub: #7020, #7426, #13413, #15568, #10649