Last active
August 7, 2023 17:59
-
-
Save dlh01/c99a48d888ca77a0f98a9209da37532d to your computer and use it in GitHub Desktop.
Infinite loop test theme
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
<?php | |
add_action( | |
'enqueue_block_editor_assets', | |
function () { | |
wp_enqueue_script( | |
'title-checker-js', | |
get_theme_file_uri( 'title-checker.js' ), | |
[], | |
null, | |
true | |
); | |
} | |
); |
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
<?php | |
// Nothing |
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
/* | |
Theme Name: Infinite Loop Test Theme | |
*/ |
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
const { | |
i18n: { __ }, | |
plugins: { | |
registerPlugin, | |
}, | |
data: { | |
useSelect, | |
useDispatch, | |
}, | |
} = wp; | |
function TitleChecker() { | |
const postTitle = useSelect((select) => select('core/editor').getEditedPostAttribute('title')); | |
const titleIsOk = 0 < postTitle.length; | |
const { lockPostSaving, unlockPostSaving } = useDispatch('core/editor'); | |
const { createWarningNotice, removeNotice } = useDispatch('core/notices'); | |
/** | |
* If post title is empty, then lock post saving and display a warning notice | |
* else release lock and remove notice. | |
*/ | |
if (! titleIsOk) { | |
lockPostSaving('title-empty-lock'); | |
createWarningNotice( | |
__('Please enter a headline before publishing.', 'my-textdomain'), | |
{ id: 'title-empty-lock', isDismissible: false }, | |
); | |
} else { | |
unlockPostSaving('title-empty-lock'); | |
removeNotice('title-empty-lock'); | |
} | |
// On the site where this issue occurred, a <PluginPrePublishPanel> was rendered here. | |
return null; | |
} | |
registerPlugin('empty-title-check', { render: TitleChecker }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment