2008-11-11 14:47:22 -05:00
< ? php
/**
* New User Administration Panel .
*
* @ package WordPress
* @ subpackage Administration
*/
/** WordPress Administration Bootstrap */
require_once ( 'admin.php' );
if ( ! current_user_can ( 'create_users' ) )
wp_die ( __ ( 'Cheatin’ uh?' ));
/** WordPress Registration API */
require_once ( ABSPATH . WPINC . '/registration.php' );
if ( isset ( $_REQUEST [ 'action' ]) && 'adduser' == $_REQUEST [ 'action' ] ) {
check_admin_referer ( 'add-user' );
if ( ! current_user_can ( 'create_users' ) )
wp_die ( __ ( 'You can’t create users.' ));
$user_id = add_user ();
2008-11-14 18:01:16 -05:00
if ( is_wp_error ( $user_id ) ) {
2008-11-11 14:47:22 -05:00
$add_user_errors = $user_id ;
2008-11-14 18:01:16 -05:00
} else {
2008-11-11 14:47:22 -05:00
$new_user_login = apply_filters ( 'pre_user_login' , sanitize_user ( stripslashes ( $_REQUEST [ 'user_login' ]), true ));
2008-11-14 18:01:16 -05:00
$redirect = 'users.php?usersearch=' . urlencode ( $new_user_login ) . '&update=add' ;
2008-11-11 14:47:22 -05:00
wp_redirect ( $redirect . '#user-' . $user_id );
die ();
}
}
$title = __ ( 'Add New User' );
$parent_file = 'users.php' ;
2009-01-12 08:43:17 -05:00
wp_enqueue_script ( 'wp-ajax-response' );
2009-05-16 02:29:10 -04:00
wp_enqueue_script ( 'user-profile' );
wp_enqueue_script ( 'password-strength-meter' );
2008-11-11 14:47:22 -05:00
require_once ( 'admin-header.php' );
?>
< div class = " wrap " >
2008-11-26 08:51:25 -05:00
< ? php screen_icon (); ?>
2008-11-11 14:47:22 -05:00
< h2 id = " add-new-user " >< ? php _e ( 'Add New User' ) ?> </h2>
< ? php if ( isset ( $errors ) && is_wp_error ( $errors ) ) : ?>
< div class = " error " >
< ul >
< ? php
foreach ( $errors -> get_error_messages () as $err )
echo " <li> $err </li> \n " ;
?>
</ ul >
</ div >
< ? php endif ;
if ( ! empty ( $messages ) ) {
foreach ( $messages as $msg )
echo $msg ;
} ?>
< ? php if ( isset ( $add_user_errors ) && is_wp_error ( $add_user_errors ) ) : ?>
< div class = " error " >
< ? php
foreach ( $add_user_errors -> get_error_messages () as $message )
echo " <p> $message </p> " ;
?>
</ div >
< ? php endif ; ?>
< div id = " ajax-response " ></ div >
< ? php
if ( get_option ( 'users_can_register' ) )
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>' ;
else
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>' ;
?>
< form action = " #add-new-user " method = " post " name = " adduser " id = " adduser " class = " add:users: validate " >
< ? php wp_nonce_field ( 'add-user' ) ?>
2008-11-14 18:01:16 -05:00
< ? php
//Load up the passed data, else set to a default.
foreach ( array ( 'user_login' => 'login' , 'first_name' => 'firstname' , 'last_name' => 'lastname' ,
'email' => 'email' , 'url' => 'uri' , 'role' => 'role' ) as $post_field => $var ) {
$var = " new_user_ $var " ;
if ( ! isset ( $$var ) )
$$var = isset ( $_POST [ $post_field ]) ? stripslashes ( $_POST [ $post_field ]) : '' ;
}
2009-05-13 18:35:17 -04:00
$new_user_send_password = ! $_POST || isset ( $_POST [ 'send_password' ]);
2008-11-14 18:01:16 -05:00
?>
2008-11-11 14:47:22 -05:00
< table class = " form-table " >
< tr class = " form-field form-required " >
2009-05-14 13:01:04 -04:00
< th scope = " row " >< label for = " user_login " >< ? php _e ( 'Username' ); ?> <span class="description"><?php _e('(required)'); ?></span></label>
< input name = " action " type = " hidden " id = " action " value = " adduser " /></ th >
< td >< input name = " user_login " type = " text " id = " user_login " value = " <?php echo esc_attr( $new_user_login ); ?> " aria - required = " true " /></ td >
2008-11-11 14:47:22 -05:00
</ tr >
< tr class = " form-field " >
< th scope = " row " >< label for = " first_name " >< ? php _e ( 'First Name' ) ?> </label></th>
2009-05-05 15:43:53 -04:00
< td >< input name = " first_name " type = " text " id = " first_name " value = " <?php echo esc_attr( $new_user_firstname ); ?> " /></ td >
2008-11-11 14:47:22 -05:00
</ tr >
< tr class = " form-field " >
< th scope = " row " >< label for = " last_name " >< ? php _e ( 'Last Name' ) ?> </label></th>
2009-05-05 15:43:53 -04:00
< td >< input name = " last_name " type = " text " id = " last_name " value = " <?php echo esc_attr( $new_user_lastname ); ?> " /></ td >
2008-11-11 14:47:22 -05:00
</ tr >
< tr class = " form-field form-required " >
2009-05-14 13:01:04 -04:00
< th scope = " row " >< label for = " email " >< ? php _e ( 'E-mail' ); ?> <span class="description"><?php _e('(required)'); ?></span></label></th>
2009-05-05 15:43:53 -04:00
< td >< input name = " email " type = " text " id = " email " value = " <?php echo esc_attr( $new_user_email ); ?> " /></ td >
2008-11-11 14:47:22 -05:00
</ tr >
< tr class = " form-field " >
< th scope = " row " >< label for = " url " >< ? php _e ( 'Website' ) ?> </label></th>
2009-05-05 15:43:53 -04:00
< td >< input name = " url " type = " text " id = " url " class = " code " value = " <?php echo esc_attr( $new_user_uri ); ?> " /></ td >
2008-11-11 14:47:22 -05:00
</ tr >
< ? php if ( apply_filters ( 'show_password_fields' , true ) ) : ?>
< tr class = " form-field form-required " >
2009-05-14 13:01:04 -04:00
< th scope = " row " >< label for = " pass1 " >< ? php _e ( 'Password' ); ?> <span class="description"><?php _e('(twice, required)'); ?></span></label></th>
2008-11-11 14:47:22 -05:00
< td >< input name = " pass1 " type = " password " id = " pass1 " autocomplete = " off " />
< br />
2009-05-16 17:51:32 -04:00
< input name = " pass2 " type = " password " id = " pass2 " autocomplete = " off " />
< br />
2009-05-16 02:29:10 -04:00
< div id = " pass-strength-result " >< ? php _e ( 'Strength indicator' ); ?> </div>
< 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>
</ td >
2008-11-11 14:47:22 -05:00
</ tr >
2009-05-13 18:35:17 -04:00
< tr >
< th scope = " row " >< label for = " send_password " >< ? php _e ( 'Send Password?' ) ?> </label></th>
< 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>
</ tr >
2008-11-11 14:47:22 -05:00
< ? php endif ; ?>
< tr class = " form-field " >
< th scope = " row " >< label for = " role " >< ? php _e ( 'Role' ); ?> </label></th>
< td >< select name = " role " id = " role " >
< ? php
if ( ! $new_user_role )
2008-11-14 18:01:16 -05:00
$new_user_role = ! empty ( $current_role ) ? $current_role : get_option ( 'default_role' );
2008-11-11 14:47:22 -05:00
wp_dropdown_roles ( $new_user_role );
?>
</ select >
</ td >
</ tr >
</ table >
< p class = " submit " >
2009-05-05 15:43:53 -04:00
< input name = " adduser " type = " submit " id = " addusersub " class = " button-primary " value = " <?php esc_attr_e('Add User') ?> " />
2008-11-11 14:47:22 -05:00
</ p >
</ form >
</ div >
< ? php
include ( 'admin-footer.php' );
2009-05-14 13:01:04 -04:00
?>