Skip to content

Commit

Permalink
Merge branch 'trunk' into 56791-coding-standards
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyBiryukov authored Sep 9, 2024
2 parents 0485b36 + a30b9b4 commit 340c975
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/wp-admin/user-new.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

$user_details = null;
$user_email = wp_unslash( $_REQUEST['email'] );

if ( str_contains( $user_email, '@' ) ) {
$user_details = get_user_by( 'email', $user_email );
} else {
Expand Down Expand Up @@ -63,6 +64,7 @@
$redirect = 'user-new.php';
$username = $user_details->user_login;
$user_id = $user_details->ID;

if ( array_key_exists( $blog_id, get_blogs_of_user( $user_id ) ) ) {
$redirect = add_query_arg( array( 'update' => 'addexisting' ), 'user-new.php' );
} else {
Expand Down Expand Up @@ -178,6 +180,7 @@
$redirect = add_query_arg( array( 'update' => 'add' ), 'user-new.php' );
}
}

wp_redirect( $redirect );
die();
} elseif ( isset( $_REQUEST['action'] ) && 'createuser' === $_REQUEST['action'] ) {
Expand All @@ -202,22 +205,26 @@
} else {
$redirect = add_query_arg( 'update', 'add', 'user-new.php' );
}

wp_redirect( $redirect );
die();
}
} else {
// Adding a new user to this site.
$new_user_email = wp_unslash( $_REQUEST['email'] );
$user_details = wpmu_validate_user_signup( $_REQUEST['user_login'], $new_user_email );

if ( is_wp_error( $user_details['errors'] ) && $user_details['errors']->has_errors() ) {
$add_user_errors = $user_details['errors'];
} else {
/** This filter is documented in wp-includes/user.php */
$new_user_login = apply_filters( 'pre_user_login', sanitize_user( wp_unslash( $_REQUEST['user_login'] ), true ) );

if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) {
add_filter( 'wpmu_signup_user_notification', '__return_false' ); // Disable confirmation email.
add_filter( 'wpmu_welcome_user_notification', '__return_false' ); // Disable welcome email.
}

wpmu_signup_user(
$new_user_login,
$new_user_email,
Expand All @@ -226,6 +233,7 @@
'new_role' => $_REQUEST['role'],
)
);

if ( isset( $_POST['noconfirmation'] ) && current_user_can( 'manage_network_users' ) ) {
$key = $wpdb->get_var( $wpdb->prepare( "SELECT activation_key FROM {$wpdb->signups} WHERE user_login = %s AND user_email = %s", $new_user_login, $new_user_email ) );
$new_user = wpmu_activate_signup( $key );
Expand All @@ -245,6 +253,7 @@
} else {
$redirect = add_query_arg( array( 'update' => 'newuserconfirmation' ), 'user-new.php' );
}

wp_redirect( $redirect );
die();
}
Expand Down

0 comments on commit 340c975

Please sign in to comment.