8 */ |
8 */ |
9 |
9 |
10 /** Load WordPress Administration Bootstrap */ |
10 /** Load WordPress Administration Bootstrap */ |
11 require_once( dirname( __FILE__ ) . '/admin.php' ); |
11 require_once( dirname( __FILE__ ) . '/admin.php' ); |
12 |
12 |
13 if ( ! is_multisite() ) |
|
14 wp_die( __( 'Multisite support is not enabled.' ) ); |
|
15 |
|
16 if ( ! current_user_can('create_users') ) |
13 if ( ! current_user_can('create_users') ) |
17 wp_die(__('You do not have sufficient permissions to add users to this network.')); |
14 wp_die(__('Sorry, you are not allowed to add users to this network.')); |
18 |
15 |
19 get_current_screen()->add_help_tab( array( |
16 get_current_screen()->add_help_tab( array( |
20 'id' => 'overview', |
17 'id' => 'overview', |
21 'title' => __('Overview'), |
18 'title' => __('Overview'), |
22 'content' => |
19 'content' => |
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>' |
21 '<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 ) ); |
22 ) ); |
26 |
23 |
27 get_current_screen()->set_help_sidebar( |
24 get_current_screen()->set_help_sidebar( |
28 '<p><strong>' . __('For more information:') . '</strong></p>' . |
25 '<p><strong>' . __('For more information:') . '</strong></p>' . |
29 '<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Users_Screen" target="_blank">Documentation on Network Users</a>') . '</p>' . |
26 '<p>' . __('<a href="https://codex.wordpress.org/Network_Admin_Users_Screen">Documentation on Network Users</a>') . '</p>' . |
30 '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/" target="_blank">Support Forums</a>') . '</p>' |
27 '<p>' . __('<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>') . '</p>' |
31 ); |
28 ); |
32 |
29 |
33 if ( isset($_REQUEST['action']) && 'add-user' == $_REQUEST['action'] ) { |
30 if ( isset($_REQUEST['action']) && 'add-user' == $_REQUEST['action'] ) { |
34 check_admin_referer( 'add-user', '_wpnonce_add-user' ); |
31 check_admin_referer( 'add-user', '_wpnonce_add-user' ); |
35 |
32 |
36 if ( ! current_user_can( 'manage_network_users' ) ) |
33 if ( ! current_user_can( 'manage_network_users' ) ) |
37 wp_die( __( 'You do not have permission to access this page.' ), 403 ); |
34 wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
38 |
35 |
39 if ( ! is_array( $_POST['user'] ) ) |
36 if ( ! is_array( $_POST['user'] ) ) |
40 wp_die( __( 'Cannot create an empty user.' ) ); |
37 wp_die( __( 'Cannot create an empty user.' ) ); |
41 |
38 |
42 $user = wp_unslash( $_POST['user'] ); |
39 $user = wp_unslash( $_POST['user'] ); |
49 $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, sanitize_email( $user['email'] ) ); |
46 $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, sanitize_email( $user['email'] ) ); |
50 |
47 |
51 if ( ! $user_id ) { |
48 if ( ! $user_id ) { |
52 $add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) ); |
49 $add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) ); |
53 } else { |
50 } else { |
54 wp_new_user_notification( $user_id, $password ); |
51 /** |
55 wp_redirect( add_query_arg( array('update' => 'added'), 'user-new.php' ) ); |
52 * Fires after a new user has been created via the network user-new.php page. |
|
53 * |
|
54 * @since 4.4.0 |
|
55 * |
|
56 * @param int $user_id ID of the newly created user. |
|
57 */ |
|
58 do_action( 'network_user_new_created_user', $user_id ); |
|
59 wp_redirect( add_query_arg( array('update' => 'added', 'user_id' => $user_id ), 'user-new.php' ) ); |
56 exit; |
60 exit; |
57 } |
61 } |
58 } |
62 } |
59 } |
63 } |
60 |
64 |
61 if ( isset($_GET['update']) ) { |
65 if ( isset($_GET['update']) ) { |
62 $messages = array(); |
66 $messages = array(); |
63 if ( 'added' == $_GET['update'] ) |
67 if ( 'added' == $_GET['update'] ) { |
64 $messages[] = __('User added.'); |
68 $edit_link = ''; |
|
69 if ( isset( $_GET['user_id'] ) ) { |
|
70 $user_id_new = absint( $_GET['user_id'] ); |
|
71 if ( $user_id_new ) { |
|
72 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_id_new ) ) ); |
|
73 } |
|
74 } |
|
75 |
|
76 if ( empty( $edit_link ) ) { |
|
77 $messages[] = __( 'User added.' ); |
|
78 } else { |
|
79 /* translators: %s: edit page url */ |
|
80 $messages[] = sprintf( __( 'User added. <a href="%s">Edit user</a>' ), $edit_link ); |
|
81 } |
|
82 } |
65 } |
83 } |
66 |
84 |
67 $title = __('Add New User'); |
85 $title = __('Add New User'); |
68 $parent_file = 'users.php'; |
86 $parent_file = 'users.php'; |
69 |
87 |
70 require( ABSPATH . 'wp-admin/admin-header.php' ); ?> |
88 require( ABSPATH . 'wp-admin/admin-header.php' ); ?> |
71 |
89 |
72 <div class="wrap"> |
90 <div class="wrap"> |
73 <h2 id="add-new-user"><?php _e('Add New User') ?></h2> |
91 <h1 id="add-new-user"><?php _e( 'Add New User' ); ?></h1> |
74 <?php |
92 <?php |
75 if ( ! empty( $messages ) ) { |
93 if ( ! empty( $messages ) ) { |
76 foreach ( $messages as $msg ) |
94 foreach ( $messages as $msg ) |
77 echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>'; |
95 echo '<div id="message" class="updated notice is-dismissible"><p>' . $msg . '</p></div>'; |
78 } |
96 } |
83 foreach ( $add_user_errors->get_error_messages() as $message ) |
101 foreach ( $add_user_errors->get_error_messages() as $message ) |
84 echo "<p>$message</p>"; |
102 echo "<p>$message</p>"; |
85 ?> |
103 ?> |
86 </div> |
104 </div> |
87 <?php } ?> |
105 <?php } ?> |
88 <form action="<?php echo network_admin_url('user-new.php?action=add-user'); ?>" id="adduser" method="post"> |
106 <form action="<?php echo network_admin_url('user-new.php?action=add-user'); ?>" id="adduser" method="post" novalidate="novalidate"> |
89 <table class="form-table"> |
107 <table class="form-table"> |
90 <tr class="form-field form-required"> |
108 <tr class="form-field form-required"> |
91 <th scope="row"><label for="username"><?php _e( 'Username' ) ?></label></th> |
109 <th scope="row"><label for="username"><?php _e( 'Username' ) ?></label></th> |
92 <td><input type="text" class="regular-text" name="user[username]" id="username" /></td> |
110 <td><input type="text" class="regular-text" name="user[username]" id="username" autocapitalize="none" autocorrect="off" maxlength="60" /></td> |
93 </tr> |
111 </tr> |
94 <tr class="form-field form-required"> |
112 <tr class="form-field form-required"> |
95 <th scope="row"><label for="email"><?php _e( 'Email' ) ?></label></th> |
113 <th scope="row"><label for="email"><?php _e( 'Email' ) ?></label></th> |
96 <td><input type="text" class="regular-text" name="user[email]" id="email"/></td> |
114 <td><input type="email" class="regular-text" name="user[email]" id="email"/></td> |
97 </tr> |
115 </tr> |
98 <tr class="form-field"> |
116 <tr class="form-field"> |
99 <td colspan="2"><?php _e( 'Username and password will be mailed to the above email address.' ) ?></td> |
117 <td colspan="2"><?php _e( 'A password reset link will be sent to the user via email.' ) ?></td> |
100 </tr> |
118 </tr> |
101 </table> |
119 </table> |
102 <?php wp_nonce_field( 'add-user', '_wpnonce_add-user' ); ?> |
120 <?php |
103 <?php submit_button( __('Add User'), 'primary', 'add-user' ); ?> |
121 /** |
|
122 * Fires at the end of the new user form in network admin. |
|
123 * |
|
124 * @since 4.5.0 |
|
125 */ |
|
126 do_action( 'network_user_new_form' ); |
|
127 |
|
128 wp_nonce_field( 'add-user', '_wpnonce_add-user' ); |
|
129 submit_button( __('Add User'), 'primary', 'add-user' ); |
|
130 ?> |
104 </form> |
131 </form> |
105 </div> |
132 </div> |
106 <?php |
133 <?php |
107 require( ABSPATH . 'wp-admin/admin-footer.php' ); |
134 require( ABSPATH . 'wp-admin/admin-footer.php' ); |