Make WordPress Core

Ticket #41937: 41937.2.patch

File 41937.2.patch, 5.6 KB (added by petertoi, 7 years ago)

Confirmed against updated coding standards. Updated @since.

  • src/wp-includes/default-constants.php

     
    240240                define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH);
    241241
    242242        /**
     243         * @since 4.9.2
     244         */
     245        if ( ! defined( 'SETTINGS_COOKIE' ) ) {
     246                define( 'SETTINGS_COOKIE', 'wp-settings-' );
     247        }
     248
     249        /**
     250         * @since 4.9.2
     251         */
     252        if ( ! defined( 'SETTINGS_TIME_COOKIE' ) ) {
     253                define( 'SETTINGS_TIME_COOKIE', 'wp-settings-time-' );
     254        }
     255
     256        /**
    243257         * @since 2.3.0
    244258         */
    245259        if ( !defined('TEST_COOKIE') )
  • src/wp-includes/js/utils.js

     
    157157        }
    158158
    159159        var uid = userSettings.uid,
    160                 settings = wpCookies.getHash( 'wp-settings-' + uid ),
     160                settings = wpCookies.getHash( userSettings.settingsCookie + uid ),
    161161                path = userSettings.url,
    162162                secure = !! userSettings.secure;
    163163
     
    177177                settings[name] = value;
    178178        }
    179179
    180         wpCookies.setHash( 'wp-settings-' + uid, settings, 31536000, path, '', secure );
    181         wpCookies.set( 'wp-settings-time-' + uid, userSettings.time, 31536000, path, '', secure );
     180        wpCookies.setHash( userSettings.settingsCookie + uid, settings, 31536000, path, '', secure );
     181        wpCookies.set( userSettings.settingsTimeCookie + uid, userSettings.time, 31536000, path, '', secure );
    182182
    183183        return name;
    184184}
  • src/wp-includes/option.php

     
    896896
    897897        $settings = (string) get_user_option( 'user-settings', $user_id );
    898898
    899         if ( isset( $_COOKIE['wp-settings-' . $user_id] ) ) {
    900                 $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id] );
     899        if ( isset( $_COOKIE[ SETTINGS_COOKIE . $user_id ] ) ) {
     900                $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE[ SETTINGS_COOKIE . $user_id ] );
    901901
    902902                // No change or both empty
    903903                if ( $cookie == $settings )
     
    904904                        return;
    905905
    906906                $last_saved = (int) get_user_option( 'user-settings-time', $user_id );
    907                 $current = isset( $_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace( '/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id] ) : 0;
     907                $current = isset( $_COOKIE[ SETTINGS_TIME_COOKIE . $user_id ] ) ? preg_replace( '/[^0-9]/', '', $_COOKIE[ SETTINGS_TIME_COOKIE . $user_id ] ) : 0;
    908908
    909909                // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is
    910910                if ( $current > $last_saved ) {
     
    916916
    917917        // The cookie is not set in the current browser or the saved value is newer.
    918918        $secure = ( 'https' === parse_url( admin_url(), PHP_URL_SCHEME ) );
    919         setcookie( 'wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
    920         setcookie( 'wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
    921         $_COOKIE['wp-settings-' . $user_id] = $settings;
     919        setcookie( SETTINGS_COOKIE . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
     920        setcookie( SETTINGS_TIME_COOKIE . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
     921        $_COOKIE[ SETTINGS_COOKIE . $user_id ] = $settings;
    922922}
    923923
    924924/**
     
    10171017
    10181018        $user_settings = array();
    10191019
    1020         if ( isset( $_COOKIE['wp-settings-' . $user_id] ) ) {
    1021                 $cookie = preg_replace( '/[^A-Za-z0-9=&_-]/', '', $_COOKIE['wp-settings-' . $user_id] );
     1020        if ( isset( $_COOKIE[ SETTINGS_COOKIE . $user_id ] ) ) {
     1021                $cookie = preg_replace( '/[^A-Za-z0-9=&_-]/', '', $_COOKIE[ SETTINGS_COOKIE . $user_id ] );
    10221022
    10231023                if ( strpos( $cookie, '=' ) ) { // '=' cannot be 1st char
    10241024                        parse_str( $cookie, $user_settings );
     
    10881088        }
    10891089
    10901090        update_user_option( $user_id, 'user-settings', '', false );
    1091         setcookie( 'wp-settings-' . $user_id, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
     1091        setcookie( SETTINGS_COOKIE . $user_id, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
    10921092}
    10931093
    10941094/**
  • src/wp-includes/pluggable.php

     
    953953        setcookie( LOGGED_IN_COOKIE,   ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH,      COOKIE_DOMAIN );
    954954
    955955        // Settings cookies
    956         setcookie( 'wp-settings-' . get_current_user_id(),      ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
    957         setcookie( 'wp-settings-time-' . get_current_user_id(), ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
     956        setcookie( SETTINGS_COOKIE . get_current_user_id(),      ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
     957        setcookie( SETTINGS_TIME_COOKIE . get_current_user_id(), ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
    958958
    959959        // Old cookies
    960960        setcookie( AUTH_COOKIE,        ' ', time() - YEAR_IN_SECONDS, COOKIEPATH,     COOKIE_DOMAIN );
  • src/wp-includes/script-loader.php

     
    7373                'uid' => (string) get_current_user_id(),
    7474                'time' => (string) time(),
    7575                'secure' => (string) ( 'https' === parse_url( site_url(), PHP_URL_SCHEME ) ),
     76                'settingsCookie' => (string) SETTINGS_COOKIE,
     77                'settingsTimeCookie' => (string) SETTINGS_TIME_COOKIE,
    7678        ) );
    7779
    7880        $scripts->add( 'common', "/wp-admin/js/common$suffix.js", array('jquery', 'hoverIntent', 'utils'), false, 1 );