Created
January 29, 2019 14:46
-
-
Save joshuafredrickson/3ca826a067b6844c214e1b25af4db31a to your computer and use it in GitHub Desktop.
WordPress: Move all admin notices and plugin nags to console
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
add_action('plugins_loaded', function() { | |
$action = is_user_admin() ? 'user_admin_notices' : 'admin_notices'; | |
add_action($action, function () { | |
ob_start(); | |
}); | |
add_action('all_admin_notices', function () { | |
$log = strip_tags(trim(ob_get_clean())); | |
if (!$log) { | |
return; | |
} | |
wp_register_script('admin-to-console', ''); | |
wp_enqueue_script('admin-to-console'); | |
wp_add_inline_script( | |
'admin-to-console', | |
'console.log(`'. $log .'`);' | |
); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dang that's a handy script!