class-cleanup-admin-bar.php
| 1 | <?php |
| 2 | |
| 3 | namespace ASENHA\Classes; |
| 4 | |
| 5 | /** |
| 6 | * Class for Clean Up Admin Bar module |
| 7 | * |
| 8 | * @since 6.9.5 |
| 9 | */ |
| 10 | class Cleanup_Admin_Bar { |
| 11 | /** |
| 12 | * Modify admin bar menu for Admin Interface >> Hide or Modify Elements feature |
| 13 | * |
| 14 | * @param $wp_admin_bar object The admin bar. |
| 15 | * @since 1.9.0 |
| 16 | */ |
| 17 | public function modify_admin_bar_menu( $wp_admin_bar ) { |
| 18 | $options = get_option( ASENHA_SLUG_U, array() ); |
| 19 | // Hide WP Logo Menu |
| 20 | if ( array_key_exists( 'hide_ab_wp_logo_menu', $options ) && $options['hide_ab_wp_logo_menu'] ) { |
| 21 | remove_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 ); |
| 22 | // priority needs to match default value. Use QM to reference. |
| 23 | } |
| 24 | // Hide Customize Menu |
| 25 | if ( array_key_exists( 'hide_ab_customize_menu', $options ) && $options['hide_ab_customize_menu'] ) { |
| 26 | remove_action( 'admin_bar_menu', 'wp_admin_bar_customize_menu', 40 ); |
| 27 | // priority needs to match default value. Use QM to reference. |
| 28 | } |
| 29 | // Hide Updates Counter/Link |
| 30 | if ( array_key_exists( 'hide_ab_updates_menu', $options ) && $options['hide_ab_updates_menu'] ) { |
| 31 | remove_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 50 ); |
| 32 | // priority needs to match default value. Use QM to reference. |
| 33 | } |
| 34 | // Hide Comments Counter/Link |
| 35 | if ( array_key_exists( 'hide_ab_comments_menu', $options ) && $options['hide_ab_comments_menu'] ) { |
| 36 | remove_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 ); |
| 37 | // priority needs to match default value. Use QM to reference. |
| 38 | } |
| 39 | // Hide New Content Menu |
| 40 | if ( array_key_exists( 'hide_ab_new_content_menu', $options ) && $options['hide_ab_new_content_menu'] ) { |
| 41 | remove_action( 'admin_bar_menu', 'wp_admin_bar_new_content_menu', 70 ); |
| 42 | // priority needs to match default value. Use QM to reference. |
| 43 | } |
| 44 | // Hide 'Howdy' text |
| 45 | if ( array_key_exists( 'hide_ab_howdy', $options ) && $options['hide_ab_howdy'] ) { |
| 46 | // Remove the whole my account sectino and later rebuild it |
| 47 | remove_action( 'admin_bar_menu', 'wp_admin_bar_my_account_item', 7 ); |
| 48 | $current_user = wp_get_current_user(); |
| 49 | $user_id = get_current_user_id(); |
| 50 | $profile_url = get_edit_profile_url( $user_id ); |
| 51 | $avatar = get_avatar( $user_id, 26 ); |
| 52 | // size 26x26 pixels |
| 53 | $display_name = $current_user->display_name; |
| 54 | $class = ( $avatar ? 'with-avatar' : 'no-avatar' ); |
| 55 | $wp_admin_bar->add_menu( array( |
| 56 | 'id' => 'my-account', |
| 57 | 'parent' => 'top-secondary', |
| 58 | 'title' => $display_name . $avatar, |
| 59 | 'href' => $profile_url, |
| 60 | 'meta' => array( |
| 61 | 'class' => $class, |
| 62 | ), |
| 63 | ) ); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Hide the Help tab and drawer |
| 69 | * |
| 70 | * @since 4.5.0 |
| 71 | */ |
| 72 | public function hide_help_drawer() { |
| 73 | if ( is_admin() ) { |
| 74 | $screen = get_current_screen(); |
| 75 | $screen->remove_help_tabs(); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | } |
| 80 |