diff -r 3d4e9c994f10 -r a86126ab1dd4 wp/wp-includes/class-wp-admin-bar.php --- a/wp/wp-includes/class-wp-admin-bar.php Tue Oct 22 16:11:46 2019 +0200 +++ b/wp/wp-includes/class-wp-admin-bar.php Tue Dec 15 13:49:49 2020 +0100 @@ -82,14 +82,22 @@ } /** - * @param array $node + * Add a node (menu item) to the Admin Bar menu. + * + * @since 3.3.0 + * + * @param array $node The attributes that define the node. */ public function add_menu( $node ) { $this->add_node( $node ); } /** - * @param string $id + * Remove a node from the admin bar. + * + * @since 3.1.0 + * + * @param string $id The menu slug to remove. */ public function remove_menu( $id ) { $this->remove_node( $id ); @@ -114,9 +122,9 @@ * } */ public function add_node( $args ) { - // Shim for old method signature: add_node( $parent_id, $menu_obj, $args ) - if ( func_num_args() >= 3 && is_string( func_get_arg( 0 ) ) ) { - $args = array_merge( array( 'parent' => func_get_arg( 0 ) ), func_get_arg( 2 ) ); + // 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 ) ) { @@ -144,7 +152,8 @@ ); // If the node already exists, keep any data that isn't provided. - if ( $maybe_defaults = $this->get_node( $args['id'] ) ) { + $maybe_defaults = $this->get_node( $args['id'] ); + if ( $maybe_defaults ) { $defaults = get_object_vars( $maybe_defaults ); } @@ -180,10 +189,11 @@ * Gets a node. * * @param string $id - * @return object Node. + * @return object|void Node. */ final public function get_node( $id ) { - if ( $node = $this->_get_node( $id ) ) { + $node = $this->_get_node( $id ); + if ( $node ) { return clone $node; } } @@ -210,7 +220,8 @@ * @return array|void */ final public function get_nodes() { - if ( ! $nodes = $this->_get_nodes() ) { + $nodes = $this->_get_nodes(); + if ( ! $nodes ) { return; } @@ -307,19 +318,20 @@ } foreach ( $this->_get_nodes() as $node ) { - if ( 'root' == $node->id ) { + if ( 'root' === $node->id ) { continue; } // Fetch the parent node. If it isn't registered, ignore the node. - if ( ! $parent = $this->_get_node( $node->parent ) ) { + $parent = $this->_get_node( $node->parent ); + if ( ! $parent ) { continue; } // Generate the group class (we distinguish between top level and other level groups). - $group_class = ( $node->parent == 'root' ) ? 'ab-top-menu' : 'ab-submenu'; + $group_class = ( 'root' === $node->parent ) ? 'ab-top-menu' : 'ab-submenu'; - if ( $node->type == 'group' ) { + if ( 'group' === $node->type ) { if ( empty( $node->meta['class'] ) ) { $node->meta['class'] = $group_class; } else { @@ -328,7 +340,7 @@ } // Items in items aren't allowed. Wrap nested items in 'default' groups. - if ( $parent->type == 'item' && $node->type == 'item' ) { + if ( 'item' === $parent->type && 'item' === $node->type ) { $default_id = $parent->id . '-default'; $default = $this->_get_node( $default_id ); @@ -357,7 +369,7 @@ // Groups in groups aren't allowed. Add a special 'container' node. // The container will invisibly wrap both groups. - } elseif ( $parent->type == 'group' && $node->type == 'group' ) { + } elseif ( 'group' === $parent->type && 'group' === $node->type ) { $container_id = $parent->id . '-container'; $container = $this->_get_node( $container_id ); @@ -386,7 +398,7 @@ $container->parent = $grandparent->id; $index = array_search( $parent, $grandparent->children, true ); - if ( $index === false ) { + if ( false === $index ) { $grandparent->children[] = $container; } else { array_splice( $grandparent->children, $index, 1, array( $container ) ); @@ -412,24 +424,13 @@ } /** - * @global bool $is_IE * @param object $root */ final protected function _render( $root ) { - global $is_IE; - // Add browser classes. // We have to do this here since admin bar shows on the front end. $class = 'nojq nojs'; - if ( $is_IE ) { - if ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 7' ) ) { - $class .= ' ie7'; - } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 8' ) ) { - $class .= ' ie8'; - } elseif ( strpos( $_SERVER['HTTP_USER_AGENT'], 'MSIE 9' ) ) { - $class .= ' ie9'; - } - } elseif ( wp_is_mobile() ) { + if ( wp_is_mobile() ) { $class .= ' mobile'; } @@ -457,7 +458,7 @@ * @param object $node */ final protected function _render_container( $node ) { - if ( $node->type != 'container' || empty( $node->children ) ) { + if ( 'container' !== $node->type || empty( $node->children ) ) { return; } @@ -472,11 +473,11 @@ * @param object $node */ final protected function _render_group( $node ) { - if ( $node->type == 'container' ) { + if ( 'container' === $node->type ) { $this->_render_container( $node ); return; } - if ( $node->type != 'group' || empty( $node->children ) ) { + if ( 'group' !== $node->type || empty( $node->children ) ) { return; } @@ -497,7 +498,7 @@ * @param object $node */ final protected function _render_item( $node ) { - if ( $node->type != 'item' ) { + if ( 'item' !== $node->type ) { return; } @@ -536,16 +537,19 @@ if ( $has_link ) { $attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' ); echo "meta['onclick'] ) ) { - echo ' onclick="' . esc_js( $node->meta['onclick'] ) . '"'; - } } else { $attributes = array( 'onclick', 'target', 'title', 'rel', 'lang', 'dir' ); echo '
meta[ $attribute ] ) ) { + if ( empty( $node->meta[ $attribute ] ) ) { + continue; + } + + if ( 'onclick' === $attribute ) { + echo " $attribute='" . esc_js( $node->meta[ $attribute ] ) . "'"; + } else { echo " $attribute='" . esc_attr( $node->meta[ $attribute ] ) . "'"; } } @@ -592,13 +596,13 @@ /** */ public function add_menus() { - // User related, aligned right. + // User-related, aligned right. add_action( 'admin_bar_menu', 'wp_admin_bar_my_account_menu', 0 ); add_action( 'admin_bar_menu', 'wp_admin_bar_search_menu', 4 ); add_action( 'admin_bar_menu', 'wp_admin_bar_my_account_item', 7 ); add_action( 'admin_bar_menu', 'wp_admin_bar_recovery_mode_menu', 8 ); - // Site related. + // Site-related. add_action( 'admin_bar_menu', 'wp_admin_bar_sidebar_toggle', 0 ); add_action( 'admin_bar_menu', 'wp_admin_bar_wp_menu', 10 ); add_action( 'admin_bar_menu', 'wp_admin_bar_my_sites_menu', 20 ); @@ -606,7 +610,7 @@ add_action( 'admin_bar_menu', 'wp_admin_bar_customize_menu', 40 ); add_action( 'admin_bar_menu', 'wp_admin_bar_updates_menu', 50 ); - // Content related. + // Content-related. if ( ! is_network_admin() && ! is_user_admin() ) { add_action( 'admin_bar_menu', 'wp_admin_bar_comments_menu', 60 ); add_action( 'admin_bar_menu', 'wp_admin_bar_new_content_menu', 70 );