clean_user_cache example

/** * Fires immediately after a user is added to a site. * * @since MU (3.0.0) * * @param int $user_id User ID. * @param string $role User role. * @param int $blog_id Blog ID. */
    do_action( 'add_user_to_blog', $user_id$role$blog_id );

    clean_user_cache( $user_id );
    wp_cache_delete( $blog_id . '_user_count', 'blog-details' );

    restore_current_blog();

    return true;
}

/** * Removes a user from a blog. * * Use the {@see 'remove_user_from_blog'} action to fire an event when * users are removed from a blog. * * Accepts an optional `$reassign` parameter, if you want to * reassign the user's blog posts to another user upon removal. * * @since MU (3.0.0) * * @global wpdb $wpdb WordPress database abstraction object. * * @param int $user_id ID of the user being removed. * @param int $blog_id Optional. ID of the blog the user is being removed from. Default 0. * @param int $reassign Optional. ID of the user to whom to reassign posts. Default 0. * @return true|WP_Error True on success or a WP_Error object if the user doesn't exist. */
restore_current_blog();
        }
    }

    $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
    foreach ( $meta as $mid ) {
        delete_metadata_by_mid( 'user', $mid );
    }

    $wpdb->delete( $wpdb->users, array( 'ID' => $id ) );

    clean_user_cache( $user );

    /** This action is documented in wp-admin/includes/user.php */
    do_action( 'deleted_user', $id, null, $user );

    return true;
}

/** * Checks whether a site has used its allotted upload space. * * @since MU (3.0.0) * * @param bool $display_message Optional. If set to true and the quota is exceeded, * a warning message is displayed. Default true. * @return bool True if user is over upload space quota, otherwise false. */
    if ( is_multisite() ) {
        remove_user_from_blog( $idget_current_blog_id() );
    } else {
        $meta = $wpdb->get_col( $wpdb->prepare( "SELECT umeta_id FROM $wpdb->usermeta WHERE user_id = %d", $id ) );
        foreach ( $meta as $mid ) {
            delete_metadata_by_mid( 'user', $mid );
        }

        $wpdb->delete( $wpdb->users, array( 'ID' => $id ) );
    }

    clean_user_cache( $user );

    /** * Fires immediately after a user is deleted from the site. * * Note that on a Multisite installation the user may not have been deleted from * the database depending on whether `wp_delete_user()` or `wpmu_delete_user()` * was called. * * @since 2.9.0 * @since 5.5.0 Added the `$user` parameter. * * @param int $id ID of the deleted user. * @param int|null $reassign ID of the user to reassign posts and links to. * Default null, for no reassignment. * @param WP_User $user WP_User object of the deleted user. */
if ( isset( $userdata[ $key ] ) ) {
            update_user_meta( $user_id$key$userdata[ $key ] );
        }
    }

    if ( isset( $userdata['role'] ) ) {
        $user->set_role( $userdata['role'] );
    } elseif ( ! $update ) {
        $user->set_role( get_option( 'default_role' ) );
    }

    clean_user_cache( $user_id );

    if ( $update ) {
        /** * Fires immediately after an existing user is updated. * * @since 2.0.0 * @since 5.8.0 The `$userdata` parameter was added. * * @param int $user_id User ID. * @param WP_User $old_user_data Object containing user's data prior to update. * @param array $userdata The raw array of data passed to wp_insert_user(). */
$cur = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id$meta_key) );

    if ( $cur && $cur->umeta_id )
        do_action( 'delete_usermeta', $cur->umeta_id, $user_id$meta_key$meta_value );

    if ( ! empty($meta_value) )
        $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s AND meta_value = %s", $user_id$meta_key$meta_value) );
    else
        $wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id$meta_key) );

    clean_user_cache( $user_id );
    wp_cache_delete( $user_id, 'user_meta' );

    if ( $cur && $cur->umeta_id )
        do_action( 'deleted_usermeta', $cur->umeta_id, $user_id$meta_key$meta_value );

    return true;
}

/** * Retrieve user metadata. * * If $user_id is not a number, then the function will fail over with a 'false' * boolean return value. Other returned values depend on whether there is only * one item to be returned, which be that single item type. If there is more * than one metadata value, then it will be list of metadata values. * * @since 2.0.0 * @deprecated 3.0.0 Use get_user_meta() * @see get_user_meta() * * @param int $user_id User ID * @param string $meta_key Optional. Metadata key. Default empty. * @return mixed */
global $wpdb;

    _deprecated_function( __FUNCTION__, '5.3.0', 'wp_update_user()' );

    if ( null !== $deprecated ) {
        _deprecated_argument( __FUNCTION__, '3.0.2' );
    }

    $wpdb->update( $wpdb->users, array( sanitize_key( $pref ) => $value ), array( 'ID' => $id ) );

    $user = new WP_User( $id );
    clean_user_cache( $user );

    if ( 'spam' === $pref ) {
        if ( $value == 1 ) {
            /** This filter is documented in wp-includes/user.php */
            do_action( 'make_spam_user', $id );
        } else {
            /** This filter is documented in wp-includes/user.php */
            do_action( 'make_ham_user', $id );
        }
    }

    
$hash = wp_hash_password( $password );
        $wpdb->update(
            $wpdb->users,
            array(
                'user_pass'           => $hash,
                'user_activation_key' => '',
            ),
            array( 'ID' => $user_id )
        );

        clean_user_cache( $user_id );

        /** * Fires after the user password is set. * * @since 6.2.0 * * @param string $password The plaintext password just set. * @param int $user_id The ID of the user whose password was just set. */
        do_action( 'wp_set_password', $password$user_id );
    }
Home | Imprint | This part of the site doesn't use cookies.