settings = (array) $settings; $this->groups = (array) $groups; } function admin_menu() { add_options_page( 'Admin Cleanup', 'Admin Cleanup', 'manage_options', 'admin-cleanup', array( $this, 'settings_page' ) ); } function parse_menus() { global $menu, $submenu; $temp_menu = array(); foreach ( $menu as $key => $data ) { $id = $data[2]; $temp_menu[ $id ] = $data; if ( isset( $submenu[ $id ] ) ) { $temp_menu[ $id ]['children'] = $submenu[ $id ]; } } // Build the final menu foreach ( $temp_menu as $id => $data ) { if ( isset( $data[5] ) ) { $id = $data[5]; // use the CSS ID if available } $this->menu[ $id ] = $data; } } function admin_bar_menu( $wp_admin_bar ) { $this->parse_menus(); if ( false !== array_search( 'move', $this->settings ) ) { $args = array( 'id' => 'admin-cleanup', 'title' => 'Menu', 'parent' => false, 'href' => '', 'meta' => array(), ); $wp_admin_bar->add_node( $args ); } foreach ( $this->groups as $group_slug => $group_name ) { if ( false !== array_search( $group_slug, $this->settings ) ) { $args = array( 'id' => 'admin-cleanup-' . $group_slug, 'title' => $group_name, 'parent' => false, 'href' => '', 'meta' => array(), ); $wp_admin_bar->add_node( $args ); } } foreach ( $this->settings as $key => $val ) { if ( 'hide' == $val || empty( $this->menu[ $key ] ) ) { continue; } $group = ( 'move' == $val ) ? 'admin-cleanup' : 'admin-cleanup-' . $val; $the_menu = $this->menu[ $key ]; $the_href = menu_page_url( $the_menu[2], false ); $the_href = empty( $the_href ) ? $the_menu[2] : $the_href; $the_id = /*'ac-' . */$key; $args = array( 'id' => $the_id, 'title' => $the_menu[0], 'parent' => $group, 'href' => $the_href, ); $wp_admin_bar->add_node( $args ); if ( isset( $the_menu['children'] ) ) { foreach ( $the_menu['children'] as $key => $child ) { $the_href = menu_page_url( $child[2], false ); $the_href = empty( $the_href ) ? $child[2] : $the_href; $args = array( 'id' => $the_id . '-' . $key, 'title' => $child[0], 'parent' => $the_id, 'href' => $the_href, ); $wp_admin_bar->add_node( $args ); } } } } function hide_menu_items() { ?>