Ticket #16001: 16001.3.diff
File 16001.3.diff, 19.6 KB (added by , 11 years ago) |
---|
-
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 ab1ee36..3897054 100644
class WP_MS_Users_List_Table extends WP_List_Table { 58 58 59 59 $mode = empty( $_REQUEST['mode'] ) ? 'list' : $_REQUEST['mode']; 60 60 61 // Query the user IDs for this page 62 $wp_user_search = new WP_User_Query( $args ); 61 if ( 'pending' === $role ) 62 $wp_user_search = new WP_Pending_User_Query( $args ); // Query for pending users 63 else 64 $wp_user_search = new WP_User_Query( $args ); // Query the user IDs for this page 63 65 64 66 $this->items = $wp_user_search->get_results(); 65 67 … … class WP_MS_Users_List_Table extends WP_List_Table { 70 72 } 71 73 72 74 function get_bulk_actions() { 75 global $role; 76 73 77 $actions = array(); 74 if ( current_user_can( 'delete_users' ) ) 75 $actions['delete'] = __( 'Delete' ); 76 $actions['spam'] = _x( 'Mark as Spam', 'user' ); 77 $actions['notspam'] = _x( 'Not Spam', 'user' ); 78 79 if ( $role == 'pending' ) { 80 if ( current_user_can( 'delete_users' ) ) 81 $actions['deletesignup'] = __( 'Delete' ); 82 83 $actions['activate'] = _x( 'Activate', 'user' ); 84 $actions['resend'] = __( 'Resend Email', 'user' ); 85 } else { 86 if ( current_user_can( 'delete_users' ) ) 87 $actions['delete'] = __( 'Delete' ); 88 89 $actions['spam'] = _x( 'Mark as Spam', 'user' ); 90 $actions['notspam'] = _x( 'Not Spam', 'user' ); 91 } 78 92 79 93 return $actions; 80 94 } … … class WP_MS_Users_List_Table extends WP_List_Table { 89 103 $total_users = get_user_count(); 90 104 $super_admins = get_super_admins(); 91 105 $total_admins = count( $super_admins ); 106 $total_pendings = get_pending_user_count(); 92 107 93 $current_role = false; 94 $class = $role != 'super' ? ' class="current"' : ''; 108 $class = in_array( $role, array( 'super', 'pending' ) ) ? '' : ' class="current"'; 95 109 $role_links = array(); 96 $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>';110 $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>'; 97 111 $class = $role == 'super' ? ' class="current"' : ''; 98 $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>'; 112 $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>'; 113 $class = $role == 'pending' ? ' class="current"' : ''; 114 $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>'; 99 115 100 116 return $role_links; 101 117 } … … class WP_MS_Users_List_Table extends WP_List_Table { 110 126 } 111 127 112 128 function get_columns() { 129 global $role; 130 113 131 $users_columns = array( 114 132 'cb' => '<input type="checkbox" />', 115 133 'username' => __( 'Username' ), 116 'name' => __( 'Name' ),117 134 'email' => __( 'E-mail' ), 118 135 'registered' => _x( 'Registered', 'user' ), 119 'blogs' => __( 'Sites' )120 136 ); 121 $users_columns = apply_filters( 'wpmu_users_columns', $users_columns );122 137 123 return $users_columns; 138 if ( 'pending' !== $role ) { 139 $users_columns['name'] = __( 'Name' ); 140 $users_columns['blogs'] = __( 'Sites' ); 141 } 142 143 return apply_filters( 'wpmu_users_columns', $users_columns ); 124 144 } 125 145 126 146 function get_sortable_columns() { 127 return array( 147 global $role; 148 149 $sortables = array( 128 150 'username' => 'login', 129 'name' => 'name',130 151 'email' => 'email', 131 152 'registered' => 'id', 132 153 ); 154 155 if ( 'pending' !== $role ) 156 $sortables['name'] = 'name'; 157 158 return $sortables; 133 159 } 134 160 135 161 function display_rows() { 136 global $current_site, $mode ;162 global $current_site, $mode, $role; 137 163 138 164 $alt = ''; 139 165 $super_admins = get_super_admins(); … … class WP_MS_Users_List_Table extends WP_List_Table { 142 168 143 169 $status_list = array( 'spam' => 'site-spammed', 'deleted' => 'site-deleted' ); 144 170 145 foreach ( $status_list as $status => $col ) { 146 if ( $user->$status ) 147 $alt .= " $col"; 171 if ( 'pending' === $role ) { 172 $user->ID = $user->user_login; 173 $user->user_registered = $user->registered; 174 } else { 175 foreach ( $status_list as $status => $col ) 176 if ( $user->$status ) 177 $alt .= " $col"; 148 178 } 149 179 150 180 ?> … … class WP_MS_Users_List_Table extends WP_List_Table { 173 203 174 204 case 'username': 175 205 $avatar = get_avatar( $user->user_email, 32 ); 176 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); 206 if ( get_current_user_id() == $user->ID ) { 207 $edit_link = esc_url( self_admin_url( 'profile.php' ) ); 208 } else { 209 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user->ID ) ) ); 210 } 211 $activate_link = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'activatesignup' ) . '&action=activatesignup&user_login=' . $user->user_login ) ) ); 212 $resend_link = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'resendsignup' ) . '&action=resendsignup&user_login=' . $user->user_login ) ) ); 177 213 178 214 echo "<td $attributes>"; ?> 179 <?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo $user->user_login; ?></a><?php 215 <?php echo $avatar; ?><strong><?php 216 217 if ( $role == 'pending' ): 218 echo stripslashes( $user->user_login ); 219 else: ?> 220 <a href="<?php echo $edit_link; ?>" class="edit"><?php echo stripslashes( $user->user_login ); ?></a> 221 <?php endif; 222 180 223 if ( in_array( $user->user_login, $super_admins ) ) 181 224 echo ' - ' . __( 'Super Admin' ); 182 225 ?></strong> 183 226 <br/> 184 227 <?php 185 228 $actions = array(); 186 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; 187 229 if ( 'pending' === $role ) { 230 $actions['activate'] = '<a href="' . $activate_link . '">' . __( 'Activate' ) . '</a>'; 231 $actions['resend'] = '<a href="' . $resend_link . '">' . __( 'Resend Email' ) . '</a>'; 232 } else { 233 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>'; 234 } 188 235 if ( current_user_can( 'delete_user', $user->ID ) && ! in_array( $user->user_login, $super_admins ) ) { 189 $actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>'; 236 if ( 'pending' === $role ) { 237 $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' ) . '&action=deletesignup&user_login=' . $user->user_login ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>'; 238 } else { 239 $actions['delete'] = '<a href="' . $delete = esc_url( network_admin_url( add_query_arg( '_wp_http_referer', urlencode( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>'; 240 } 190 241 } 191 242 192 243 $actions = apply_filters( 'ms_user_row_actions', $actions, $user ); -
wp-admin/network/users.php
diff --git wp-admin/network/users.php wp-admin/network/users.php index 1318355..0ba368f 100644
if ( ! is_multisite() ) 16 16 if ( ! current_user_can( 'manage_network_users' ) ) 17 17 wp_die( __( 'You do not have permission to access this page.' ) ); 18 18 19 function confirm_delete_signups( $signups ) { 20 if ( ! is_array( $signups ) ) 21 return false; 22 ?> 23 <h2><?php esc_html_e( 'Users' ); ?></h2> 24 <p><?php _e( 'Transfer or delete posts before deleting users.' ); ?></p> 25 <form action="users.php?action=dodeletesignup" method="post"> 26 <input type="hidden" name="dodeletesignup" /> 27 <?php wp_nonce_field( 'ms-signups-delete' ); ?> 28 <ul> 29 <?php 30 foreach ( $signups as $delete_signup ) { 31 echo "<li><input type='hidden' name='user[]' value='{$delete_signup}'/>{$delete_signup}</li>\n"; 32 } 33 ?> 34 </ul> 35 <?php submit_button( __( 'Confirm Deletion' ), 'delete' ); ?> 36 </form> 37 <?php 38 return true; 39 } 40 19 41 function confirm_delete_users( $users ) { 20 42 $current_user = wp_get_current_user(); 21 if ( ! is_array( $users ) )43 if ( ! is_array( $users ) ) 22 44 return false; 23 45 24 46 screen_icon(); … … if ( isset( $_GET['action'] ) ) { 91 113 92 114 switch ( $_GET['action'] ) { 93 115 case 'deleteuser': 94 if ( ! current_user_can( 'manage_network_users' ) )95 wp_die( __( 'You do not have permission to access this page.' ) );96 97 116 check_admin_referer( 'deleteuser' ); 98 117 99 118 $id = intval( $_GET['id'] ); … … if ( isset( $_GET['action'] ) ) { 113 132 break; 114 133 115 134 case 'allusers': 116 if ( !current_user_can( 'manage_network_users' ) )117 wp_die( __( 'You do not have permission to access this page.' ) );118 119 135 if ( ( isset( $_POST['action']) || isset($_POST['action2'] ) ) && isset( $_POST['allusers'] ) ) { 120 136 check_admin_referer( 'bulk-users-network' ); 121 137 … … if ( isset( $_GET['action'] ) ) { 123 139 $userfunction = ''; 124 140 125 141 foreach ( (array) $_POST['allusers'] as $key => $val ) { 126 if ( ! empty( $val ) ) {142 if ( ! empty( $val ) ) { 127 143 switch ( $doaction ) { 128 144 case 'delete': 129 145 if ( ! current_user_can( 'delete_users' ) ) … … if ( isset( $_GET['action'] ) ) { 160 176 161 177 update_user_status( $val, 'spam', '0' ); 162 178 break; 179 180 case 'activate': 181 $userfunction = 'all_activate'; 182 wp_activate_by_user_login( $val ); 183 break; 184 185 case 'resend': 186 $userfunction = 'all_resend'; 187 wp_resend_by_user_login( $val ); 188 break; 189 190 case 'deletesignup': 191 if ( ! current_user_can( 'delete_users' ) ) 192 wp_die( __( 'You do not have permission to access this page.' ) ); 193 194 $title = __( 'Users' ); 195 $parent_file = 'users.php'; 196 require_once( '../admin-header.php' ); 197 echo '<div class="wrap">'; 198 confirm_delete_signups( $_POST['allusers'] ); 199 echo '</div>'; 200 require_once( '../admin-footer.php' ); 201 exit(); 202 break; 163 203 } 164 204 } 165 205 } … … if ( isset( $_GET['action'] ) ) { 177 217 178 218 case 'dodelete': 179 219 check_admin_referer( 'ms-users-delete' ); 180 if ( ! ( current_user_can( 'manage_network_users' ) && current_user_can( 'delete_users' )) )220 if ( ! current_user_can( 'delete_users' ) ) 181 221 wp_die( __( 'You do not have permission to access this page.' ) ); 182 222 183 223 if ( ! empty( $_POST['blog'] ) && is_array( $_POST['blog'] ) ) { … … if ( isset( $_GET['action'] ) ) { 210 250 wp_redirect( add_query_arg( array( 'updated' => 'true', 'action' => $deletefunction ), network_admin_url( 'users.php' ) ) ); 211 251 exit(); 212 252 break; 253 254 case 'activatesignup': 255 check_admin_referer( 'activatesignup' ); 256 257 wp_activate_by_user_login( $_GET['user_login'] ); 258 259 wp_redirect( add_query_arg( array( 'role' => 'pending', 'updated' => 'true', 'action' => 'activate' ), network_admin_url( 'users.php' ) ) ); 260 exit(); 261 break; 262 263 case 'resendsignup': 264 check_admin_referer( 'resendsignup' ); 265 266 wp_resend_by_user_login( $_GET['user_login'] ); 267 268 wp_redirect( add_query_arg( array( 'role' => 'pending', 'updated' => 'true', 'action' => 'resend' ), network_admin_url( 'users.php' ) ) ); 269 exit(); 270 break; 271 272 case 'deletesignup': 273 check_admin_referer( 'deletesignup' ); 274 275 if ( ! empty( $_GET['user_login'] ) ) { 276 $title = __( 'Users' ); 277 $parent_file = 'users.php'; 278 require_once( '../admin-header.php' ); 279 echo '<div class="wrap">'; 280 confirm_delete_signups( array( $_GET['user_login'] ) ); 281 echo '</div>'; 282 require_once( '../admin-footer.php' ); 283 } else { 284 wp_redirect( add_query_arg( array( 'role' => 'pending' ), network_admin_url( 'users.php' ) ) ); 285 } 286 exit(); 287 break; 288 289 case 'dodeletesignup': 290 if ( ! current_user_can( 'delete_users' ) ) 291 wp_die( __( 'You do not have permission to access this page.' ) ); 292 293 check_admin_referer( 'ms-signups-delete' ); 294 295 if ( ! empty( $_POST['user'] ) ) { 296 array_walk( $_POST['user'], array( &$wpdb, 'escape_by_ref' ) ); 297 $wpdb->query( "DELETE FROM {$wpdb->signups} WHERE active != 1 AND user_login IN ('" . implode( "','", $_POST['user'] ) . "')" ); 298 } 299 300 if ( count( $_POST['user'] ) > 1 ) { 301 $delete_action = 'all_delete'; 302 } else { 303 $delete_action = 'delete'; 304 } 305 306 wp_redirect( add_query_arg( array( 'role' => 'pending', 'updated' => 'true', 'action' => $delete_action ), network_admin_url( 'users.php' ) ) ); 307 exit(); 308 break; 213 309 } 214 310 } 215 311 … … if ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] == 'true' && ! empty( 267 363 case 'add': 268 364 _e( 'User added.' ); 269 365 break; 366 case 'activate': 367 _e( 'User activated.' ); 368 break; 369 case 'resend': 370 _e( 'Activation instruction resent to user.'); 371 break; 372 case 'all_activate': 373 _e( 'Users activated.' ); 374 break; 375 case 'all_resend': 376 _e( 'Activation instruction resent to users.'); 377 break; 270 378 } 271 379 ?> 272 380 </p></div> -
wp-includes/ms-functions.php
diff --git wp-includes/ms-functions.php wp-includes/ms-functions.php index 1037a9f..94243db 100644
function get_active_blog_for_user( $user_id ) { 128 128 * @return int 129 129 */ 130 130 function get_user_count() { 131 return get_site_option( 'user_count' ); 131 $option = get_site_option( 'user_count' ); 132 if ( is_numeric( $option ) ) 133 return (int) $option; 134 135 return 0; 136 } 137 138 /** 139 * The number of pending users in your installation. 140 * 141 * The count is cached and updated twice daily. This is not a live count. 142 * 143 * @since 3.6 144 * 145 * @return int 146 */ 147 function get_pending_user_count() { 148 $option = get_site_option( 'pending_user_count' ); 149 if ( is_numeric( $option ) ) 150 return (int) $option; 151 152 return 0; 132 153 } 133 154 134 155 /** … … function wpmu_create_user( $user_name, $password, $email ) { 910 931 } 911 932 912 933 /** 934 * Active user automatically after looking up via user_login 935 * 936 * @since 3.6.0 937 * 938 * @uses wpmu_activate_signup() 939 * 940 * @global wpdb $wpdb 941 * 942 * @param string $user_login 943 * @return array An array containing information about the activated user and/or blog 944 */ 945 function wp_activate_by_user_login( $user_login ) { 946 global $wpdb; 947 948 $key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE active != 1 AND user_login = %s", $user_login ) ); 949 if ( $key ) 950 return wpmu_activate_signup( $key ); 951 } 952 953 /** 954 * Lookup signup and, when valid, resend the signup notification 955 * 956 * @since 3.6.0 957 * 958 * @uses wpmu_signup_user_notification() 959 * 960 * @global wpdb $wpdb 961 * 962 * @param string $user_login 963 * @return bool 964 */ 965 function wp_resend_by_user_login( $user_login ) { 966 global $wpdb; 967 968 $user = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->signups} WHERE active !=1 AND user_login = %s", $user_login ) ); 969 970 if ( $user ) 971 return wpmu_signup_user_notification( $user->user_login, $user->user_email, $user->activation_key, $user->meta ); 972 } 973 974 /** 913 975 * Create a site. 914 976 * 915 977 * This function runs when a user self-registers a new site as well … … function wp_schedule_update_network_counts() { 1883 1945 function wp_update_network_counts() { 1884 1946 global $wpdb; 1885 1947 1886 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $wpdb->siteid) );1948 $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(blog_id) as c FROM $wpdb->blogs WHERE site_id = %d AND spam = '0' AND deleted = '0' and archived = '0'", $wpdb->siteid ) ); 1887 1949 update_site_option( 'blog_count', $count ); 1888 1950 1889 1951 $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" ); 1890 1952 update_site_option( 'user_count', $count ); 1953 1954 $count = $wpdb->get_var( "SELECT COUNT(user_login) AS c FROM $wpdb->signups WHERE active != 1" ); 1955 update_site_option( 'pending_user_count', $count ); 1891 1956 } 1892 1957 1893 1958 /** -
wp-includes/user.php
diff --git wp-includes/user.php wp-includes/user.php index bc583a5..55f1011 100644
class WP_User_Query { 649 649 } 650 650 651 651 /** 652 * WordPress Pending User Query class. 653 * 654 * @since 3.6.0 655 */ 656 class WP_Pending_User_Query extends WP_User_Query { 657 658 public function prepare_query() { 659 global $wpdb; 660 661 $qv =& $this->query_vars; 662 $this->query_fields = "{$wpdb->signups}.*"; 663 664 $this->query_from = "FROM {$wpdb->signups}"; 665 $this->query_where = "WHERE 1=1 AND active != 1"; 666 667 // sorting 668 if ( in_array( $qv['orderby'], array( 'nicename', 'email' ) ) ) { 669 $orderby = 'user_' . $qv['orderby']; 670 } elseif ( in_array( $qv['orderby'], array( 'user_email', 'registered' ) ) ) { 671 $orderby = $qv['orderby']; 672 } else { 673 $orderby = 'user_login'; 674 } 675 676 $qv['order'] = strtoupper( $qv['order'] ); 677 $order = 'ASC' == $qv['order'] ? 'ASC' : 'DESC'; 678 $this->query_orderby = "ORDER BY $orderby $order"; 679 680 // limit 681 if ( $qv['number'] ) { 682 if ( $qv['offset'] ) 683 $this->query_limit = $wpdb->prepare( "LIMIT %d, %d", $qv['offset'], $qv['number'] ); 684 else 685 $this->query_limit = $wpdb->prepare( "LIMIT %d", $qv['number'] ); 686 } 687 688 $search = trim( $qv['search'] ); 689 if ( $search ) { 690 $leading_wild = ( ltrim( $search, '*' ) != $search ); 691 $trailing_wild = ( rtrim( $search, '*' ) != $search ); 692 693 $wild = false; 694 if ( $leading_wild && $trailing_wild ) 695 $wild = 'both'; 696 elseif ( $leading_wild ) 697 $wild = 'leading'; 698 elseif ( $trailing_wild ) 699 $wild = 'trailing'; 700 701 if ( $wild ) 702 $search = trim($search, '*'); 703 704 if ( false !== strpos( $search, '@') ) 705 $search_columns = array( 'user_email' ); 706 else 707 $search_columns = array( 'user_login' ); 708 709 $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild ); 710 } 711 712 $blog_id = absint( $qv['blog_id'] ); 713 714 do_action_ref_array( 'pre_user_query', array( $this ) ); 715 } 716 717 /** 718 * Execute the query, with the current variables 719 * 720 * @since 3.6.0 721 */ 722 public function query() { 723 global $wpdb; 724 725 $this->results = $wpdb->get_results( "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit" ); 726 727 if ( ! $this->results ) 728 return; 729 730 if ( $this->query_vars['count_total'] ) 731 $this->total_users = $wpdb->get_var( "SELECT COUNT(*) $this->query_from $this->query_where" ); 732 } 733 } 734 735 /** 652 736 * Retrieve list of users matching criteria. 653 737 * 654 738 * @since 3.1.0