Last active
August 29, 2015 14:02
-
-
Save norcross/60a59f38b32b7a3547c3 to your computer and use it in GitHub Desktop.
add a dropdown with all node IDs in the admin bar
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 | |
add_action( 'wp_before_admin_bar_render', 'rkv_node_ids_to_toolbar' ); | |
/** | |
* run throught all available nodes in the global wp_admin_bar | |
* and create a multi level dropdown | |
* | |
* used for when you need to remove one (or more) | |
*/ | |
function rkv_node_ids_to_toolbar() { | |
global $wp_admin_bar; | |
$all_toolbar_nodes = $wp_admin_bar->get_nodes(); | |
if ( $all_toolbar_nodes ) { | |
// add a top-level Toolbar item called "Node Id's" to the Toolbar | |
$args = array( | |
'id' => 'node_ids', | |
'title' => 'Node ID\'s' | |
); | |
$wp_admin_bar->add_node( $args ); | |
// add all current parent node id's to the top-level node. | |
foreach ( $all_toolbar_nodes as $node ) { | |
if ( isset($node->parent) && $node->parent ) { | |
$args = array( | |
'id' => 'node_id_'.$node->id, // prefix id with "node_id_" to make it a unique id | |
'title' => $node->id, | |
'parent' => 'node_ids' | |
// 'href' => $node->href, | |
); | |
// add parent node to node "node_ids" | |
$wp_admin_bar->add_node($args); | |
} | |
} | |
// add all current Toolbar items to their parent node or to the top-level node | |
foreach ( $all_toolbar_nodes as $node ) { | |
$args = array( | |
'id' => 'node_id_'.$node->id, // prefix id with "node_id_" to make it a unique id | |
'title' => $node->id, | |
// 'href' => $node->href, | |
); | |
if ( isset($node->parent) && $node->parent ) { | |
$args['parent'] = 'node_id_'.$node->parent; | |
} else { | |
$args['parent'] = 'node_ids'; | |
} | |
$wp_admin_bar->add_node($args); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment