WP_Users_List_Table::get_views() – Return an associative array listing all the views that can be used with this table.

You appear to be a bot. Output may be restricted

Description

Return an associative array listing all the views that can be used with this table.

Provides a list of roles and user count for that role for easy Filtersing of the user table.

Usage

$string[] = WP_Users_List_Table::get_views();

Parameters

Returns

string[] An array of HTML links keyed by their view.

Source

File name: wordpress/wp-admin/includes/class-wp-users-list-table.php
Lines:

1 to 89 of 89
  protected function get_views() {
    global $role;

    $wp_roles = wp_roles();

    $count_users = ! wp_is_large_user_count();

    if ( $this->is_site_users ) {
      $url = 'site-users.php?id=' . $this->site_id;
    } else {
      $url = 'users.php';
    }

    $role_links  = array();
    $avail_roles = array();
    $all_text    = __( 'All' );

    if ( $count_users ) {
      if ( $this->is_site_users ) {
        switch_to_blog( $this->site_id );
        $users_of_blog = count_users( 'time', $this->site_id );
        restore_current_blog();
      } else {
        $users_of_blog = count_users();
      }

      $total_users = $users_of_blog['total_users'];
      $avail_roles =& $users_of_blog['avail_roles'];
      unset( $users_of_blog );

      $all_text = sprintf(
        /* translators: %s: Number of users. */
        _nx(
          'All <span class="count">(%s)</span>',
          'All <span class="count">(%s)</span>',
          $total_users,
          'users'
        ),
        number_format_i18n( $total_users )
      );
    }

    $role_links['all'] = array(
      'url'     => $url,
      'label'   => $all_text,
      'current' => empty( $role ),
    );

    foreach ( $wp_roles->get_names() as $this_role => $name ) {
      if ( $count_users && ! isset( $avail_roles[ $this_role ] ) ) {
        continue;
      }

      $name = translate_user_role( $name );
      if ( $count_users ) {
        $name = sprintf(
          /* translators: 1: User role name, 2: Number of users. */
          __( '%1$s <span class="count">(%2$s)</span>' ),
          $name,
          number_format_i18n( $avail_roles[ $this_role ] )
        );
      }

      $role_links[ $this_role ] = array(
        'url'     => esc_url( add_query_arg( 'role', $this_role, $url ) ),
        'label'   => $name,
        'current' => $this_role === $role,
      );
    }

    if ( ! empty( $avail_roles['none'] ) ) {

      $name = __( 'No role' );
      $name = sprintf(
        /* translators: 1: User role name, 2: Number of users. */
        __( '%1$s <span class="count">(%2$s)</span>' ),
        $name,
        number_format_i18n( $avail_roles['none'] )
      );

      $role_links['none'] = array(
        'url'     => esc_url( add_query_arg( 'role', 'none', $url ) ),
        'label'   => $name,
        'current' => 'none' === $role,
      );
    }

    return $this->get_views_links( $role_links );
  }
 

 View on GitHub View on Trac