Skip to content

Instantly share code, notes, and snippets.

@akiya64
Created October 24, 2023 11:11
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 akiya64/a4342b7a6b72ec780ec47aa1ebec8404 to your computer and use it in GitHub Desktop.
Save akiya64/a4342b7a6b72ec780ec47aa1ebec8404 to your computer and use it in GitHub Desktop.
Redirect from Gutenberg Block editor
let hasRedirectSet
wp.data.subscribe(()=>{
const { isAutosavingPost,
didPostSaveRequestSucceed,
getCurrentPostAttribute } = wp.data.select('core/editor')
if ( !isAutosavingPost()
&& !hasRedirectSet
&& didPostSaveRequestSucceed()
&& getCurrentPostAttribute('status') === 'publish' ) {
hasRedirectSet = true
setTimeout(() => window.location.href = getPermalink(), 0);
}
})
jQuery(($) => {
$(document).ready( $ =>{
const panel = $('.editor-post-publish-panel__toggle').get(0)
const callback = mutations => {
mutations.forEach( mutation => {
if( mutation.oldValue ){
// Disable check box
$('.editor-post-publish-panel__footer .components-checkbox-control__input')
.attr('disabled', 'disabled')
$('.editor-post-publish-button').click(() =>{
$('#editor')
.css('pointer-events', 'none')
.keydown( () => false )
})
}
})
} // end callback
const observer = new MutationObserver( callback )
observer.observe( panel, {
attributes: true,
attributeFilter: ["aria-expanded"],
attributeOldValue: true
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment