Skip to content

Instantly share code, notes, and snippets.

@jomurgel
Last active February 7, 2020 15:04
Show Gist options
  • Save jomurgel/8c12fcc391667b0ee48f7b4794533fd4 to your computer and use it in GitHub Desktop.
Save jomurgel/8c12fcc391667b0ee48f7b4794533fd4 to your computer and use it in GitHub Desktop.
Lock/Unlock Saving for Gutenberg
/* global wp */
const {
data: {
dispatch,
},
plugins: {
registerPlugin,
},
} = wp;
// Quick and dirty lock/unlock of post saving.
function RequireField() {
// Lock post saving.
dispatch('core/editor').lockPostSaving();
// Do some check.
console.log('locked');
// Unlock — Eventually when criteria is met.
setTimeout(() => {
dispatch('core/editor').unlockPostSaving();
// Unlocked.
console.log('unlocked');
}, 5000);
return false;
}
registerPlugin('plugin-name-here', {
render: RequireField,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment