Source
File: wp-includes/class-wp-admin-bar.php
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 );
}