Skip to content

Instantly share code, notes, and snippets.

@stokesman
Last active August 14, 2023 16:39
Show Gist options
  • Save stokesman/af6cf3a3f9d068e21832084141a81c05 to your computer and use it in GitHub Desktop.
Save stokesman/af6cf3a3f9d068e21832084141a81c05 to your computer and use it in GitHub Desktop.
WP: hack to keep the Block library/Inserter open unless manually closed.
<?php
/**
* Plugin Name: Block Library Disdialoged
* Description: Hack to keep the Block library/Inserter open unless manually closed.
* Version: 0.2.0
* License: GPL-2.0-or-later
*/
add_action( 'admin_footer', function() {
// Bails unless on a block editor screen
if ( ! get_current_screen()->is_block_editor() ) return;
?>
<script>
const ogHasFocus = document.__proto__.hasFocus;
document.addEventListener('focusout', e => {
const wasWithinInserter = !! e.target?.closest('[aria-label="Block Library"]');
if ( wasWithinInserter )
document.__proto__.hasFocus = () => {
document.__proto__.hasFocus = ogHasFocus;
return false;
}
})
</script>
<?php
}, 1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment