Created
October 24, 2023 11:11
-
-
Save akiya64/a4342b7a6b72ec780ec47aa1ebec8404 to your computer and use it in GitHub Desktop.
Redirect from Gutenberg Block editor
This file contains hidden or 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
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