WordPress.org

Make WordPress Core


Ignore:
Timestamp:
11/24/2010 05:31:25 AM (9 years ago)
Author:
PeteMall
Message:

Adapt user-list-table for network admin site-users. See #15558

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/class-wp-users-list-table.php

    r16536 r16560  
    88 */
    99class WP_Users_List_Table extends WP_List_Table {
     10   
     11    var $site_id;
     12    var $is_site_users;
     13   
     14    function WP_Users_List_Table() {
     15        $screen = get_current_screen();
     16        $this->is_site_users = ( 'site-users-network' == $screen->id ) ? true : false;
     17
     18        if ( $this->is_site_users )
     19            $this->site_id = isset( $_REQUEST['id'] ) ? intval( $_REQUEST['id'] ) : 0;
     20
     21        parent::WP_List_Table( array(
     22            'singular' => 'user',
     23            'plural'   => 'users'
     24        ) );
     25    }
    1026
    1127    function check_permissions() {
    1228        if ( !current_user_can('list_users') )
    1329            wp_die(__('Cheatin’ uh?'));
     30
     31        if ( $this->is_site_users && !current_user_can('manage_sites') )
     32            wp_die(__('You do not have sufficient permissions to edit this site.'));
    1433    }
    1534
     
    3150            'search' => $usersearch
    3251        );
     52       
     53        if ( $this->is_site_users )
     54            $args['blog_id'] = $this->site_id;
    3355
    3456        if ( isset( $_REQUEST['orderby'] ) )
     
    5678        global $wp_roles, $role;
    5779
    58         $users_of_blog = count_users();
     80        if ( $this->is_site_users ) {
     81            $url = 'site-users.php?id=' . $this->site_id;           
     82            switch_to_blog( $this->site_id );
     83            $users_of_blog = count_users();
     84            restore_current_blog();
     85        } else {
     86            $url = 'users.php';
     87            $users_of_blog = count_users();
     88        }
    5989        $total_users = $users_of_blog['total_users'];
    6090        $avail_roles =& $users_of_blog['avail_roles'];
     
    6494        $class = empty($role) ? ' class="current"' : '';
    6595        $role_links = array();
    66         $role_links['all'] = "<a href='users.php'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
     96        $role_links['all'] = "<a href='$url'$class>" . sprintf( _nx( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users, 'users' ), number_format_i18n( $total_users ) ) . '</a>';
    6797        foreach ( $wp_roles->get_names() as $this_role => $name ) {
    6898            if ( !isset($avail_roles[$this_role]) )
     
    79109            /* translators: User role name with count */
    80110            $name = sprintf( __('%1$s <span class="count">(%2$s)</span>'), $name, $avail_roles[$this_role] );
    81             $role_links[$this_role] = "<a href='users.php?role=$this_role'$class>$name</a>";
     111            $role_links[$this_role] = "<a href='" . add_query_arg( 'role', $this_role, $url ) . "'$class>$name</a>";
    82112        }
    83113
     
    172202        $user_object = sanitize_user_object( $user_object, 'display' );
    173203        $email = $user_object->user_email;
     204       
     205        if ( $this->is_site_users )
     206            $url = "site-users.php?id={$this->site_id}&amp;";
     207        else
     208            $url = 'users.php?';
    174209
    175210        $checkbox = '';
     
    198233                $actions['delete'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=delete&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Delete' ) . "</a>";
    199234            if ( is_multisite() && get_current_user_id() != $user_object->ID && current_user_can( 'remove_user', $user_object->ID ) )
    200                 $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( "users.php?action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>";
     235                $actions['remove'] = "<a class='submitdelete' href='" . wp_nonce_url( $url."action=remove&amp;user=$user_object->ID", 'bulk-users' ) . "'>" . __( 'Remove' ) . "</a>";
    201236            $actions = apply_filters( 'user_row_actions', $actions, $user_object );
    202237            $edit .= $this->row_actions( $actions );
Note: See TracChangeset for help on using the changeset viewer.