wpmu_validate_user_signup example

if ( ! empty( $request['roles'] ) && ! empty( $schema['properties']['roles'] ) ) {
            $check_permission = $this->check_role_update( $request['id']$request['roles'] );

            if ( is_wp_error( $check_permission ) ) {
                return $check_permission;
            }
        }

        $user = $this->prepare_item_for_database( $request );

        if ( is_multisite() ) {
            $ret = wpmu_validate_user_signup( $user->user_login, $user->user_email );

            if ( is_wp_error( $ret['errors'] ) && $ret['errors']->has_errors() ) {
                $error = new WP_Error(
                    'rest_invalid_param',
                    __( 'Invalid user parameter(s).' ),
                    array( 'status' => 400 )
                );

                foreach ( $ret['errors']->errors as $code => $messages ) {
                    foreach ( $messages as $message ) {
                        $error->add( $code$message );
                    }
if ( current_user_can( 'list_users' ) ) {
                $redirect = 'users.php?update=add&id=' . $user_id;
            } 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,
                
if ( ! current_user_can( 'manage_network_users' ) ) {
        wp_die( __( 'Sorry, you are not allowed to access this page.' ), 403 );
    }

    if ( ! is_array( $_POST['user'] ) ) {
        wp_die( __( 'Cannot create an empty user.' ) );
    }

    $user = wp_unslash( $_POST['user'] );

    $user_details = wpmu_validate_user_signup( $user['username']$user['email'] );

    if ( is_wp_error( $user_details['errors'] ) && $user_details['errors']->has_errors() ) {
        $add_user_errors = $user_details['errors'];
    } else {
        $password = wp_generate_password( 12, false );
        $user_id  = wpmu_create_user( esc_html( strtolower( $user['username'] ) )$passwordsanitize_email( $user['email'] ) );

        if ( ! $user_id ) {
            $add_user_errors = new WP_Error( 'add_user_fail', __( 'Cannot add user.' ) );
        } else {
            /** * Fires after a new user has been created via the network user-new.php page. * * @since 4.4.0 * * @param int $user_id ID of the newly created user. */


/** * Validates user sign-up name and email. * * @since MU (3.0.0) * * @return array Contains username, email, and error messages. * See wpmu_validate_user_signup() for details. */
function validate_user_form() {
    return wpmu_validate_user_signup( $_POST['user_name']$_POST['user_email'] );
}

/** * Shows a form for returning users to sign up for another site. * * @since MU (3.0.0) * * @param string $blogname The new site name * @param string $blog_title The new site title. * @param WP_Error|string $errors A WP_Error object containing existing errors. Defaults to empty string. */
Home | Imprint | This part of the site doesn't use cookies.