WP_Admin_Bar::add_node( array $args )
- Since
- 3.1.0, 4.5.0, 6.5.0
- Source
wp-includes/class-wp-admin-bar.php:124
Compatibility
- WordPress
- since 6.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$argsarray- Arguments for adding a node.
$idstringID of the item.$titlestringTitle of the node.$parentstringOptional. ID of the parent node.$hrefstringOptional. Link for the item.$groupbooldefault: falseOptional. Whether or not the node is a group.$metaarraydefault: emptyMeta data including the following keys: 'html', 'class', 'rel', 'lang', 'dir', 'onclick', 'target', 'title', 'tabindex', 'menu_title'.
Performance profile
How much work a call to WP_Admin_Bar::add_node() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 11–102
- Plugin surface
- None
- Called by
- 3
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 103.
Nothing here hands control to plugin code.
3 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
do_action()one call below WP_Admin_Bar::add_node()
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 68 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Admin_Bar::add_node() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!is_object($args) && empty($args) | 11–13 | none |
is_object($args) && empty($args) | 15–17 | get_object_vars() |
is_string($args) && !is_object($args) && empty($args) | 22 | func_get_arg(), parent() |
is_string($args) && is_object($args) && empty($args) | 26 | func_get_arg(), parent(), get_object_vars() |
!is_object($args) && !empty($args) && !isset([…]) | 30–34 | ->get_node(), wp_parse_args(), ->_set_node() |
!is_object($args) && !empty($args) && !isset([…]) | 34–38 | ->get_node(), get_object_vars(), wp_parse_args(), ->_set_node() |
is_object($args) && !empty($args) && !isset([…]) | 34–38 | get_object_vars(), ->get_node(), wp_parse_args(), ->_set_node() |
is_object($args) && !empty($args) && !isset([…]) | 38–42 | get_object_vars(), ->get_node(), get_object_vars(), wp_parse_args(), ->_set_node() |
is_string($args) && !is_object($args) && !empty($args) && !isset([…]) | 41–43 | func_get_arg(), parent(), ->get_node(), wp_parse_args(), ->_set_node() |
!is_object($args) && !empty($args) && !empty($defaults) && !isset([…]) | 42–44 | ->get_node(), wp_parse_args(), wp_parse_args(), ->_set_node() |
is_string($args) && !is_object($args) && !empty($args) && !isset([…]) | 45–47 | func_get_arg(), parent(), ->get_node(), get_object_vars(), wp_parse_args(), ->_set_node() |
is_string($args) && is_object($args) && !empty($args) && !isset([…]) | 45–47 | func_get_arg(), parent(), get_object_vars(), ->get_node(), wp_parse_args(), ->_set_node() |
56 further outcomes, up to 102 instructions
!is_object($args) && !empty($args) && !empty($defaults) && !isset([…]) | 46–48 | ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), ->_set_node() |
is_object($args) && !empty($args) && !empty($defaults) && !isset([…]) | 46–48 | get_object_vars(), ->get_node(), wp_parse_args(), wp_parse_args(), ->_set_node() |
is_string($args) && is_object($args) && !empty($args) && !isset([…]) | 49–51 | func_get_arg(), parent(), get_object_vars(), ->get_node(), get_object_vars(), wp_parse_args(), ->_set_node() |
is_object($args) && !empty($args) && !empty($defaults) && !isset([…]) | 50–52 | get_object_vars(), ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), ->_set_node() |
!is_object($args) && !isset([…]) | 50–54 | __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), ->_set_node() |
!is_object($args) && !empty($args) && isset([…]) | 51–55 | ->get_node(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && !is_object($args) && !empty($args) && !empty($defaults) && !isset([…]) | 53 | func_get_arg(), parent(), ->get_node(), wp_parse_args(), wp_parse_args(), ->_set_node() |
!is_object($args) && !isset([…]) | 54–58 | __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), ->_set_node() |
is_object($args) && !isset([…]) | 54–58 | get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), ->_set_node() |
!is_object($args) && !empty($args) && isset([…]) | 55–59 | ->get_node(), get_object_vars(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_object($args) && !empty($args) && isset([…]) | 55–59 | get_object_vars(), ->get_node(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && !is_object($args) && !empty($args) && !empty($defaults) && !isset([…]) | 57 | func_get_arg(), parent(), ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), ->_set_node() |
is_string($args) && is_object($args) && !empty($args) && !empty($defaults) && !isset([…]) | 57 | func_get_arg(), parent(), get_object_vars(), ->get_node(), wp_parse_args(), wp_parse_args(), ->_set_node() |
is_object($args) && !isset([…]) | 58–62 | get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), ->_set_node() |
is_object($args) && !empty($args) && isset([…]) | 59–63 | get_object_vars(), ->get_node(), get_object_vars(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && is_object($args) && !empty($args) && !empty($defaults) && !isset([…]) | 61 | func_get_arg(), parent(), get_object_vars(), ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), ->_set_node() |
is_string($args) && !is_object($args) && !isset([…]) | 61–63 | func_get_arg(), parent(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), ->_set_node() |
is_string($args) && !is_object($args) && !empty($args) && isset([…]) | 62–64 | func_get_arg(), parent(), ->get_node(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
!is_object($args) && !empty($defaults) && !isset([…]) | 62–64 | __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), wp_parse_args(), ->_set_node() |
!is_object($args) && !empty($args) && !empty($defaults) && isset([…]) | 63–65 | ->get_node(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && !is_object($args) && !isset([…]) | 65–67 | func_get_arg(), parent(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), ->_set_node() |
is_string($args) && is_object($args) && !isset([…]) | 65–67 | func_get_arg(), parent(), get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), ->_set_node() |
is_string($args) && !is_object($args) && !empty($args) && isset([…]) | 66–68 | func_get_arg(), parent(), ->get_node(), get_object_vars(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && is_object($args) && !empty($args) && isset([…]) | 66–68 | func_get_arg(), parent(), get_object_vars(), ->get_node(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
!is_object($args) && !empty($defaults) && !isset([…]) | 66–68 | __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), ->_set_node() |
is_object($args) && !empty($defaults) && !isset([…]) | 66–68 | get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), wp_parse_args(), ->_set_node() |
!is_object($args) && !empty($args) && !empty($defaults) && isset([…]) | 67–69 | ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_object($args) && !empty($args) && !empty($defaults) && isset([…]) | 67–69 | get_object_vars(), ->get_node(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && is_object($args) && !isset([…]) | 69–71 | func_get_arg(), parent(), get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), ->_set_node() |
is_string($args) && is_object($args) && !empty($args) && isset([…]) | 70–72 | func_get_arg(), parent(), get_object_vars(), ->get_node(), get_object_vars(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_object($args) && !empty($defaults) && !isset([…]) | 70–72 | get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), ->_set_node() |
is_object($args) && !empty($args) && !empty($defaults) && isset([…]) | 71–73 | get_object_vars(), ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
!is_object($args) && isset([…]) | 71–75 | __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && !is_object($args) && !empty($defaults) && !isset([…]) | 73 | func_get_arg(), parent(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), wp_parse_args(), ->_set_node() |
is_string($args) && !is_object($args) && !empty($args) && !empty($defaults) && isset([…]) | 74 | func_get_arg(), parent(), ->get_node(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
!is_object($args) && isset([…]) | 75–79 | __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_object($args) && isset([…]) | 75–79 | get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && !is_object($args) && !empty($defaults) && !isset([…]) | 77 | func_get_arg(), parent(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), ->_set_node() |
is_string($args) && is_object($args) && !empty($defaults) && !isset([…]) | 77 | func_get_arg(), parent(), get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), wp_parse_args(), ->_set_node() |
is_string($args) && !is_object($args) && !empty($args) && !empty($defaults) && isset([…]) | 78 | func_get_arg(), parent(), ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && is_object($args) && !empty($args) && !empty($defaults) && isset([…]) | 78 | func_get_arg(), parent(), get_object_vars(), ->get_node(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_object($args) && isset([…]) | 79–83 | get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && is_object($args) && !empty($defaults) && !isset([…]) | 81 | func_get_arg(), parent(), get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), ->_set_node() |
is_string($args) && is_object($args) && !empty($args) && !empty($defaults) && isset([…]) | 82 | func_get_arg(), parent(), get_object_vars(), ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && !is_object($args) && isset([…]) | 82–84 | func_get_arg(), parent(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
!is_object($args) && !empty($defaults) && isset([…]) | 83–85 | __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && !is_object($args) && isset([…]) | 86–88 | func_get_arg(), parent(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && is_object($args) && isset([…]) | 86–88 | func_get_arg(), parent(), get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
!is_object($args) && !empty($defaults) && isset([…]) | 87–89 | __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_object($args) && !empty($defaults) && isset([…]) | 87–89 | get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && is_object($args) && isset([…]) | 90–92 | func_get_arg(), parent(), get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_object($args) && !empty($defaults) && isset([…]) | 91–93 | get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && !is_object($args) && !empty($defaults) && isset([…]) | 94 | func_get_arg(), parent(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && !is_object($args) && !empty($defaults) && isset([…]) | 98 | func_get_arg(), parent(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && is_object($args) && !empty($defaults) && isset([…]) | 98 | func_get_arg(), parent(), get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
is_string($args) && is_object($args) && !empty($defaults) && isset([…]) | 102 | func_get_arg(), parent(), get_object_vars(), __(), _doing_it_wrong(), sanitize_title(), esc_attr(), ->get_node(), get_object_vars(), wp_parse_args(), wp_parse_args(), _deprecated_argument(), ->_set_node() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 103 | 11–102 | 9 | |
| 8.5 | 103 | 11–102 | 9 | |
| 8.4 | 103 | 11–102 | 9 | 1 fewer instruction than PHP 8.3 |
| 8.3 | 104 | 11–103 | 9 | |
| 8.2 | 104 | 11–103 | 9 | 2 fewer instructions than PHP 8.1 |
| 8.1 | 106 | 11–105 | 9 | |
| 7.4 | 106 | 11–105 | 9 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 8
- _doing_it_wrong()Marks something as being incorrectly called.
- __()Retrieves the translation of $text.
- esc_attr()Escaping for HTML attributes.
- sanitize_title()Sanitizes a string into a slug, which can be used in URLs or HTML attributes.
- wp_parse_args()Merges user defined arguments into defaults array.
- _deprecated_argument()Marks a function argument as deprecated and inform when it has been used.
- WP_Admin_Bar::get_node()Gets a node.
- WP_Admin_Bar::_set_node()
Used by · 3
- WP_Admin_Bar::_bind()
- WP_Admin_Bar::add_group()Adds a group to a toolbar menu node.
- WP_Admin_Bar::add_menu()Adds a node (menu item) to the admin bar menu.
Source code
public function add_node( $args ) { // Shim for old method signature: add_node( $parent_id, $menu_obj, $args ). if ( func_num_args() >= 3 && is_string( $args ) ) { $args = array_merge( array( 'parent' => $args ), func_get_arg( 2 ) ); } if ( is_object( $args ) ) { $args = get_object_vars( $args ); } // Ensure we have a valid title. if ( empty( $args['id'] ) ) { if ( empty( $args['title'] ) ) { return; } _doing_it_wrong( __METHOD__, __( 'The menu ID should not be empty.' ), '3.3.0' ); // Deprecated: Generate an ID from the title. $args['id'] = esc_attr( sanitize_title( trim( $args['title'] ) ) ); } $defaults = array( 'id' => false, 'title' => false, 'parent' => false, 'href' => false, 'group' => false, 'meta' => array(), ); // If the node already exists, keep any data that isn't provided. $maybe_defaults = $this->get_node( $args['id'] ); if ( $maybe_defaults ) { $defaults = get_object_vars( $maybe_defaults ); } // Do the same for 'meta' items. if ( ! empty( $defaults['meta'] ) && ! empty( $args['meta'] ) ) { $args['meta'] = wp_parse_args( $args['meta'], $defaults['meta'] ); } $args = wp_parse_args( $args, $defaults ); $back_compat_parents = array( 'my-account-with-avatar' => array( 'my-account', '3.3' ), 'my-blogs' => array( 'my-sites', '3.3' ), ); if ( isset( $back_compat_parents[ $args['parent'] ] ) ) { list( $new_parent, $version ) = $back_compat_parents[ $args['parent'] ]; _deprecated_argument( __METHOD__, $version, sprintf( 'Use <code>%s</code> as the parent for the <code>%s</code> admin bar node instead of <code>%s</code>.', $new_parent, $args['id'], $args['parent'] ) ); $args['parent'] = $new_parent; } $this->_set_node( $args ); }Changelog
Introduced in 3.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 tag, from
src/wp-includes/class-wp-admin-bar.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.