WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Class Reference/WP Admin Bar

Role of WP_Admin_Bar

WP_Admin_Bar is WordPress' class for generating the Toolbar that lines the top of WordPress sites when signed in. This class can be hooked and modified to add or remove options that appear in the admin bar.

The Toolbar replaces the Admin Bar since WordPress Version 3.3.

Usage

This class is used internally by WordPress to create an object called $wp_admin_bar. Most modifications to WordPress toolbar will generally be done by modifying the $wp_admin_bar object that is passed through the admin_bar_menu hook.

Example:

add_action( 'admin_bar_menu', 'modify_admin_bar' );

function modify_admin_bar( $wp_admin_bar ){
  // do something with $wp_admin_bar;
}

Methods and Properties

Properties

$nodes
An associative array containing the toolbar items (also called "nodes").
$bound
$user

Methods

__get()
initialize()
add_menu()
Add an item into the Admin bar.
remove_menu()
Remove an item from the Admin bar.
add_node()
Add a node to the menu.
_set_node()
get_node()
Gets a node.
_get_node()
get_nodes()
Gets nodes.
_get_nodes()
add_group()
Add a group to a menu node.
remove_node()
Remove any pre-defined node from the object.
_unset_node()
render()
_bind()
_render()
_render_container()
_render_group()
_render_item()
recursive_render()
add_menus()

Hooks

  • admin_bar_init - This action hook is called at the very end of initialization.
  • add_admin_bar_menus - This action hook is called at the end of the public add_menus() method.

Please note that the hooks are available for modifying this class but they have very limited use. In many cases, you will simply want to modify the $wp_admin_bar object.

Source File

WP_Admin_Bar is located in wp-includes/class-wp-admin-bar.php.

Resources

Related

Toolbar API

See also index of Class Reference and index of Function Reference.