6 * @subpackage Multisite |
6 * @subpackage Multisite |
7 * @since 3.1.0 |
7 * @since 3.1.0 |
8 */ |
8 */ |
9 |
9 |
10 /** Load WordPress Administration Bootstrap */ |
10 /** Load WordPress Administration Bootstrap */ |
11 require_once( dirname( __FILE__ ) . '/admin.php' ); |
11 require_once __DIR__ . '/admin.php'; |
12 |
12 |
13 if ( ! current_user_can( 'create_users' ) ) { |
13 if ( ! current_user_can( 'create_users' ) ) { |
14 wp_die( __( 'Sorry, you are not allowed to add users to this network.' ) ); |
14 wp_die( __( 'Sorry, you are not allowed to add users to this network.' ) ); |
15 } |
15 } |
16 |
16 |
28 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
28 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
29 '<p>' . __( '<a href="https://codex.wordpress.org/Network_Admin_Users_Screen">Documentation on Network Users</a>' ) . '</p>' . |
29 '<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/">Support Forums</a>' ) . '</p>' |
30 '<p>' . __( '<a href="https://wordpress.org/support/forum/multisite/">Support Forums</a>' ) . '</p>' |
31 ); |
31 ); |
32 |
32 |
33 if ( isset( $_REQUEST['action'] ) && 'add-user' == $_REQUEST['action'] ) { |
33 if ( isset( $_REQUEST['action'] ) && 'add-user' === $_REQUEST['action'] ) { |
34 check_admin_referer( 'add-user', '_wpnonce_add-user' ); |
34 check_admin_referer( 'add-user', '_wpnonce_add-user' ); |
35 |
35 |
36 if ( ! current_user_can( 'manage_network_users' ) ) { |
36 if ( ! current_user_can( 'manage_network_users' ) ) { |
37 wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
37 wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 ); |
38 } |
38 } |
42 } |
42 } |
43 |
43 |
44 $user = wp_unslash( $_POST['user'] ); |
44 $user = wp_unslash( $_POST['user'] ); |
45 |
45 |
46 $user_details = wpmu_validate_user_signup( $user['username'], $user['email'] ); |
46 $user_details = wpmu_validate_user_signup( $user['username'], $user['email'] ); |
|
47 |
47 if ( is_wp_error( $user_details['errors'] ) && $user_details['errors']->has_errors() ) { |
48 if ( is_wp_error( $user_details['errors'] ) && $user_details['errors']->has_errors() ) { |
48 $add_user_errors = $user_details['errors']; |
49 $add_user_errors = $user_details['errors']; |
49 } else { |
50 } else { |
50 $password = wp_generate_password( 12, false ); |
51 $password = wp_generate_password( 12, false ); |
51 $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, sanitize_email( $user['email'] ) ); |
52 $user_id = wpmu_create_user( esc_html( strtolower( $user['username'] ) ), $password, sanitize_email( $user['email'] ) ); |
75 } |
77 } |
76 } |
78 } |
77 |
79 |
78 if ( isset( $_GET['update'] ) ) { |
80 if ( isset( $_GET['update'] ) ) { |
79 $messages = array(); |
81 $messages = array(); |
80 if ( 'added' == $_GET['update'] ) { |
82 if ( 'added' === $_GET['update'] ) { |
81 $edit_link = ''; |
83 $edit_link = ''; |
82 if ( isset( $_GET['user_id'] ) ) { |
84 if ( isset( $_GET['user_id'] ) ) { |
83 $user_id_new = absint( $_GET['user_id'] ); |
85 $user_id_new = absint( $_GET['user_id'] ); |
84 if ( $user_id_new ) { |
86 if ( $user_id_new ) { |
85 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_id_new ) ) ); |
87 $edit_link = esc_url( add_query_arg( 'wp_http_referer', urlencode( wp_unslash( $_SERVER['REQUEST_URI'] ) ), get_edit_user_link( $user_id_new ) ) ); |
86 } |
88 } |
87 } |
89 } |
88 |
90 |
89 if ( empty( $edit_link ) ) { |
91 $message = __( 'User added.' ); |
90 $messages[] = __( 'User added.' ); |
92 |
91 } else { |
93 if ( $edit_link ) { |
92 /* translators: %s: edit page url */ |
94 $message .= sprintf( ' <a href="%s">%s</a>', $edit_link, __( 'Edit user' ) ); |
93 $messages[] = sprintf( __( 'User added. <a href="%s">Edit user</a>' ), $edit_link ); |
|
94 } |
95 } |
|
96 |
|
97 $messages[] = $message; |
95 } |
98 } |
96 } |
99 } |
97 |
100 |
98 $title = __( 'Add New User' ); |
101 $title = __( 'Add New User' ); |
99 $parent_file = 'users.php'; |
102 $parent_file = 'users.php'; |
100 |
103 |
101 require( ABSPATH . 'wp-admin/admin-header.php' ); ?> |
104 require_once ABSPATH . 'wp-admin/admin-header.php'; ?> |
102 |
105 |
103 <div class="wrap"> |
106 <div class="wrap"> |
104 <h1 id="add-new-user"><?php _e( 'Add New User' ); ?></h1> |
107 <h1 id="add-new-user"><?php _e( 'Add New User' ); ?></h1> |
105 <?php |
108 <?php |
106 if ( ! empty( $messages ) ) { |
109 if ( ! empty( $messages ) ) { |