Created
April 1, 2020 17:35
-
-
Save MervinHernandez/17d42dc921bab343b08f5beaf5bf9347 to your computer and use it in GitHub Desktop.
TOGGLE WP Admin Notices
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 | |
// -- Header - TOGGLE Hide Admin Notices | |
// -- -- ADD Script and Styling | |
function wm_admin_notices_toggle_script() { ?> | |
<!-- JS for Admin Notices Hide --> | |
<script> | |
function toggle_visibility(className) { | |
//alert ('you clicked it'); | |
elements = document.getElementsByClassName('notice'); | |
for (var i = 0; i < elements.length; i++) { | |
elements[i].style.display = elements[i].style.display == 'block' ? 'none' : 'block'; | |
} | |
} | |
</script> | |
<!-- Style for Admin Notices Hide --> | |
<style> | |
.notice {display:none;} | |
#wpadminbar #wp-admin-bar-notices .ab-icon:before { | |
content: "\f348"; | |
} | |
</style> | |
<?php } | |
add_action( 'admin_head', 'wm_admin_notices_toggle_script' ); | |
// -- -- ADMIN BAR Toggle Button to show Admin Notices | |
function wm_admin_notices_toggle_button( \WP_Admin_Bar $bar ) | |
{ | |
$bar->add_menu( array( | |
'id' => 'notices', | |
'title' => '<span class="ab-icon"></span>'.__( 'Show Admin Notices', 'wingman-avionics' ), | |
'href' => '#', | |
'meta' => array( | |
'target' => '_self', | |
'title' => __( 'Toggle showing admin notices on off', 'wingman-avionics' ), | |
'onclick' => 'toggle_visibility()' | |
), | |
) ); | |
}; | |
add_action( 'admin_bar_menu','wm_admin_notices_toggle_button', 910 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment