mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Users administration panel.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Administration
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /** WordPress Administration Bootstrap */
mp-wp_genesis 10 require_once('admin.php');
mp-wp_genesis 11
mp-wp_genesis 12 /** WordPress Registration API */
mp-wp_genesis 13 require_once( ABSPATH . WPINC . '/registration.php');
mp-wp_genesis 14
mp-wp_genesis 15 if ( !current_user_can('edit_users') )
mp-wp_genesis 16 wp_die(__('Cheatin’ uh?'));
mp-wp_genesis 17
mp-wp_genesis 18 $title = __('Users');
mp-wp_genesis 19 $parent_file = 'users.php';
mp-wp_genesis 20
mp-wp_genesis 21 $update = $doaction = '';
mp-wp_genesis 22 if ( isset($_REQUEST['action']) )
mp-wp_remove-all-... 23 $doaction = $_REQUEST['action'];
mp-wp_genesis 24
mp-wp_genesis 25 if ( empty($doaction) ) {
mp-wp_genesis 26 if ( isset($_GET['changeit']) && !empty($_GET['new_role']) )
mp-wp_genesis 27 $doaction = 'promote';
mp-wp_genesis 28 }
mp-wp_genesis 29
mp-wp_genesis 30 if ( empty($_REQUEST) ) {
mp-wp_genesis 31 $referer = '<input type="hidden" name="wp_http_referer" value="'. attribute_escape(stripslashes($_SERVER['REQUEST_URI'])) . '" />';
mp-wp_genesis 32 } elseif ( isset($_REQUEST['wp_http_referer']) ) {
mp-wp_genesis 33 $redirect = remove_query_arg(array('wp_http_referer', 'updated', 'delete_count'), stripslashes($_REQUEST['wp_http_referer']));
mp-wp_genesis 34 $referer = '<input type="hidden" name="wp_http_referer" value="' . attribute_escape($redirect) . '" />';
mp-wp_genesis 35 } else {
mp-wp_genesis 36 $redirect = 'users.php';
mp-wp_genesis 37 $referer = '';
mp-wp_genesis 38 }
mp-wp_genesis 39
mp-wp_genesis 40 switch ($doaction) {
mp-wp_genesis 41
mp-wp_genesis 42 case 'promote':
mp-wp_genesis 43 check_admin_referer('bulk-users');
mp-wp_genesis 44
mp-wp_genesis 45 if (empty($_REQUEST['users'])) {
mp-wp_genesis 46 wp_redirect($redirect);
mp-wp_genesis 47 exit();
mp-wp_genesis 48 }
mp-wp_genesis 49
mp-wp_genesis 50 if ( !current_user_can('edit_users') )
mp-wp_genesis 51 wp_die(__('You can’t edit users.'));
mp-wp_genesis 52
mp-wp_genesis 53 $userids = $_REQUEST['users'];
mp-wp_genesis 54 $update = 'promote';
mp-wp_genesis 55 foreach($userids as $id) {
mp-wp_genesis 56 if ( ! current_user_can('edit_user', $id) )
mp-wp_genesis 57 wp_die(__('You can’t edit that user.'));
mp-wp_genesis 58 // The new role of the current user must also have edit_users caps
mp-wp_genesis 59 if($id == $current_user->ID && !$wp_roles->role_objects[$_REQUEST['new_role']]->has_cap('edit_users')) {
mp-wp_genesis 60 $update = 'err_admin_role';
mp-wp_genesis 61 continue;
mp-wp_genesis 62 }
mp-wp_genesis 63
mp-wp_genesis 64 $user = new WP_User($id);
mp-wp_genesis 65 $user->set_role($_REQUEST['new_role']);
mp-wp_genesis 66 }
mp-wp_genesis 67
mp-wp_genesis 68 wp_redirect(add_query_arg('update', $update, $redirect));
mp-wp_genesis 69 exit();
mp-wp_genesis 70
mp-wp_genesis 71 break;
mp-wp_genesis 72
mp-wp_genesis 73 case 'dodelete':
mp-wp_genesis 74
mp-wp_genesis 75 check_admin_referer('delete-users');
mp-wp_genesis 76
mp-wp_genesis 77 if ( empty($_REQUEST['users']) ) {
mp-wp_genesis 78 wp_redirect($redirect);
mp-wp_genesis 79 exit();
mp-wp_genesis 80 }
mp-wp_genesis 81
mp-wp_genesis 82 if ( !current_user_can('delete_users') )
mp-wp_genesis 83 wp_die(__('You can’t delete users.'));
mp-wp_genesis 84
mp-wp_genesis 85 $userids = $_REQUEST['users'];
mp-wp_genesis 86 $update = 'del';
mp-wp_genesis 87 $delete_count = 0;
mp-wp_genesis 88
mp-wp_genesis 89 foreach ( (array) $userids as $id) {
mp-wp_genesis 90 if ( ! current_user_can('delete_user', $id) )
mp-wp_genesis 91 wp_die(__('You can’t delete that user.'));
mp-wp_genesis 92
mp-wp_genesis 93 if($id == $current_user->ID) {
mp-wp_genesis 94 $update = 'err_admin_del';
mp-wp_genesis 95 continue;
mp-wp_genesis 96 }
mp-wp_genesis 97 switch($_REQUEST['delete_option']) {
mp-wp_genesis 98 case 'delete':
mp-wp_genesis 99 wp_delete_user($id);
mp-wp_genesis 100 break;
mp-wp_genesis 101 case 'reassign':
mp-wp_genesis 102 wp_delete_user($id, $_REQUEST['reassign_user']);
mp-wp_genesis 103 break;
mp-wp_genesis 104 }
mp-wp_genesis 105 ++$delete_count;
mp-wp_genesis 106 }
mp-wp_genesis 107
mp-wp_genesis 108 $redirect = add_query_arg( array('delete_count' => $delete_count, 'update' => $update), $redirect);
mp-wp_genesis 109 wp_redirect($redirect);
mp-wp_genesis 110 exit();
mp-wp_genesis 111
mp-wp_genesis 112 break;
mp-wp_genesis 113
mp-wp_genesis 114 case 'delete':
mp-wp_genesis 115
mp-wp_genesis 116 check_admin_referer('bulk-users');
mp-wp_genesis 117
mp-wp_genesis 118 if ( empty($_REQUEST['users']) && empty($_REQUEST['user']) ) {
mp-wp_genesis 119 wp_redirect($redirect);
mp-wp_genesis 120 exit();
mp-wp_genesis 121 }
mp-wp_genesis 122
mp-wp_genesis 123 if ( !current_user_can('delete_users') )
mp-wp_genesis 124 $errors = new WP_Error('edit_users', __('You can’t delete users.'));
mp-wp_genesis 125
mp-wp_genesis 126 if ( empty($_REQUEST['users']) )
mp-wp_genesis 127 $userids = array(intval($_REQUEST['user']));
mp-wp_genesis 128 else
mp-wp_genesis 129 $userids = $_REQUEST['users'];
mp-wp_genesis 130
mp-wp_genesis 131 include ('admin-header.php');
mp-wp_genesis 132 ?>
mp-wp_genesis 133 <form action="" method="post" name="updateusers" id="updateusers">
mp-wp_genesis 134 <?php wp_nonce_field('delete-users') ?>
mp-wp_genesis 135 <?php echo $referer; ?>
mp-wp_genesis 136
mp-wp_genesis 137 <div class="wrap">
mp-wp_genesis 138 <?php screen_icon(); ?>
mp-wp_genesis 139 <h2><?php _e('Delete Users'); ?></h2>
mp-wp_genesis 140 <p><?php _e('You have specified these users for deletion:'); ?></p>
mp-wp_genesis 141 <ul>
mp-wp_genesis 142 <?php
mp-wp_genesis 143 $go_delete = false;
mp-wp_genesis 144 foreach ( (array) $userids as $id ) {
mp-wp_genesis 145 $id = (int) $id;
mp-wp_genesis 146 $user = new WP_User($id);
mp-wp_genesis 147 if ( $id == $current_user->ID ) {
mp-wp_genesis 148 echo "<li>" . sprintf(__('ID #%1s: %2s <strong>The current user will not be deleted.</strong>'), $id, $user->user_login) . "</li>\n";
mp-wp_genesis 149 } else {
mp-wp_genesis 150 echo "<li><input type=\"hidden\" name=\"users[]\" value=\"{$id}\" />" . sprintf(__('ID #%1s: %2s'), $id, $user->user_login) . "</li>\n";
mp-wp_genesis 151 $go_delete = true;
mp-wp_genesis 152 }
mp-wp_genesis 153 }
mp-wp_genesis 154 $all_logins = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users ORDER BY user_login");
mp-wp_genesis 155 $user_dropdown = '<select name="reassign_user">';
mp-wp_genesis 156 foreach ( (array) $all_logins as $login )
mp-wp_genesis 157 if ( $login->ID == $current_user->ID || !in_array($login->ID, $userids) )
mp-wp_genesis 158 $user_dropdown .= "<option value=\"{$login->ID}\">{$login->user_login}</option>";
mp-wp_genesis 159 $user_dropdown .= '</select>';
mp-wp_genesis 160 ?>
mp-wp_genesis 161 </ul>
mp-wp_genesis 162 <?php if ( $go_delete ) : ?>
mp-wp_genesis 163 <fieldset><p><legend><?php _e('What should be done with posts and links owned by this user?'); ?></legend></p>
mp-wp_genesis 164 <ul style="list-style:none;">
mp-wp_genesis 165 <li><label><input type="radio" id="delete_option0" name="delete_option" value="delete" checked="checked" />
mp-wp_genesis 166 <?php _e('Delete all posts and links.'); ?></label></li>
mp-wp_genesis 167 <li><input type="radio" id="delete_option1" name="delete_option" value="reassign" />
mp-wp_genesis 168 <?php echo '<label for="delete_option1">'.__('Attribute all posts and links to:')."</label> $user_dropdown"; ?></li>
mp-wp_genesis 169 </ul></fieldset>
mp-wp_genesis 170 <input type="hidden" name="action" value="dodelete" />
mp-wp_genesis 171 <p class="submit"><input type="submit" name="submit" value="<?php _e('Confirm Deletion'); ?>" class="button-secondary" /></p>
mp-wp_genesis 172 <?php else : ?>
mp-wp_genesis 173 <p><?php _e('There are no valid users selected for deletion.'); ?></p>
mp-wp_genesis 174 <?php endif; ?>
mp-wp_genesis 175 </div>
mp-wp_genesis 176 </form>
mp-wp_genesis 177 <?php
mp-wp_genesis 178
mp-wp_genesis 179 break;
mp-wp_genesis 180
mp-wp_genesis 181 default:
mp-wp_genesis 182
mp-wp_genesis 183 if ( !empty($_GET['_wp_http_referer']) ) {
mp-wp_genesis 184 wp_redirect(remove_query_arg(array('_wp_http_referer', '_wpnonce'), stripslashes($_SERVER['REQUEST_URI'])));
mp-wp_genesis 185 exit;
mp-wp_genesis 186 }
mp-wp_genesis 187
mp-wp_genesis 188 include('admin-header.php');
mp-wp_genesis 189
mp-wp_genesis 190 $usersearch = isset($_GET['usersearch']) ? $_GET['usersearch'] : null;
mp-wp_genesis 191 $userspage = isset($_GET['userspage']) ? $_GET['userspage'] : null;
mp-wp_genesis 192 $role = isset($_GET['role']) ? $_GET['role'] : null;
mp-wp_genesis 193
mp-wp_genesis 194 // Query the users
mp-wp_genesis 195 $wp_user_search = new WP_User_Search($usersearch, $userspage, $role);
mp-wp_genesis 196
mp-wp_genesis 197 $messages = array();
mp-wp_genesis 198 if ( isset($_GET['update']) ) :
mp-wp_genesis 199 switch($_GET['update']) {
mp-wp_genesis 200 case 'del':
mp-wp_genesis 201 case 'del_many':
mp-wp_genesis 202 $delete_count = isset($_GET['delete_count']) ? (int) $_GET['delete_count'] : 0;
mp-wp_genesis 203 $messages[] = '<div id="message" class="updated fade"><p>' . sprintf(__ngettext('%s user deleted', '%s users deleted', $delete_count), $delete_count) . '</p></div>';
mp-wp_genesis 204 break;
mp-wp_genesis 205 case 'add':
mp-wp_genesis 206 $messages[] = '<div id="message" class="updated fade"><p>' . __('New user created.') . '</p></div>';
mp-wp_genesis 207 break;
mp-wp_genesis 208 case 'promote':
mp-wp_genesis 209 $messages[] = '<div id="message" class="updated fade"><p>' . __('Changed roles.') . '</p></div>';
mp-wp_genesis 210 break;
mp-wp_genesis 211 case 'err_admin_role':
mp-wp_genesis 212 $messages[] = '<div id="message" class="error"><p>' . __("The current user's role must have user editing capabilities.") . '</p></div>';
mp-wp_genesis 213 $messages[] = '<div id="message" class="updated fade"><p>' . __('Other user roles have been changed.') . '</p></div>';
mp-wp_genesis 214 break;
mp-wp_genesis 215 case 'err_admin_del':
mp-wp_genesis 216 $messages[] = '<div id="message" class="error"><p>' . __("You can't delete the current user.") . '</p></div>';
mp-wp_genesis 217 $messages[] = '<div id="message" class="updated fade"><p>' . __('Other users have been deleted.') . '</p></div>';
mp-wp_genesis 218 break;
mp-wp_genesis 219 }
mp-wp_genesis 220 endif; ?>
mp-wp_genesis 221
mp-wp_genesis 222 <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?>
mp-wp_genesis 223 <div class="error">
mp-wp_genesis 224 <ul>
mp-wp_genesis 225 <?php
mp-wp_genesis 226 foreach ( $errors->get_error_messages() as $err )
mp-wp_genesis 227 echo "<li>$err</li>\n";
mp-wp_genesis 228 ?>
mp-wp_genesis 229 </ul>
mp-wp_genesis 230 </div>
mp-wp_genesis 231 <?php endif;
mp-wp_genesis 232
mp-wp_genesis 233 if ( ! empty($messages) ) {
mp-wp_genesis 234 foreach ( $messages as $msg )
mp-wp_genesis 235 echo $msg;
mp-wp_genesis 236 } ?>
mp-wp_genesis 237
mp-wp_genesis 238 <div class="wrap">
mp-wp_genesis 239 <?php screen_icon(); ?>
mp-wp_genesis 240 <h2><?php echo wp_specialchars( $title );
mp-wp_genesis 241 if ( isset($_GET['s']) && $_GET['s'] )
mp-wp_genesis 242 printf( '<span class="subtitle">' . __('Search results for “%s”') . '</span>', wp_specialchars( get_search_query() ) ); ?>
mp-wp_genesis 243 </h2>
mp-wp_genesis 244
mp-wp_genesis 245 <div class="filter">
mp-wp_genesis 246 <form id="list-filter" action="" method="get">
mp-wp_genesis 247 <ul class="subsubsub">
mp-wp_genesis 248 <?php
mp-wp_genesis 249 $role_links = array();
mp-wp_genesis 250 $avail_roles = array();
mp-wp_genesis 251 $users_of_blog = get_users_of_blog();
mp-wp_genesis 252 $total_users = count( $users_of_blog );
mp-wp_genesis 253 foreach ( (array) $users_of_blog as $b_user ) {
mp-wp_genesis 254 $b_roles = unserialize($b_user->meta_value);
mp-wp_genesis 255 foreach ( (array) $b_roles as $b_role => $val ) {
mp-wp_genesis 256 if ( !isset($avail_roles[$b_role]) )
mp-wp_genesis 257 $avail_roles[$b_role] = 0;
mp-wp_genesis 258 $avail_roles[$b_role]++;
mp-wp_genesis 259 }
mp-wp_genesis 260 }
mp-wp_genesis 261 unset($users_of_blog);
mp-wp_genesis 262
mp-wp_genesis 263 $current_role = false;
mp-wp_genesis 264 $class = empty($role) ? ' class="current"' : '';
mp-wp_genesis 265 $role_links[] = "<li><a href='users.php'$class>" . sprintf( __ngettext( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $total_users ), number_format_i18n( $total_users ) ) . '</a>';
mp-wp_genesis 266 foreach ( $wp_roles->get_names() as $this_role => $name ) {
mp-wp_genesis 267 if ( !isset($avail_roles[$this_role]) )
mp-wp_genesis 268 continue;
mp-wp_genesis 269
mp-wp_genesis 270 $class = '';
mp-wp_genesis 271
mp-wp_genesis 272 if ( $this_role == $role ) {
mp-wp_genesis 273 $current_role = $role;
mp-wp_genesis 274 $class = ' class="current"';
mp-wp_genesis 275 }
mp-wp_genesis 276
mp-wp_genesis 277 $name = translate_with_context($name);
mp-wp_genesis 278 $name = sprintf( _c('%1$s <span class="count">(%2$s)</span>|user role with count'), $name, $avail_roles[$this_role] );
mp-wp_genesis 279 $role_links[] = "<li><a href='users.php?role=$this_role'$class>$name</a>";
mp-wp_genesis 280 }
mp-wp_genesis 281 echo implode( " |</li>\n", $role_links) . '</li>';
mp-wp_genesis 282 unset($role_links);
mp-wp_genesis 283 ?>
mp-wp_genesis 284 </ul>
mp-wp_genesis 285 </form>
mp-wp_genesis 286 </div>
mp-wp_genesis 287
mp-wp_genesis 288 <form class="search-form" action="" method="get">
mp-wp_genesis 289 <p class="search-box">
mp-wp_genesis 290 <label class="hidden" for="user-search-input"><?php _e( 'Search Users' ); ?>:</label>
mp-wp_genesis 291 <input type="text" class="search-input" id="user-search-input" name="usersearch" value="<?php echo attribute_escape($wp_user_search->search_term); ?>" />
mp-wp_genesis 292 <input type="submit" value="<?php _e( 'Search Users' ); ?>" class="button" />
mp-wp_genesis 293 </p>
mp-wp_genesis 294 </form>
mp-wp_genesis 295
mp-wp_genesis 296 <form id="posts-filter" action="" method="get">
mp-wp_genesis 297 <div class="tablenav">
mp-wp_genesis 298
mp-wp_genesis 299 <?php if ( $wp_user_search->results_are_paged() ) : ?>
mp-wp_genesis 300 <div class="tablenav-pages"><?php $wp_user_search->page_links(); ?></div>
mp-wp_genesis 301 <?php endif; ?>
mp-wp_genesis 302
mp-wp_genesis 303 <div class="alignleft actions">
mp-wp_genesis 304 <select name="action">
mp-wp_genesis 305 <option value="" selected="selected"><?php _e('Bulk Actions'); ?></option>
mp-wp_genesis 306 <option value="delete"><?php _e('Delete'); ?></option>
mp-wp_genesis 307 </select>
mp-wp_genesis 308 <input type="submit" value="<?php _e('Apply'); ?>" name="doaction" id="doaction" class="button-secondary action" />
mp-wp_genesis 309 <label class="hidden" for="new_role"><?php _e('Change role to…') ?></label><select name="new_role" id="new_role"><option value=''><?php _e('Change role to…') ?></option><?php wp_dropdown_roles(); ?></select>
mp-wp_genesis 310 <input type="submit" value="<?php _e('Change'); ?>" name="changeit" class="button-secondary" />
mp-wp_genesis 311 <?php wp_nonce_field('bulk-users'); ?>
mp-wp_genesis 312 </div>
mp-wp_genesis 313
mp-wp_genesis 314 <br class="clear" />
mp-wp_genesis 315 </div>
mp-wp_genesis 316
mp-wp_genesis 317 <?php if ( is_wp_error( $wp_user_search->search_errors ) ) : ?>
mp-wp_genesis 318 <div class="error">
mp-wp_genesis 319 <ul>
mp-wp_genesis 320 <?php
mp-wp_genesis 321 foreach ( $wp_user_search->search_errors->get_error_messages() as $message )
mp-wp_genesis 322 echo "<li>$message</li>";
mp-wp_genesis 323 ?>
mp-wp_genesis 324 </ul>
mp-wp_genesis 325 </div>
mp-wp_genesis 326 <?php endif; ?>
mp-wp_genesis 327
mp-wp_genesis 328
mp-wp_genesis 329 <?php if ( $wp_user_search->get_results() ) : ?>
mp-wp_genesis 330
mp-wp_genesis 331 <?php if ( $wp_user_search->is_search() ) : ?>
mp-wp_genesis 332 <p><a href="users.php"><?php _e('← Back to All Users'); ?></a></p>
mp-wp_genesis 333 <?php endif; ?>
mp-wp_genesis 334
mp-wp_genesis 335 <table class="widefat fixed" cellspacing="0">
mp-wp_genesis 336 <thead>
mp-wp_genesis 337 <tr class="thead">
mp-wp_genesis 338 <?php print_column_headers('users') ?>
mp-wp_genesis 339 </tr>
mp-wp_genesis 340 </thead>
mp-wp_genesis 341 <tbody id="users" class="list:user user-list">
mp-wp_genesis 342 <?php
mp-wp_genesis 343 $style = '';
mp-wp_genesis 344 foreach ( $wp_user_search->get_results() as $userid ) {
mp-wp_genesis 345 $user_object = new WP_User($userid);
mp-wp_genesis 346 $roles = $user_object->roles;
mp-wp_genesis 347 $role = array_shift($roles);
mp-wp_genesis 348
mp-wp_genesis 349 $style = ( ' class="alternate"' == $style ) ? '' : ' class="alternate"';
mp-wp_genesis 350 echo "\n\t" . user_row($user_object, $style, $role);
mp-wp_genesis 351 }
mp-wp_genesis 352 ?>
mp-wp_genesis 353 </tbody>
mp-wp_genesis 354 </table>
mp-wp_genesis 355
mp-wp_genesis 356 <?php endif; ?>
mp-wp_genesis 357
mp-wp_genesis 358 </form>
mp-wp_genesis 359 </div>
mp-wp_genesis 360
mp-wp_genesis 361 <?php
mp-wp_genesis 362 foreach ( array('user_login' => 'user_login', 'first_name' => 'user_firstname', 'last_name' => 'user_lastname', 'email' => 'user_email', 'url' => 'user_uri', 'role' => 'user_role') as $formpost => $var ) {
mp-wp_genesis 363 $var = 'new_' . $var;
mp-wp_genesis 364 $$var = isset($_REQUEST[$formpost]) ? attribute_escape(stripslashes($_REQUEST[$formpost])) : '';
mp-wp_genesis 365 }
mp-wp_genesis 366 unset($name);
mp-wp_genesis 367 ?>
mp-wp_genesis 368
mp-wp_genesis 369 <br class="clear" />
mp-wp_genesis 370 <?php
mp-wp_genesis 371 break;
mp-wp_genesis 372
mp-wp_genesis 373 } // end of the $doaction switch
mp-wp_genesis 374
mp-wp_genesis 375 include('admin-footer.php');
mp-wp_genesis 376 ?>