Ticket #16001: 16001.2.diff
File 16001.2.diff, 19.1 KB (added by , 12 years ago) |
---|
-
wp-includes/user.php
650 650 } 651 651 652 652 /** 653 * WordPress Pending User Query class. 654 * 655 * @since 3.6.0 656 */ 657 class WP_Pending_User_Query extends WP_User_Query { 658 659 public function prepare_query() { 660 global $wpdb; 661 662 $qv =& $this->query_vars; 663 $this->query_fields = "{$wpdb->signups}.*"; 664 665 $this->query_from = "FROM {$wpdb->signups}"; 666 $this->query_where = "WHERE 1=1 AND active != 1"; 667 668 // sorting 669 if ( in_array( $qv['orderby'], array( 'nicename', 'email' ) ) ) { 670 $orderby = 'user_' . $qv['orderby']; 671 } elseif ( in_array( $qv['orderby'], array( 'user_email', 'registered' ) ) ) { 672 $orderby = $qv['orderby']; 673 } else { 674 $orderby = 'user_login'; 675 } 676 677 $qv['order'] = strtoupper( $qv['order'] ); 678 $order = 'ASC' == $qv['order'] ? 'ASC' : 'DESC'; 679 $this->query_orderby = "ORDER BY $orderby $order"; 680 681 // limit 682 if ( $qv['number'] ) { 683 if ( $qv['offset'] ) 684 $this->query_limit = $wpdb->prepare( "LIMIT %d, %d", $qv['offset'], $qv['number'] ); 685 else 686 $this->query_limit = $wpdb->prepare( "LIMIT %d", $qv['number'] ); 687 } 688 689 $search = trim( $qv['search'] ); 690 if ( $search ) { 691 $leading_wild = ( ltrim( $search, '*' ) != $search ); 692 $trailing_wild = ( rtrim( $search, '*' ) != $search ); 693 694 $wild = false; 695 if ( $leading_wild && $trailing_wild ) 696 $wild = 'both'; 697 elseif ( $leading_wild ) 698 $wild = 'leading'; 699 elseif ( $trailing_wild ) 700 $wild = 'trailing'; 701 702 if ( $wild ) 703 $search = trim($search, '*'); 704 705 if ( false !== strpos( $search, '@') ) 706 $search_columns = array( 'user_email' ); 707 else 708 $search_columns = array( 'user_login' ); 709 710 $this->query_where .= $this->get_search_sql( $search, $search_columns, $wild ); 711 } 712 713 $blog_id = absint( $qv['blog_id'] ); 714 715 do_action_ref_array( 'pre_user_query', array( $this ) ); 716 } 717 718 /** 719 * Execute the query, with the current variables 720 * 721 * @since 3.6.0 722 */ 723 public function query() { 724 global $wpdb; 725 726 $this->results = $wpdb->get_results( "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit" ); 727 728 if ( ! $this->results ) 729 return; 730 731 if ( $this->query_vars['count_total'] ) 732 $this->total_users = $wpdb->get_var( "SELECT COUNT(*) $this->query_from $this->query_where" ); 733 } 734 } 735 736 /** 653 737 * Retrieve list of users matching criteria. 654 738 * 655 739 * @since 3.1.0 -
wp-includes/ms-functions.php
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; 132 136 } 133 137 134 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; 153 } 154 155 /** 135 156 * The number of active sites on your installation. 136 157 * 137 158 * The count is cached and updated twice daily. This is not a live count. … … 926 947 } 927 948 928 949 /** 950 * Active user automatically after looking up via user_login 951 * 952 * @since 3.6.0 953 * 954 * @uses wpmu_activate_signup() 955 * 956 * @global wpdb $wpdb 957 * 958 * @param string $user_login 959 * @return array An array containing information about the activated user and/or blog 960 */ 961 function wp_activate_by_user_login( $user_login ) { 962 global $wpdb; 963 964 $key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE active != 1 AND user_login = %s", $user_login ) ); 965 if ( $key ) 966 return wpmu_activate_signup( $key ); 967 } 968 969 /** 970 * Lookup signup and, when valid, resend the signup notification 971 * 972 * @since 3.6.0 973 * 974 * @uses wpmu_signup_user_notification() 975 * 976 * @global wpdb $wpdb 977 * 978 * @param string $user_login 979 * @return bool 980 */ 981 function wp_resend_by_user_login( $user_login ) { 982 global $wpdb; 983 984 $user = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->signups} WHERE active !=1 AND user_login = %s", $user_login ) ); 985 986 if ( $user ) 987 return wpmu_signup_user_notification( $user->user_login, $user->user_email, $user->activation_key, $user->meta ); 988 } 989 990 /** 929 991 * Create a site. 930 992 * 931 993 * This function runs when a user self-registers a new site as well … … 1925 1987 function wp_update_network_counts() { 1926 1988 global $wpdb; 1927 1989 1928 $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) );1990 $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 ) ); 1929 1991 update_site_option( 'blog_count', $count ); 1930 1992 1931 1993 $count = $wpdb->get_var( "SELECT COUNT(ID) as c FROM $wpdb->users WHERE spam = '0' AND deleted = '0'" ); 1932 1994 update_site_option( 'user_count', $count ); 1995 1996 $count = $wpdb->get_var( "SELECT COUNT(user_login) AS c FROM $wpdb->signups WHERE active != 1" ); 1997 update_site_option( 'pending_user_count', $count ); 1933 1998 } 1934 1999 1935 2000 /** -
wp-admin/includes/class-wp-ms-users-list-table.php
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 … … 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 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 } 92 79 93 return $actions; 80 94 } 81 95 … … 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 } … … 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(); … … 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 ?> … … 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( stripslashes( $_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 } 177 211 212 $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 ) ) ); 213 $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 ) ) ); 214 178 215 echo "<td $attributes>"; ?> 179 <?php echo $avatar; ?><strong><a href="<?php echo $edit_link; ?>" class="edit"><?php echo stripslashes( $user->user_login ); ?></a><?php 216 <?php echo $avatar; ?><strong><?php 217 218 if ( $role == 'pending' ): ?> 219 <?php echo stripslashes( $user->user_login ); ?> 220 <?php else: ?> 221 <a href="<?php echo $edit_link; ?>" class="edit"><?php echo stripslashes( $user->user_login ); ?></a> 222 <?php endif; 223 180 224 if ( in_array( $user->user_login, $super_admins ) ) 181 225 echo ' - ' . __( 'Super Admin' ); 182 226 ?></strong> 183 227 <br/> 184 228 <?php 185 229 $actions = array(); 186 $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';187 230 231 if ( 'pending' === $role ) { 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 } 237 188 238 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( stripslashes( $_SERVER['REQUEST_URI'] ) ), wp_nonce_url( 'users.php', 'deleteuser' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>'; 239 if ( 'pending' === $role ) { 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' ) . '&action=deletesignup&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( 'users.php', 'deleteuser' ) . '&action=deleteuser&id=' . $user->ID ) ) ) . '" class="delete">' . __( 'Delete' ) . '</a>'; 243 } 190 244 } 191 245 192 246 $actions = apply_filters( 'ms_user_row_actions', $actions, $user ); -
wp-admin/network/users.php
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(); … … 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'] ); … … 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 … … 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' ) ) … … 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 } … … 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'] ) ) { … … 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 … … 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>