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