wppaste
WordPress

wp_user_settings()

Since
2.7.0
Source
wp-includes/option.php:1698
Saves and restores user interface settings stored in a cookie.

Description

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.

Uses · 7

Source

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    = 0; 		if ( isset( $_COOKIE[ 'wp-settings-time-' . $user_id ] ) ) {			$current = (int) preg_replace( '/[^0-9]/', '', $_COOKIE[ 'wp-settings-time-' . $user_id ] );		} 		// 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;}

History

Introduced in 2.7.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 6.9.7 tag, from src/wp-includes/option.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.