store->get_users() as $user ) { // Reset parent for each loop due to groupUserRoles. $item_parent = $parent; $href = VAA_API::get_vaa_action_link( array( $this->type => $user->ID ), $this->store->get_nonce( true ) ); $class = 'vaa-' . $this->type . '-item'; $title = $this->get_view_title( $user ); $view_title = VAA_View_Admin_As_Form::do_view_title( $title, $this, $user->ID ); /** * Add the user roles to the user title? * Only available if users are not grouped under their roles. * * @since 1.8 * @param bool $true True by default. * @param \WP_User $user The user object. * @return bool */ if ( ! $this->group_user_roles() && apply_filters( 'vaa_admin_bar_view_title_' . $this->type . '_show_roles', true, $user ) ) { // Users displayed as normal. $user_roles = array(); // Add the roles of this user in the name. foreach ( $user->roles as $role ) { $user_roles[] = $this->store->get_rolenames( $role ); } $view_title = $view_title . '   (' . implode( ', ', $user_roles ) . ')'; } // Check if this user is the current view. if ( VAA_API::is_current_view( $user->ID, $this->type ) ) { $class .= ' current'; if ( 1 === count( $this->store->get_view() ) ) { $href = false; } } $user_node = array( 'id' => $root . '-' . $this->type . '-' . $user->ID, 'parent' => $item_parent, 'title' => $view_title, 'href' => $href, 'meta' => array( // Translators: %s stands for the user display name. 'title' => sprintf( __( 'View as %s', VIEW_ADMIN_AS_DOMAIN ), $title ), 'class' => $class, ), ); if ( $this->group_user_roles() ) { // Users grouped under roles. foreach ( $user->roles as $role ) { $user_role_node = $user_node; $item_parent = $main_root . '-roles-role-' . $role; $group = $item_parent . '-users'; if ( ! $admin_bar->get_node( $group ) ) { $admin_bar->add_group( array( 'id' => $group, 'parent' => $item_parent, 'meta' => array( 'class' => 'vaa-auto-max-height', ), ) ); } $user_role_node['id'] .= '-' . $role; $user_role_node['parent'] = $group; $admin_bar->add_node( $user_role_node ); } } else { $admin_bar->add_node( $user_node ); } } // End foreach(). } else { _doing_it_wrong( __FILE__, esc_html__( 'No toolbar resources found.', VIEW_ADMIN_AS_DOMAIN ), '1.7' ); } // End if().