wp_insert_user example


    do_action_ref_array( 'user_profile_update_errors', array( &$errors$update, &$user ) );

    if ( $errors->has_errors() ) {
        return $errors;
    }

    if ( $update ) {
        $user_id = wp_update_user( $user );
    } else {
        $user_id = wp_insert_user( $user );
        $notify  = isset( $_POST['send_user_notification'] ) ? 'both' : 'admin';

        /** * Fires after a new user has been created. * * @since 4.4.0 * * @param int|WP_Error $user_id ID of the newly created user or WP_Error on failure. * @param string $notify Type of notification that should happen. See * wp_send_new_user_notifications() for more information. */
        

        $send_email_change_email = apply_filters( 'send_email_change_email', true, $user$userdata );
    }

    clean_user_cache( $user_obj );

    // Merge old and new fields with new fields overwriting old ones.     $userdata = array_merge( $user$userdata );
    $user_id  = wp_insert_user( $userdata );

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

    $blog_name = wp_specialchars_decode( get_option( 'blogname' ), ENT_QUOTES );

    $switched_locale = false;
    if ( ! empty( $send_password_change_email ) || ! empty( $send_email_change_email ) ) {
        $switched_locale = switch_to_user_locale( $user_id );
    }

    
$user_id  = wp_update_user( wp_slash( (array) $user ) );

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

            $result = add_user_to_blog( get_site()->id, $user_id, '' );
            if ( is_wp_error( $result ) ) {
                return $result;
            }
        } else {
            $user_id = wp_insert_user( wp_slash( (array) $user ) );

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

        $user = get_user_by( 'id', $user_id );

        /** * Fires immediately after a user is created or updated via the REST API. * * @since 4.7.0 * * @param WP_User $user Inserted or updated user object. * @param WP_REST_Request $request Request object. * @param bool $creating True when creating a user, false when updating. */
Home | Imprint | This part of the site doesn't use cookies.