GeneratorsAdminToolbar Node

Toolbar Node Generator

Add a custom node to the admin bar, wire up its dropdown children, and clear the core nodes this site does not use.

acme-tools.php
Saved just now
The parent node
Show a count bubble
Child nodes
3 items
Settingsacme-settings
Nonce
Clear cacheacme-clear-cache
Nonce
Documentationacme-docs
Nonce
Remove core nodes
1 node removed
<?php
// Generated with WP CodeKit — powered by GrowQuest (https://growquest.io).
/**
 * Plugin Name:       Acme toolbar node
 * Description:       Adds the acme-tools node to the admin bar.
 * Version:           1.0.0
 * Requires PHP:      7.4
 * Text Domain:       acme
 */

defined( 'ABSPATH' ) || exit;

/**
 * Add the Acme node to the toolbar.
 *
 * @param WP_Admin_Bar $wp_admin_bar The toolbar instance.
 */
function acme_toolbar_node( $wp_admin_bar ) {
	if ( ! current_user_can( 'edit_others_posts' ) ) {
		return;
	}

	$wp_admin_bar->add_node(
		array(
			'id'    => 'acme-tools',
			'title' => __( 'Acme', 'acme' ),
			'href'  => esc_url( admin_url( 'options-general.php?page=acme-toolkit' ) ),
			'meta'  => array(
				'title' => __( 'Acme shortcuts', 'acme' ),
			),
		)
	);

	$wp_admin_bar->add_node(
		array(
			'id'     => 'acme-settings',
			'parent' => 'acme-tools',
			'title'  => __( 'Settings', 'acme' ),
			'href'   => esc_url( admin_url( 'options-general.php?page=acme-toolkit' ) ),
		)
	);

	$wp_admin_bar->add_node(
		array(
			'id'     => 'acme-clear-cache',
			'parent' => 'acme-tools',
			'title'  => __( 'Clear cache', 'acme' ),
			'href'   => wp_nonce_url( admin_url( 'admin-post.php?action=acme_clear_cache' ), 'acme_acme-clear-cache' ),
		)
	);

	$wp_admin_bar->add_node(
		array(
			'id'     => 'acme-docs',
			'parent' => 'acme-tools',
			'title'  => __( 'Documentation', 'acme' ),
			'href'   => esc_url( 'https://example.com/docs' ),
		)
	);
}
add_action( 'admin_bar_menu', 'acme_toolbar_node', 80 );

/**
 * Clear the core nodes this site does not use.
 *
 * @param WP_Admin_Bar $wp_admin_bar The toolbar instance.
 */
function acme_toolbar_cleanup( $wp_admin_bar ) {
	$wp_admin_bar->remove_node( 'wp-logo' );
}
add_action( 'admin_bar_menu', 'acme_toolbar_cleanup', 999 );