Last active
February 7, 2020 15:04
-
-
Save jomurgel/8c12fcc391667b0ee48f7b4794533fd4 to your computer and use it in GitHub Desktop.
Lock/Unlock Saving for Gutenberg
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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