]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-admin/network/user-new.php
Wordpress 3.7
[autoinstalls/wordpress.git] / wp-admin / network / user-new.php
1 <?php
2 /**
3  * Add New User network administration panel.
4  *
5  * @package WordPress
6  * @subpackage Multisite
7  * @since 3.1.0
8  */
9
10 /** Load WordPress Administration Bootstrap */
11 require_once( dirname( __FILE__ ) . '/admin.php' );
12
13 if ( ! is_multisite() )
14         wp_die( __( 'Multisite support is not enabled.' ) );
15
16 if ( ! current_user_can('create_users') )
17         wp_die(__('You do not have sufficient permissions to add users to this network.'));
18
19 get_current_screen()->add_help_tab( array(
20         'id'      => 'overview',
21         'title'   => __('Overview'),
22         'content' =>
23                 '<p>' . __('Add User will set up a new user account on the network and send that person an email with username and password.') . '</p>' .
24                 '<p>' . __('Users who are signed up to the network without a site are added as subscribers to the main or primary dashboard site, giving them profile pages to manage their accounts. These users will only see Dashboard and My Sites in the main navigation until a site is created for them.') . '</p>'
25 ) );
26
27 get_current_screen()->set_help_sidebar(
28         '<p><strong>' . __('For more information:') . '</strong></p>' .
29         '<p>' . __('<a href="http://codex.wordpress.org/Network_Admin_Users_Screen" target="_blank">Documentation on Network Users</a>') . '</p>' .
30         '<p>' . __('<a href="http://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>'
31 );
32
33 if ( isset($_REQUEST['action']) && 'add-user' == $_REQUEST['action'] ) {
34         check_admin_referer( 'add-user', '_wpnonce_add-user' );
35         if ( ! current_user_can( 'manage_network_users' ) )
36                 wp_die( __( 'You do not have permission to access this page.' ) );
37
38         if ( ! is_array( $_POST['user'] ) )
39                 wp_die( __( 'Cannot create an empty user.' ) );
40
41         $user = $_POST['user'];
42
43         $user_details = wpmu_validate_user_signup( $user['username'], $user['email'] );
44         if ( is_wp_error( $user_details[ 'errors' ] ) && ! empty( $user_details[ 'errors' ]->errors ) ) {
45                 $add_user_errors = $user_details[ 'errors' ];
46         } else {
47                 $password = wp_generate_password( 12, false);
48                 $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, esc_html( $user['email'] ) );
49
50                 if ( ! $user_id ) {
51                         $add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) );
52                 } else {
53                         wp_new_user_notification( $user_id, $password );
54                         wp_redirect( add_query_arg( array('update' => 'added'), 'user-new.php' ) );
55                         exit;
56                 }
57         }
58 }
59
60 if ( isset($_GET['update']) ) {
61         $messages = array();
62         if ( 'added' == $_GET['update'] )
63                 $messages[] = __('User added.');
64 }
65
66 $title = __('Add New User');
67 $parent_file = 'users.php';
68
69 require( ABSPATH . 'wp-admin/admin-header.php' ); ?>
70
71 <div class="wrap">
72 <?php screen_icon(); ?>
73 <h2 id="add-new-user"><?php _e('Add New User') ?></h2>
74 <?php
75 if ( ! empty( $messages ) ) {
76         foreach ( $messages as $msg )
77                 echo '<div id="message" class="updated"><p>' . $msg . '</p></div>';
78 }
79
80 if ( isset( $add_user_errors ) && is_wp_error( $add_user_errors ) ) { ?>
81         <div class="error">
82                 <?php
83                         foreach ( $add_user_errors->get_error_messages() as $message )
84                                 echo "<p>$message</p>";
85                 ?>
86         </div>
87 <?php } ?>
88         <form action="<?php echo network_admin_url('user-new.php?action=add-user'); ?>" id="adduser" method="post">
89         <table class="form-table">
90                 <tr class="form-field form-required">
91                         <th scope="row"><?php _e( 'Username' ) ?></th>
92                         <td><input type="text" class="regular-text" name="user[username]" /></td>
93                 </tr>
94                 <tr class="form-field form-required">
95                         <th scope="row"><?php _e( 'Email' ) ?></th>
96                         <td><input type="text" class="regular-text" name="user[email]" /></td>
97                 </tr>
98                 <tr class="form-field">
99                         <td colspan="2"><?php _e( 'Username and password will be mailed to the above email address.' ) ?></td>
100                 </tr>
101         </table>
102         <?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ); ?>
103         <?php submit_button( __('Add User'), 'primary', 'add-user' ); ?>
104         </form>
105 </div>
106 <?php
107 require( ABSPATH . 'wp-admin/admin-footer.php' );