Make WordPress Core

Ticket #16001: 16001.diff

File 16001.diff, 17.2 KB (added by garyc40, 14 years ago)

first attempt to patch this bug

  • wp-admin/includes/class-wp-ms-users-list-table.php

    diff --git wp-admin/includes/class-wp-ms-users-list-table.php wp-admin/includes/class-wp-ms-users-list-table.php
    index c3bfec2..bd502ed 100644
    class WP_MS_Users_List_Table extends WP_List_Table { 
    5656
    5757                $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode'];
    5858
    59                 // Query the user IDs for this page
    60                 $wp_user_search = new WP_User_Query( $args );
     59                if ( $role == 'pending' )
     60                        $wp_user_search = new WP_Pending_User_Query( $args ); // Query for pending users
     61                else
     62                        $wp_user_search = new WP_User_Query( $args ); // Query the user IDs for this page
    6163
    6264                $this->items = $wp_user_search->get_results();
    6365
    class WP_MS_Users_List_Table extends WP_List_Table { 
    6870        }
    6971
    7072        function get_bulk_actions() {
     73                global $role;
     74               
    7175                $actions = array();
    72                 if ( current_user_can( 'delete_users' ) )
    73                         $actions['delete'] = __( 'Delete' );
    74                 $actions['spam'] = _x( 'Mark as Spam', 'user' );
    75                 $actions['notspam'] = _x( 'Not Spam', 'user' );
     76               
     77                if ( $role == 'pending' ) {
     78                        if ( current_user_can( 'delete_users' ) )
     79                                $actions['deletesignup'] = __( 'Delete' );
     80                        $actions['activate'] = _x( 'Activate', 'user' );
     81                        $actions['resend'] = __( 'Resend Email' );
     82                } else {
     83                        if ( current_user_can( 'delete_users' ) )
     84                                $actions['delete'] = __( 'Delete' );
     85                        $actions['spam'] = _x( 'Mark as Spam', 'user' );
     86                        $actions['notspam'] = _x( 'Not Spam', 'user' );
     87                }
    7688
    7789                return $actions;
    7890        }
    class WP_MS_Users_List_Table extends WP_List_Table { 
    8799                $total_users = get_user_count();
    88100                $super_admins = get_super_admins();
    89101                $total_admins = count( $super_admins );
     102                $total_pendings = get_pending_user_count();
    90103
    91                 $current_role = false;
    92                 $class = $role != 'super' ? ' class="current"' : '';
     104                $class = in_array( $role, array( 'super', 'pending' ) ) ? '' : ' class="current"';
    93105                $role_links = array();
    94106                $role_links['all'] = "<a href='" . network_admin_url('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>';
    95107                $class = $role == 'super' ? ' class="current"' : '';
    96108                $role_links['super'] = "<a href='" . network_admin_url('users.php?role=super') . "'$class>" . sprintf( _n( 'Super Admin <span class="count">(%s)</span>', 'Super Admins <span class="count">(%s)</span>', $total_admins ), number_format_i18n( $total_admins ) ) . '</a>';
     109                $class = $role == 'pending' ? ' class="current"' : '';
     110                $role_links['pending'] = "<a href='" . network_admin_url('users.php?role=pending') . "'$class>" . sprintf( _n( 'Pending Confirmation <span class="count">(%s)</span>', 'Pending Confirmation <span class="count">(%s)</span>', $total_pendings ), number_format_i18n( $total_pendings ) ) . '</a>';
    97111
    98112                return $role_links;
    99113        }
    class WP_MS_Users_List_Table extends WP_List_Table { 
    108122        }
    109123
    110124        function get_columns() {
     125                global $role;
     126               
    111127                $users_columns = array(
    112128                        'cb'         => '<input type="checkbox" />',
    113129                        'username'   => __( 'Username' ),
    114                         'name'       => __( 'Name' ),
    115130                        'email'      => __( 'E-mail' ),
    116131                        'registered' => _x( 'Registered', 'user' ),
    117                         'blogs'      => __( 'Sites' )
    118132                );
     133               
     134                if ( $role != 'pending' ) {
     135                        $users_columns['name'] = __( 'Name' );
     136                        $users_columns['blogs'] = __( 'Sites' );
     137                }
     138               
    119139                $users_columns = apply_filters( 'wpmu_users_columns', $users_columns );
    120140
    121141                return $users_columns;
    122142        }
    123143
    124144        function get_sortable_columns() {
    125                 return array(
     145                global $role;
     146               
     147                $sortables = array(
    126148                        'username'   => 'login',
    127                         'name'       => 'name',
    128149                        'email'      => 'email',
    129150                        'registered' => 'id',
    130151                );
     152               
     153                if ( $role != 'pending' ) {
     154                        $sortables['name'] = 'name';
     155                }
     156               
     157                return $sortables;
    131158        }
    132159
    133160        function display_rows() {
    134                 global $current_site, $mode;
     161                global $current_site, $mode, $role;
    135162
    136163                $alt = '';
    137164                $super_admins = get_super_admins();
    class WP_MS_Users_List_Table extends WP_List_Table { 
    140167
    141168                        $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' );
    142169
    143                         foreach ( $status_list as $status => $col ) {
    144                                 if ( $user->$status )
    145                                         $alt .= " $col";
     170                        if ( $role == 'pending' ) {                             
     171                                $user->ID = $user->user_login;
     172                                $user->user_registered = $user->registered;
     173                        } else {
     174                                foreach ( $status_list as $status => $col ) {
     175                                        if ( $user->$status )
     176                                                $alt .= " $col";
     177                                }
    146178                        }
    147179
    148180                        ?>
    class WP_MS_Users_List_Table extends WP_List_Table { 
    171203
    172204                                        case 'username':
    173205                                                $avatar = get_avatar( $user->user_email, 32 );
    174                                                 if ( get_current_user_id() == $user->ID ) {
    175                                                         $edit_link = esc_url( network_admin_url( 'profile.php' ) );
     206                                                if ( $role == 'pending' ) {
     207                                                        $activate_link = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'edit.php', 'activatesignup' ) . '&amp;action=activatesignup&amp;user_login=' . $user->user_login ) ) );
     208                                                        $resend_link = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'edit.php', 'resendsignup' ) . '&amp;action=resendsignup&amp;user_login=' . $user->user_login ) ) );
    176209                                                } else {
    177                                                         $edit_link = esc_url( network_admin_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), 'user-edit.php?user_id=' . $user->ID ) ) );
     210                                                        if ( get_current_user_id() == $user->ID ) {
     211                                                                $edit_link = esc_url( network_admin_url( 'profile.php' ) );
     212                                                        } else {
     213                                                                $edit_link = esc_url( network_admin_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), 'user-edit.php?user_id=' . $user->ID ) ) );
     214                                                        }
    178215                                                }
    179216
    180217                                                echo "<td $attributes>"; ?>
    181                                                         <?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo stripslashes( $user->user_login ); ?></a><?php
     218                                                        <?php echo $avatar; ?><strong>
     219                                                                <?php if ( $role == 'pending' ): ?>
     220                                                                        <?php echo stripslashes( $user->user_login ); ?>
     221                                                                <?php else: ?>
     222                                                                        <a href="<?php echo $edit_link; ?>" class="edit"><?php echo stripslashes( $user->user_login ); ?></a>   
     223                                                                <?php endif ?>
     224                                                                <?php
    182225                                                        if ( in_array( $user->user_login, $super_admins ) )
    183226                                                                echo ' - ' . __( 'Super Admin' );
    184227                                                        ?></strong>
    185228                                                        <br/>
    186229                                                        <?php
    187230                                                                $actions = array();
    188                                                                 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
     231                                                                if ( $role == 'pending' ) {
     232                                                                        $actions['activate'] = '<a href="' . $activate_link . '">' . __( 'Activate' ) . '</a>';
     233                                                                        $actions['resend'] = '<a href="' . $resend_link . '">' . __( 'Resend Email' ) . '</a>';
     234                                                                } else {
     235                                                                        $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
     236                                                                }
    189237
    190238                                                                if ( current_user_can( 'delete_user', $user->ID) && ! in_array( $user->user_login, $super_admins ) ) {
    191                                                                         $actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'edit.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
     239                                                                        if ( $role == 'pending' ) {
     240                                                                                $actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'edit.php', 'deletesignup' ) . '&amp;action=deletesignup&amp;user_login=' . $user->user_login ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
     241                                                                        } else {
     242                                                                                $actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'edit.php', 'deleteuser' ) . '&amp;action=deleteuser&amp;id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>';
     243                                                                        }
    192244                                                                }
    193245
    194246                                                                echo $this->row_actions( $actions );
  • wp-admin/network/edit.php

    diff --git wp-admin/network/edit.php wp-admin/network/edit.php
    index e785d38..5cadac7 100644
    if ( empty( $_GET['action'] ) ) { 
    1818        exit;
    1919}
    2020
     21function _wp_activate_by_user_login( $user_login ) {
     22        global $wpdb;
     23       
     24        $key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE active != 1 AND user_login = %s", $user_login ) );
     25        if ( $key ) {
     26                wpmu_activate_signup( $key );
     27        }
     28}
     29
     30function _wp_resend_by_user_login( $user_login ) {
     31        global $wpdb;
     32       
     33        $user = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->signups} WHERE active !=1 AND user_login = %s", $user_login ) );
     34       
     35        if ( $user ) {
     36                wpmu_signup_user_notification($user->user_login, $user->user_email, $user->activation_key, $user->meta);
     37        }
     38}
     39
     40function confirm_delete_signups( $signups ) {
     41        global $wpdb;
     42       
     43        $current_user = wp_get_current_user();
     44        if ( ! is_array( $signups ) ) {
     45                return false;
     46        }
     47       
     48        screen_icon();
     49        ?>
     50        <h2><?php esc_html_e( 'Users' ); ?></h2>
     51        <p><?php _e( 'Are you sure you want to delete the following users?' ); ?></p>
     52        <form action="edit.php?action=dodeletesignup" method="post">
     53        <input type="hidden" name="dodeletesignup" />
     54        <?php
     55        wp_nonce_field( 'ms-signups-delete' );
     56        echo '<ul>';
     57        foreach ( $signups as $delete_signup ) {
     58                echo "<li><input type='hidden' name='user[]' value='{$delete_signup}'/>{$delete_signup}</li>\n";
     59        }
     60        echo '</ul>';
     61
     62        submit_button( __('Confirm Deletion'), 'delete' );
     63        ?>
     64        </form>
     65    <?php
     66        return true;
     67}
     68
    2169function confirm_delete_users( $users ) {
    2270        $current_user = wp_get_current_user();
    2371        if ( !is_array( $users ) )
    switch ( $_GET['action'] ) { 
    421469
    422470                                                        update_user_status( $val, 'spam', '0', 1 );
    423471                                                break;
     472                                               
     473                                                case 'activate':
     474                                                        $userfunction = 'all_activate';
     475                                                        _wp_activate_by_user_login( $val );
     476                                                break;
     477                                               
     478                                                case 'resend':
     479                                                        $userfunction = 'all_resend';
     480                                                        _wp_resend_by_user_login( $val );
     481                                                break;
     482                                               
     483                                                case 'deletesignup':
     484                                                        if ( ! current_user_can( 'delete_users' ) )
     485                                                                wp_die( __( 'You do not have permission to access this page.' ) );
     486                                                               
     487                                                        $title = __( 'Users' );
     488                                                        $parent_file = 'users.php';
     489                                                        require_once( '../admin-header.php' );
     490                                                        echo '<div class="wrap">';
     491                                                        confirm_delete_signups( $_POST['allusers'] );
     492                                                        echo '</div>';
     493                                            require_once( '../admin-footer.php' );
     494                                            exit();
     495                                                break;
    424496                                        }
    425497                                }
    426498                        }
    switch ( $_GET['action'] ) { 
    467539                wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), network_admin_url( 'users.php' ) ) );
    468540                exit();
    469541        break;
     542       
     543        case 'activatesignup':
     544                if ( ! current_user_can( 'manage_network_users' ) )
     545                        wp_die( __( 'You do not have permission to access this page.' ) );
     546
     547                check_admin_referer( 'activatesignup' );
     548               
     549                _wp_activate_by_user_login( $_GET['user_login'] );
     550               
     551                wp_redirect( add_query_arg( array( 'role' => 'pending', 'updated' => 'true', 'action' => 'activate' ), network_admin_url( 'users.php' ) ) );
     552                exit();
     553        break;
     554       
     555        case 'resendsignup':
     556                if ( ! current_user_can( 'manage_network_users' ) )
     557                        wp_die( __( 'You do not have permission to access this page.' ) );
     558
     559                check_admin_referer( 'resendsignup' );
     560               
     561                _wp_resend_by_user_login( $_GET['user_login'] );
     562       
     563                wp_redirect( add_query_arg( array( 'role' => 'pending', 'updated' => 'true', 'action' => 'resend' ), network_admin_url( 'users.php' ) ) );
     564                exit();
     565        break;
     566       
     567        case 'deletesignup':
     568                if ( ! current_user_can( 'manage_network_users' ) )
     569                        wp_die( __( 'You do not have permission to access this page.' ) );
     570
     571                check_admin_referer( 'deletesignup' );
     572               
     573                if ( ! empty( $_GET['user_login'] ) ) {
     574                        $title = __( 'Users' );
     575                        $parent_file = 'users.php';
     576                        require_once( '../admin-header.php' );
     577                        echo '<div class="wrap">';
     578                        confirm_delete_signups( array( $_GET['user_login'] ) );
     579                        echo '</div>';
     580            require_once( '../admin-footer.php' );
     581                } else {
     582                        wp_redirect( add_query_arg( array( 'role' => 'pending' ), network_admin_url( 'users.php' ) ) );
     583                }
     584                exit();
     585        break;
     586       
     587        case 'dodeletesignup':
     588                if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' ) ) )
     589                        wp_die( __( 'You do not have permission to access this page.' ) );
     590
     591                check_admin_referer( 'ms-signups-delete' );
     592               
     593                if ( ! empty( $_POST['user'] ) ) {
     594                        array_walk( $_POST['user'], array( &$wpdb, 'escape_by_ref' ) );
     595                        $wpdb->query( "DELETE FROM {$wpdb->signups} WHERE active != 1 AND user_login IN ('" . implode( "','", $_POST['user'] ) . "')" );
     596                }
     597
     598                if ( count( $_POST['user'] ) > 1 ) {
     599                        $delete_action = 'all_delete';
     600                } else {
     601                        $delete_action = 'delete';
     602                }
     603
     604                wp_redirect( add_query_arg( array( 'role' => 'pending', 'updated' => 'true', 'action' => $delete_action ), network_admin_url( 'users.php' ) ) );
     605                exit();
     606        break;
    470607
    471608        default:
    472609                // Let plugins use us as a post handler easily
  • wp-admin/network/users.php

    diff --git wp-admin/network/users.php wp-admin/network/users.php
    index 15853dd..87eb130 100644
    if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( 
    5858                        case 'add':
    5959                                _e( 'User added.' );
    6060                        break;
     61                        case 'activate':
     62                                _e( 'User activated.' );
     63                        break;
     64                        case 'resend':
     65                                _e( 'Activation instruction resent to user.');
     66                        break;
     67                        case 'all_activate':
     68                                _e( 'Users activated.' );
     69                        break;
     70                        case 'all_resend':
     71                                _e( 'Activation instruction resent to users.');
     72                        break;
    6173                }
    6274                ?>
    6375        </p></div>
  • wp-includes/ms-functions.php

    diff --git wp-includes/ms-functions.php wp-includes/ms-functions.php
    index b3b21df..5622a56 100644
    function get_user_count() { 
    156156}
    157157
    158158/**
     159 * The number of pending users in your installation.
     160 *
     161 * The count is cached and updated twice daily. This is not a live count.
     162 *
     163 * @since 3.2
     164 *
     165 * @return int
     166 */
     167function get_pending_user_count() {
     168        return get_site_option( 'pending_user_count' );
     169}
     170
     171/**
    159172 * The number of active sites on your installation.
    160173 *
    161174 * The count is cached and updated twice daily. This is not a live count.
    function wp_update_network_counts() { 
    20672080
    20682081        $count = $wpdb->get_var( $wpdb->prepare("SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'") );
    20692082        update_site_option( 'user_count', $count );
     2083       
     2084        $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(user_login) AS c FROM $wpdb->signups WHERE active != 1" ) );
     2085        update_site_option( 'pending_user_count', $count );
    20702086}
    20712087
    20722088?>
     2089 No newline at end of file
  • wp-includes/user.php

    diff --git wp-includes/user.php wp-includes/user.php
    index c30f7be..5e792a6 100644
    class WP_User_Query { 
    617617        }
    618618}
    619619
     620class WP_Pending_User_Query extends WP_User_Query {
     621        function prepare_query() {
     622                global $wpdb;
     623
     624                $qv = &$this->query_vars;
     625                $this->query_fields = "{$wpdb->signups}.*";
     626
     627                $this->query_from = "FROM {$wpdb->signups}";
     628                $this->query_where = "WHERE 1=1 AND active != 1";
     629
     630                // sorting
     631                if ( in_array( $qv['orderby'], array( 'nicename', 'email' ) ) ) {
     632                        $orderby = 'user_' . $qv['orderby'];
     633                } elseif ( in_array( $qv['orderby'], array( 'user_email', 'registered' ) ) ) {
     634                        $orderby = $qv['orderby'];
     635                } else {
     636                        $orderby = 'user_login';
     637                }
     638
     639                $qv['order'] = strtoupper( $qv['order'] );
     640                if ( 'ASC' == $qv['order'] )
     641                        $order = 'ASC';
     642                else
     643                        $order = 'DESC';
     644                $this->query_orderby = "ORDER BY $orderby $order";
     645
     646                // limit
     647                if ( $qv['number'] ) {
     648                        if ( $qv['offset'] )
     649                                $this->query_limit = $wpdb->prepare("LIMIT %d, %d", $qv['offset'], $qv['number']);
     650                        else
     651                                $this->query_limit = $wpdb->prepare("LIMIT %d", $qv['number']);
     652                }
     653
     654                $search = trim( $qv['search'] );
     655                if ( $search ) {
     656                        $leading_wild = ( ltrim($search, '*') != $search );
     657                        $trailing_wild = ( rtrim($search, '*') != $search );
     658                        if ( $leading_wild && $trailing_wild )
     659                                $wild = 'both';
     660                        elseif ( $leading_wild )
     661                                $wild = 'leading';
     662                        elseif ( $trailing_wild )
     663                                $wild = 'trailing';
     664                        else
     665                                $wild = false;
     666                        if ( $wild )
     667                                $search = trim($search, '*');
     668
     669                        if ( false !== strpos( $search, '@') )
     670                                $search_columns = array('user_email');
     671                        else
     672                                $search_columns = array('user_login');
     673
     674                        $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild );
     675                }
     676
     677                $blog_id = absint( $qv['blog_id'] );
     678
     679                do_action_ref_array( 'pre_user_query', array( &$this ) );
     680        }
     681       
     682        /**
     683         * Execute the query, with the current variables
     684         *
     685         * @since 3.2.0
     686         * @access private
     687         */
     688        function query() {
     689                global $wpdb;
     690               
     691                $this->results = $wpdb->get_results("SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit");
     692
     693                if ( !$this->results )
     694                        return;
     695
     696                if ( $this->query_vars['count_total'] )
     697                        $this->total_users = $wpdb->get_var("SELECT COUNT(*) $this->query_from $this->query_where");
     698        }
     699}
     700
    620701/**
    621702 * Retrieve list of users matching criteria.
    622703 *