Skip to content

Instantly share code, notes, and snippets.

@gsgoraya
Last active December 12, 2019 06:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsgoraya/79a3ff70d9cdd2e76cac97e1486668cb to your computer and use it in GitHub Desktop.
Save gsgoraya/79a3ff70d9cdd2e76cac97e1486668cb to your computer and use it in GitHub Desktop.
// insert the code inside this block
$('a#ct-edit-template-builder, a#ct-edit-template-builder-parent').on('click', function(e) {
.......
.......
.......
.......
// following is the code to be inserted at the end of this block.
// if it is a newly created post, still in draft mode, then have it published before the oxygenbuilder opens
if(wp.data.select('core/editor').getCurrentPost().status === 'auto-draft') {
e.preventDefault();
var unsubscribe = wp.data.use(() => {})['stores']['core/edit-post'].store.subscribe(function(e) {
if(wp.data.use(() => {})['stores']['core/edit-post'].store.getState().metaBoxes.isSaving === false) {
location.href = me.attr('href');
unsubscribe();
}
});
// trigger the post update
wp.data.dispatch('core/editor').savePost();
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment