get_nodes(); if ( $all_nodes ) { if ( WP_DEBUG ) { $node_meta = array( 'title' => esc_html__( 'ABMP debug mode', 'ab-menu-packer' ) ); } else { $node_meta = ''; } $wp_admin_bar->add_node( array( 'id' => 'abmp-root', 'title' => '', 'meta' => $node_meta, ) ); foreach ( $all_nodes as $node ) { $node_count += 1; if ( in_array( $node->id, $excluding_ids, true ) ) { continue; } else if ( in_array( $node->parent, $excluding_ids, true ) ) { $excluding_ids[] = $node->id; } else { if ( !$node->parent ) { $wp_admin_bar->remove_node( $node->id ); } if ( WP_DEBUG ) { $node_meta = array( 'class' => 'abmp-item', 'title' => $node_count . ' ' . $node->id ); } else { $node_meta = array( 'class' => 'abmp-item' ); } $args = array( 'id' => 'abmp-' . $node->id, 'title' => strip_tags( $node->title ), 'href' => $node->href, 'meta' => $node_meta, ); if ( isset( $node->parent ) && $node->parent && $node->parent !== 'top-secondary' ) { $args['parent'] = 'abmp-' . $node->parent; } else { $args['parent'] = 'abmp-root'; } $wp_admin_bar->add_node( $args ); $packed += 1; } } if ( $packed == 0 ) { $args = array( 'id' => 'abmp-no-item', // translators: label when the menu is empty 'title' => '(' . strip_tags( __( 'no items', 'ab-menu-packer' ) ) .')', 'parent' => 'abmp-root', ); $wp_admin_bar->add_node( $args ); } abmp_hide_howdy( true ); if ( WP_DEBUG ) abmp_debug_menu( $all_nodes ); } } add_action( 'admin_notices', 'abmp_admin_notices' ); function abmp_admin_notices() { if ( WP_DEBUG ) { // translators: %s is plugin name $debug_notice1 = sprintf( esc_html__( '%1$s is currently working in debug mode, because WP_DEBUG is set to true.', 'ab-menu-packer' ), ABMP_NAME ); // translators: %s is the label for debug menu ('All Nodes ID') $debug_notice2 = sprintf( esc_html__( 'Each item in the menu has a title attribute including the node ID, and a debug menu %s containing all items\' node ID is displayed.', 'ab-menu-packer' ), '\'All Nodes\'' ); $class = 'notice notice-warning is-dismissible'; printf( '

%2$s
%3$s

', esc_attr( $class ), $debug_notice1, $debug_notice2 ); } } /** * Update 'my-account' node to hide Howdy text * * @since 0.5.1 * * @param boolean $hide */ function abmp_hide_howdy( $hide = true ) { global $wp_admin_bar; $user_id = get_current_user_id(); if ( $hide ) { $avatar = get_avatar( $user_id, 26 ); $wp_admin_bar->add_node( array( 'id' => 'my-account', 'title' => $avatar, ) ); } } /** * Show hierarchical menu with all nodes (for debug) * * @since 0.6.0 * * @param array $nodes */ function abmp_debug_menu( $nodes ) { global $wp_admin_bar; $args = array( 'id' => 'abmp-debug-root', 'title' => 'All Nodes', 'parent' => 'abmp-root', 'meta' => array( 'title' => esc_html__( 'ABMP Debug Menu', 'ab-menu-packer' ), ), ); $wp_admin_bar->add_node( $args ); $counter = 0; foreach ( $nodes as $node ) { $counter += 1; $args = array( 'id' => 'node_id_' . $node->id, 'title' => $counter . ' ' . $node->id, 'href' => $node->href, ); if ( isset( $node->parent ) && $node->parent ) { $args['parent'] = 'node_id_' . $node->parent; } else { $args['parent'] = 'abmp-debug-root'; } $wp_admin_bar->add_node($args); } }