|
1 <?php |
|
2 /** |
|
3 * New User Administration Panel. |
|
4 * |
|
5 * @package WordPress |
|
6 * @subpackage Administration |
|
7 */ |
|
8 |
|
9 /** WordPress Administration Bootstrap */ |
|
10 require_once('admin.php'); |
|
11 |
|
12 if ( !current_user_can('create_users') ) |
|
13 wp_die(__('Cheatin’ uh?')); |
|
14 |
|
15 /** WordPress Registration API */ |
|
16 require_once( ABSPATH . WPINC . '/registration.php'); |
|
17 |
|
18 if ( isset($_REQUEST['action']) && 'adduser' == $_REQUEST['action'] ) { |
|
19 check_admin_referer('add-user'); |
|
20 |
|
21 if ( ! current_user_can('create_users') ) |
|
22 wp_die(__('You can’t create users.')); |
|
23 |
|
24 $user_id = add_user(); |
|
25 |
|
26 if ( is_wp_error( $user_id ) ) { |
|
27 $add_user_errors = $user_id; |
|
28 } else { |
|
29 $new_user_login = apply_filters('pre_user_login', sanitize_user(stripslashes($_REQUEST['user_login']), true)); |
|
30 $redirect = 'users.php?usersearch='. urlencode($new_user_login) . '&update=add'; |
|
31 wp_redirect( $redirect . '#user-' . $user_id ); |
|
32 die(); |
|
33 } |
|
34 } |
|
35 |
|
36 $title = __('Add New User'); |
|
37 $parent_file = 'users.php'; |
|
38 |
|
39 wp_enqueue_script('wp-ajax-response'); |
|
40 wp_enqueue_script('user-profile'); |
|
41 wp_enqueue_script('password-strength-meter'); |
|
42 |
|
43 require_once ('admin-header.php'); |
|
44 |
|
45 ?> |
|
46 <div class="wrap"> |
|
47 <?php screen_icon(); ?> |
|
48 <h2 id="add-new-user"><?php _e('Add New User') ?></h2> |
|
49 |
|
50 <?php if ( isset($errors) && is_wp_error( $errors ) ) : ?> |
|
51 <div class="error"> |
|
52 <ul> |
|
53 <?php |
|
54 foreach ( $errors->get_error_messages() as $err ) |
|
55 echo "<li>$err</li>\n"; |
|
56 ?> |
|
57 </ul> |
|
58 </div> |
|
59 <?php endif; |
|
60 |
|
61 if ( ! empty($messages) ) { |
|
62 foreach ( $messages as $msg ) |
|
63 echo $msg; |
|
64 } ?> |
|
65 |
|
66 <?php if ( isset($add_user_errors) && is_wp_error( $add_user_errors ) ) : ?> |
|
67 <div class="error"> |
|
68 <?php |
|
69 foreach ( $add_user_errors->get_error_messages() as $message ) |
|
70 echo "<p>$message</p>"; |
|
71 ?> |
|
72 </div> |
|
73 <?php endif; ?> |
|
74 <div id="ajax-response"></div> |
|
75 |
|
76 <?php |
|
77 if ( get_option('users_can_register') ) |
|
78 echo '<p>' . sprintf(__('Users can <a href="%1$s">register themselves</a> or you can manually create users here.'), site_url('wp-register.php')) . '</p>'; |
|
79 else |
|
80 echo '<p>' . sprintf(__('Users cannot currently <a href="%1$s">register themselves</a>, but you can manually create users here.'), admin_url('options-general.php#users_can_register')) . '</p>'; |
|
81 ?> |
|
82 <form action="#add-new-user" method="post" name="adduser" id="adduser" class="add:users: validate"> |
|
83 <?php wp_nonce_field('add-user') ?> |
|
84 <?php |
|
85 //Load up the passed data, else set to a default. |
|
86 foreach ( array('user_login' => 'login', 'first_name' => 'firstname', 'last_name' => 'lastname', |
|
87 'email' => 'email', 'url' => 'uri', 'role' => 'role') as $post_field => $var ) { |
|
88 $var = "new_user_$var"; |
|
89 if ( ! isset($$var) ) |
|
90 $$var = isset($_POST[$post_field]) ? stripslashes($_POST[$post_field]) : ''; |
|
91 } |
|
92 $new_user_send_password = !$_POST || isset($_POST['send_password']); |
|
93 ?> |
|
94 <table class="form-table"> |
|
95 <tr class="form-field form-required"> |
|
96 <th scope="row"><label for="user_login"><?php _e('Username'); ?> <span class="description"><?php _e('(required)'); ?></span></label> |
|
97 <input name="action" type="hidden" id="action" value="adduser" /></th> |
|
98 <td><input name="user_login" type="text" id="user_login" value="<?php echo esc_attr($new_user_login); ?>" aria-required="true" /></td> |
|
99 </tr> |
|
100 <tr class="form-field"> |
|
101 <th scope="row"><label for="first_name"><?php _e('First Name') ?> </label></th> |
|
102 <td><input name="first_name" type="text" id="first_name" value="<?php echo esc_attr($new_user_firstname); ?>" /></td> |
|
103 </tr> |
|
104 <tr class="form-field"> |
|
105 <th scope="row"><label for="last_name"><?php _e('Last Name') ?> </label></th> |
|
106 <td><input name="last_name" type="text" id="last_name" value="<?php echo esc_attr($new_user_lastname); ?>" /></td> |
|
107 </tr> |
|
108 <tr class="form-field form-required"> |
|
109 <th scope="row"><label for="email"><?php _e('E-mail'); ?> <span class="description"><?php _e('(required)'); ?></span></label></th> |
|
110 <td><input name="email" type="text" id="email" value="<?php echo esc_attr($new_user_email); ?>" /></td> |
|
111 </tr> |
|
112 <tr class="form-field"> |
|
113 <th scope="row"><label for="url"><?php _e('Website') ?></label></th> |
|
114 <td><input name="url" type="text" id="url" class="code" value="<?php echo esc_attr($new_user_uri); ?>" /></td> |
|
115 </tr> |
|
116 |
|
117 <?php if ( apply_filters('show_password_fields', true) ) : ?> |
|
118 <tr class="form-field form-required"> |
|
119 <th scope="row"><label for="pass1"><?php _e('Password'); ?> <span class="description"><?php _e('(twice, required)'); ?></span></label></th> |
|
120 <td><input name="pass1" type="password" id="pass1" autocomplete="off" /> |
|
121 <br /> |
|
122 <input name="pass2" type="password" id="pass2" autocomplete="off" /> |
|
123 <br /> |
|
124 <div id="pass-strength-result"><?php _e('Strength indicator'); ?></div> |
|
125 <p class="description indicator-hint"><?php _e('Hint: The password should be at least seven characters long. To make it stronger, use upper and lower case letters, numbers and symbols like ! " ? $ % ^ & ).'); ?></p> |
|
126 </td> |
|
127 </tr> |
|
128 <tr> |
|
129 <th scope="row"><label for="send_password"><?php _e('Send Password?') ?></label></th> |
|
130 <td><label for="send_password"><input type="checkbox" name="send_password" id="send_password" <?php checked($new_user_send_password, true); ?> /> <?php _e('Send this password to the new user by email.'); ?></label></td> |
|
131 </tr> |
|
132 <?php endif; ?> |
|
133 |
|
134 <tr class="form-field"> |
|
135 <th scope="row"><label for="role"><?php _e('Role'); ?></label></th> |
|
136 <td><select name="role" id="role"> |
|
137 <?php |
|
138 if ( !$new_user_role ) |
|
139 $new_user_role = !empty($current_role) ? $current_role : get_option('default_role'); |
|
140 wp_dropdown_roles($new_user_role); |
|
141 ?> |
|
142 </select> |
|
143 </td> |
|
144 </tr> |
|
145 </table> |
|
146 <p class="submit"> |
|
147 <input name="adduser" type="submit" id="addusersub" class="button-primary" value="<?php esc_attr_e('Add User') ?>" /> |
|
148 </p> |
|
149 </form> |
|
150 |
|
151 </div> |
|
152 <?php |
|
153 include('admin-footer.php'); |
|
154 ?> |