Last active
August 14, 2023 16:39
-
-
Save stokesman/af6cf3a3f9d068e21832084141a81c05 to your computer and use it in GitHub Desktop.
WP: hack to keep the Block library/Inserter open unless manually closed.
This file contains 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 | |
/** | |
* 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