wp_user_settings

The timeline below displays how wordpress function wp_user_settings has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.4

/**
 * Saves and restores user interface settings stored in a cookie.
 *
 * Checks if the current user-settings cookie is updated and stores it. When no
 * cookie exists (different browser used), adds the last saved cookie restoring
 * the settings.
 *
 * @since 2.7.0
 */
function wp_user_settings()
{
    if (!is_admin() || wp_doing_ajax()) {
        return;
    }
    $user_id = get_current_user_id();
    if (!$user_id) {
        return;
    }
    if (!is_user_member_of_blog()) {
        return;
    }
    $settings = (string) get_user_option('user-settings', $user_id);
    if (isset($_COOKIE['wp-settings-' . $user_id])) {
        $cookie = preg_replace('/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id]);
        // No change or both empty.
        if ($cookie === $settings) {
            return;
        }
        $last_saved = (int) get_user_option('user-settings-time', $user_id);
        $current = isset($_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace('/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id]) : 0;
        // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is.
        if ($current > $last_saved) {
            update_user_option($user_id, 'user-settings', $cookie, false);
            update_user_option($user_id, 'user-settings-time', time() - 5, false);
            return;
        }
    }
    // The cookie is not set in the current browser or the saved value is newer.
    $secure = 'https' === parse_url(admin_url(), PHP_URL_SCHEME);
    setcookie('wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, '', $secure);
    setcookie('wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, '', $secure);
    $_COOKIE['wp-settings-' . $user_id] = $settings;
}

WordPress Version: 6.1

/**
 * Saves and restores user interface settings stored in a cookie.
 *
 * Checks if the current user-settings cookie is updated and stores it. When no
 * cookie exists (different browser used), adds the last saved cookie restoring
 * the settings.
 *
 * @since 2.7.0
 */
function wp_user_settings()
{
    if (!is_admin() || wp_doing_ajax()) {
        return;
    }
    $user_id = get_current_user_id();
    if (!$user_id) {
        return;
    }
    if (!is_user_member_of_blog()) {
        return;
    }
    $settings = (string) get_user_option('user-settings', $user_id);
    if (isset($_COOKIE['wp-settings-' . $user_id])) {
        $cookie = preg_replace('/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id]);
        // No change or both empty.
        if ($cookie == $settings) {
            return;
        }
        $last_saved = (int) get_user_option('user-settings-time', $user_id);
        $current = isset($_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace('/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id]) : 0;
        // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is.
        if ($current > $last_saved) {
            update_user_option($user_id, 'user-settings', $cookie, false);
            update_user_option($user_id, 'user-settings-time', time() - 5, false);
            return;
        }
    }
    // The cookie is not set in the current browser or the saved value is newer.
    $secure = 'https' === parse_url(admin_url(), PHP_URL_SCHEME);
    setcookie('wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, '', $secure);
    setcookie('wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, '', $secure);
    $_COOKIE['wp-settings-' . $user_id] = $settings;
}

WordPress Version: 5.4

/**
 * Saves and restores user interface settings stored in a cookie.
 *
 * Checks if the current user-settings cookie is updated and stores it. When no
 * cookie exists (different browser used), adds the last saved cookie restoring
 * the settings.
 *
 * @since 2.7.0
 */
function wp_user_settings()
{
    if (!is_admin() || wp_doing_ajax()) {
        return;
    }
    $user_id = get_current_user_id();
    if (!$user_id) {
        return;
    }
    if (!is_user_member_of_blog()) {
        return;
    }
    $settings = (string) get_user_option('user-settings', $user_id);
    if (isset($_COOKIE['wp-settings-' . $user_id])) {
        $cookie = preg_replace('/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id]);
        // No change or both empty.
        if ($cookie == $settings) {
            return;
        }
        $last_saved = (int) get_user_option('user-settings-time', $user_id);
        $current = isset($_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace('/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id]) : 0;
        // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is.
        if ($current > $last_saved) {
            update_user_option($user_id, 'user-settings', $cookie, false);
            update_user_option($user_id, 'user-settings-time', time() - 5, false);
            return;
        }
    }
    // The cookie is not set in the current browser or the saved value is newer.
    $secure = 'https' === parse_url(admin_url(), PHP_URL_SCHEME);
    setcookie('wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure);
    setcookie('wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure);
    $_COOKIE['wp-settings-' . $user_id] = $settings;
}

WordPress Version: 5.3

/**
 * Saves and restores user interface settings stored in a cookie.
 *
 * Checks if the current user-settings cookie is updated and stores it. When no
 * cookie exists (different browser used), adds the last saved cookie restoring
 * the settings.
 *
 * @since 2.7.0
 */
function wp_user_settings()
{
    if (!is_admin() || wp_doing_ajax()) {
        return;
    }
    $user_id = get_current_user_id();
    if (!$user_id) {
        return;
    }
    if (!is_user_member_of_blog()) {
        return;
    }
    $settings = (string) get_user_option('user-settings', $user_id);
    if (isset($_COOKIE['wp-settings-' . $user_id])) {
        $cookie = preg_replace('/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id]);
        // No change or both empty
        if ($cookie == $settings) {
            return;
        }
        $last_saved = (int) get_user_option('user-settings-time', $user_id);
        $current = isset($_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace('/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id]) : 0;
        // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is
        if ($current > $last_saved) {
            update_user_option($user_id, 'user-settings', $cookie, false);
            update_user_option($user_id, 'user-settings-time', time() - 5, false);
            return;
        }
    }
    // The cookie is not set in the current browser or the saved value is newer.
    $secure = 'https' === parse_url(admin_url(), PHP_URL_SCHEME);
    setcookie('wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure);
    setcookie('wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure);
    $_COOKIE['wp-settings-' . $user_id] = $settings;
}

WordPress Version: 4.8

/**
 * Saves and restores user interface settings stored in a cookie.
 *
 * Checks if the current user-settings cookie is updated and stores it. When no
 * cookie exists (different browser used), adds the last saved cookie restoring
 * the settings.
 *
 * @since 2.7.0
 */
function wp_user_settings()
{
    if (!is_admin() || wp_doing_ajax()) {
        return;
    }
    if (!$user_id = get_current_user_id()) {
        return;
    }
    if (!is_user_member_of_blog()) {
        return;
    }
    $settings = (string) get_user_option('user-settings', $user_id);
    if (isset($_COOKIE['wp-settings-' . $user_id])) {
        $cookie = preg_replace('/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id]);
        // No change or both empty
        if ($cookie == $settings) {
            return;
        }
        $last_saved = (int) get_user_option('user-settings-time', $user_id);
        $current = isset($_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace('/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id]) : 0;
        // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is
        if ($current > $last_saved) {
            update_user_option($user_id, 'user-settings', $cookie, false);
            update_user_option($user_id, 'user-settings-time', time() - 5, false);
            return;
        }
    }
    // The cookie is not set in the current browser or the saved value is newer.
    $secure = 'https' === parse_url(admin_url(), PHP_URL_SCHEME);
    setcookie('wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure);
    setcookie('wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure);
    $_COOKIE['wp-settings-' . $user_id] = $settings;
}

WordPress Version: 4.7

/**
 * Saves and restores user interface settings stored in a cookie.
 *
 * Checks if the current user-settings cookie is updated and stores it. When no
 * cookie exists (different browser used), adds the last saved cookie restoring
 * the settings.
 *
 * @since 2.7.0
 */
function wp_user_settings()
{
    if (!is_admin() || wp_doing_ajax()) {
        return;
    }
    if (!$user_id = get_current_user_id()) {
        return;
    }
    if (is_super_admin() && !is_user_member_of_blog()) {
        return;
    }
    $settings = (string) get_user_option('user-settings', $user_id);
    if (isset($_COOKIE['wp-settings-' . $user_id])) {
        $cookie = preg_replace('/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id]);
        // No change or both empty
        if ($cookie == $settings) {
            return;
        }
        $last_saved = (int) get_user_option('user-settings-time', $user_id);
        $current = isset($_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace('/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id]) : 0;
        // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is
        if ($current > $last_saved) {
            update_user_option($user_id, 'user-settings', $cookie, false);
            update_user_option($user_id, 'user-settings-time', time() - 5, false);
            return;
        }
    }
    // The cookie is not set in the current browser or the saved value is newer.
    $secure = 'https' === parse_url(admin_url(), PHP_URL_SCHEME);
    setcookie('wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure);
    setcookie('wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure);
    $_COOKIE['wp-settings-' . $user_id] = $settings;
}

WordPress Version: 4.4

/**
 * Saves and restores user interface settings stored in a cookie.
 *
 * Checks if the current user-settings cookie is updated and stores it. When no
 * cookie exists (different browser used), adds the last saved cookie restoring
 * the settings.
 *
 * @since 2.7.0
 */
function wp_user_settings()
{
    if (!is_admin() || defined('DOING_AJAX')) {
        return;
    }
    if (!$user_id = get_current_user_id()) {
        return;
    }
    if (is_super_admin() && !is_user_member_of_blog()) {
        return;
    }
    $settings = (string) get_user_option('user-settings', $user_id);
    if (isset($_COOKIE['wp-settings-' . $user_id])) {
        $cookie = preg_replace('/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id]);
        // No change or both empty
        if ($cookie == $settings) {
            return;
        }
        $last_saved = (int) get_user_option('user-settings-time', $user_id);
        $current = isset($_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace('/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id]) : 0;
        // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is
        if ($current > $last_saved) {
            update_user_option($user_id, 'user-settings', $cookie, false);
            update_user_option($user_id, 'user-settings-time', time() - 5, false);
            return;
        }
    }
    // The cookie is not set in the current browser or the saved value is newer.
    $secure = 'https' === parse_url(admin_url(), PHP_URL_SCHEME);
    setcookie('wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure);
    setcookie('wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure);
    $_COOKIE['wp-settings-' . $user_id] = $settings;
}

WordPress Version: 4.0

/**
 * Saves and restores user interface settings stored in a cookie.
 *
 * Checks if the current user-settings cookie is updated and stores it. When no
 * cookie exists (different browser used), adds the last saved cookie restoring
 * the settings.
 *
 * @since 2.7.0
 */
function wp_user_settings()
{
    if (!is_admin() || defined('DOING_AJAX')) {
        return;
    }
    if (!$user_id = get_current_user_id()) {
        return;
    }
    if (is_super_admin() && !is_user_member_of_blog()) {
        return;
    }
    $settings = (string) get_user_option('user-settings', $user_id);
    if (isset($_COOKIE['wp-settings-' . $user_id])) {
        $cookie = preg_replace('/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id]);
        // No change or both empty
        if ($cookie == $settings) {
            return;
        }
        $last_saved = (int) get_user_option('user-settings-time', $user_id);
        $current = isset($_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace('/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id]) : 0;
        // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is
        if ($current > $last_saved) {
            update_user_option($user_id, 'user-settings', $cookie, false);
            update_user_option($user_id, 'user-settings-time', time() - 5, false);
            return;
        }
    }
    // The cookie is not set in the current browser or the saved value is newer.
    $secure = 'https' === parse_url(site_url(), PHP_URL_SCHEME);
    setcookie('wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure);
    setcookie('wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure);
    $_COOKIE['wp-settings-' . $user_id] = $settings;
}

WordPress Version: 3.9

/**
 * Saves and restores user interface settings stored in a cookie.
 *
 * Checks if the current user-settings cookie is updated and stores it. When no
 * cookie exists (different browser used), adds the last saved cookie restoring
 * the settings.
 *
 * @since 2.7.0
 */
function wp_user_settings()
{
    if (!is_admin()) {
        return;
    }
    if (defined('DOING_AJAX')) {
        return;
    }
    if (!$user_id = get_current_user_id()) {
        return;
    }
    if (is_super_admin() && !is_user_member_of_blog()) {
        return;
    }
    $settings = (string) get_user_option('user-settings', $user_id);
    if (isset($_COOKIE['wp-settings-' . $user_id])) {
        $cookie = preg_replace('/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id]);
        // No change or both empty
        if ($cookie == $settings) {
            return;
        }
        $last_saved = (int) get_user_option('user-settings-time', $user_id);
        $current = isset($_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace('/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id]) : 0;
        // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is
        if ($current > $last_saved) {
            update_user_option($user_id, 'user-settings', $cookie, false);
            update_user_option($user_id, 'user-settings-time', time() - 5, false);
            return;
        }
    }
    // The cookie is not set in the current browser or the saved value is newer.
    setcookie('wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH);
    setcookie('wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH);
    $_COOKIE['wp-settings-' . $user_id] = $settings;
}

WordPress Version: 3.7

/**
 * Saves and restores user interface settings stored in a cookie.
 *
 * Checks if the current user-settings cookie is updated and stores it. When no
 * cookie exists (different browser used), adds the last saved cookie restoring
 * the settings.
 *
 * @package WordPress
 * @subpackage Option
 * @since 2.7.0
 */
function wp_user_settings()
{
    if (!is_admin()) {
        return;
    }
    if (defined('DOING_AJAX')) {
        return;
    }
    if (!$user_id = get_current_user_id()) {
        return;
    }
    if (is_super_admin() && !is_user_member_of_blog()) {
        return;
    }
    $settings = (string) get_user_option('user-settings', $user_id);
    if (isset($_COOKIE['wp-settings-' . $user_id])) {
        $cookie = preg_replace('/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id]);
        // No change or both empty
        if ($cookie == $settings) {
            return;
        }
        $last_saved = (int) get_user_option('user-settings-time', $user_id);
        $current = isset($_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace('/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id]) : 0;
        // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is
        if ($current > $last_saved) {
            update_user_option($user_id, 'user-settings', $cookie, false);
            update_user_option($user_id, 'user-settings-time', time() - 5, false);
            return;
        }
    }
    // The cookie is not set in the current browser or the saved value is newer.
    setcookie('wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH);
    setcookie('wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH);
    $_COOKIE['wp-settings-' . $user_id] = $settings;
}