wp_update_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. */
$blogs        = get_blogs_of_user( $user_id, true );

                                foreach ( (array) $blogs as $details ) {
                                    if ( ! is_main_site( $details->userblog_id ) ) { // Main site is not a spam!                                         update_blog_status( $details->userblog_id, 'spam', '1' );
                                    }
                                }

                                $user_data         = $user->to_array();
                                $user_data['spam'] = '1';

                                wp_update_user( $user_data );
                                break;

                            case 'notspam':
                                $user = get_userdata( $user_id );

                                $userfunction = 'all_notspam';
                                $blogs        = get_blogs_of_user( $user_id, true );

                                foreach ( (array) $blogs as $details ) {
                                    update_blog_status( $details->userblog_id, 'spam', '0' );
                                }

                                

    do_action( 'retrieve_password_key', $user->user_login, $key );

    // Now insert the key, hashed, into the DB.     if ( empty( $wp_hasher ) ) {
        require_once ABSPATH . WPINC . '/class-phpass.php';
        $wp_hasher = new PasswordHash( 8, true );
    }

    $hashed = time() . ':' . $wp_hasher->HashPassword( $key );

    $key_saved = wp_update_user(
        array(
            'ID'                  => $user->ID,
            'user_activation_key' => $hashed,
        )
    );

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

    return $key;
}
$user_id      = wp_create_user( $user_name$user_password$user_email );
            $user_created = true;
        } else {
            $message = __( 'User already exists. Password inherited.' );
        }

        $user = new WP_User( $user_id );
        $user->set_role( 'administrator' );

        if ( $user_created ) {
            $user->user_url = $guessurl;
            wp_update_user( $user );
        }

        wp_install_defaults( $user_id );

        wp_install_maybe_enable_pretty_permalinks();

        flush_rewrite_rules();

        wp_new_blog_notification( $blog_title$guessurl$user_id( $email_password ? $user_password : __( 'The password you chose during installation.' ) ) );

        wp_cache_flush();

        
// Execute confirmed email change. See send_confirmation_on_profile_email(). if ( IS_PROFILE_PAGE && isset( $_GET['newuseremail'] ) && $current_user->ID ) {
    $new_email = get_user_meta( $current_user->ID, '_new_email', true );
    if ( $new_email && hash_equals( $new_email['hash']$_GET['newuseremail'] ) ) {
        $user             = new stdClass();
        $user->ID         = $current_user->ID;
        $user->user_email = esc_html( trim( $new_email['newemail'] ) );
        if ( is_multisite() && $wpdb->get_var( $wpdb->prepare( "SELECT user_login FROM {$wpdb->signups} WHERE user_login = %s", $current_user->user_login ) ) ) {
            $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_email = %s WHERE user_login = %s", $user->user_email, $current_user->user_login ) );
        }
        wp_update_user( $user );
        delete_user_meta( $current_user->ID, '_new_email' );
        wp_redirect( add_query_arg( array( 'updated' => 'true' )self_admin_url( 'profile.php' ) ) );
        die();
    } else {
        wp_redirect( add_query_arg( array( 'error' => 'new-email' )self_admin_url( 'profile.php' ) ) );
    }
} elseif ( IS_PROFILE_PAGE && ! empty( $_GET['dismiss'] ) && $current_user->ID . '_new_email' === $_GET['dismiss'] ) {
    check_admin_referer( 'dismiss-' . $current_user->ID . '_new_email' );
    delete_user_meta( $current_user->ID, '_new_email' );
    wp_redirect( add_query_arg( array( 'updated' => 'true' )self_admin_url( 'profile.php' ) ) );
    die();
}
$user_data['nickname'] = $content_struct['nickname'];
        }

        if ( isset( $content_struct['nicename'] ) ) {
            $user_data['user_nicename'] = $content_struct['nicename'];
        }

        if ( isset( $content_struct['bio'] ) ) {
            $user_data['description'] = $content_struct['bio'];
        }

        $result = wp_update_user( $user_data );

        if ( is_wp_error( $result ) ) {
            return new IXR_Error( 500, $result->get_error_message() );
        }

        if ( ! $result ) {
            return new IXR_Error( 500, __( 'Sorry, the user could not be updated.' ) );
        }

        return true;
    }

    
$user_id = wpmu_create_user( $user->user_login, $user->user_pass, $user->user_email );

            if ( ! $user_id ) {
                return new WP_Error(
                    'rest_user_create',
                    __( 'Error creating new user.' ),
                    array( 'status' => 500 )
                );
            }

            $user->ID = $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 ) );

            
Home | Imprint | This part of the site doesn't use cookies.