Make WordPress Core

Ticket #41937: 41937.patch

File 41937.patch, 5.6 KB (added by petertoi, 6 years ago)

Convert strings for wp-settings- and wp-settings-time- to constants

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

     
    239239                define('LOGGED_IN_COOKIE', 'wordpress_logged_in_' . COOKIEHASH);
    240240
    241241        /**
     242         * @since 4.9.0
     243         */
     244        if ( ! defined( 'SETTINGS_COOKIE' ) ) {
     245                define( 'SETTINGS_COOKIE', 'wp-settings-' );
     246        }
     247
     248        /**
     249         * @since 4.9.0
     250         */
     251        if ( ! defined( 'SETTINGS_TIME_COOKIE' ) ) {
     252                define( 'SETTINGS_TIME_COOKIE', 'wp-settings-time-' );
     253        }
     254
     255        /**
    242256         * @since 2.3.0
    243257         */
    244258        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

     
    841841
    842842        $settings = (string) get_user_option( 'user-settings', $user_id );
    843843
    844         if ( isset( $_COOKIE['wp-settings-' . $user_id] ) ) {
    845                 $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE['wp-settings-' . $user_id] );
     844        if ( isset( $_COOKIE[ SETTINGS_COOKIE . $user_id ] ) ) {
     845                $cookie = preg_replace( '/[^A-Za-z0-9=&_]/', '', $_COOKIE[ SETTINGS_COOKIE . $user_id ] );
    846846
    847847                // No change or both empty
    848848                if ( $cookie == $settings )
    849849                        return;
    850850
    851851                $last_saved = (int) get_user_option( 'user-settings-time', $user_id );
    852                 $current = isset( $_COOKIE['wp-settings-time-' . $user_id]) ? preg_replace( '/[^0-9]/', '', $_COOKIE['wp-settings-time-' . $user_id] ) : 0;
     852                $current = isset( $_COOKIE[ SETTINGS_TIME_COOKIE . $user_id ] ) ? preg_replace( '/[^0-9]/', '', $_COOKIE[ SETTINGS_TIME_COOKIE . $user_id ] ) : 0;
    853853
    854854                // The cookie is newer than the saved value. Update the user_option and leave the cookie as-is
    855855                if ( $current > $last_saved ) {
     
    861861
    862862        // The cookie is not set in the current browser or the saved value is newer.
    863863        $secure = ( 'https' === parse_url( admin_url(), PHP_URL_SCHEME ) );
    864         setcookie( 'wp-settings-' . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
    865         setcookie( 'wp-settings-time-' . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
    866         $_COOKIE['wp-settings-' . $user_id] = $settings;
     864        setcookie( SETTINGS_COOKIE . $user_id, $settings, time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
     865        setcookie( SETTINGS_TIME_COOKIE . $user_id, time(), time() + YEAR_IN_SECONDS, SITECOOKIEPATH, null, $secure );
     866        $_COOKIE[ SETTINGS_COOKIE . $user_id ] = $settings;
    867867}
    868868
    869869/**
     
    962962
    963963        $user_settings = array();
    964964
    965         if ( isset( $_COOKIE['wp-settings-' . $user_id] ) ) {
    966                 $cookie = preg_replace( '/[^A-Za-z0-9=&_-]/', '', $_COOKIE['wp-settings-' . $user_id] );
     965        if ( isset( $_COOKIE[ SETTINGS_COOKIE . $user_id ] ) ) {
     966                $cookie = preg_replace( '/[^A-Za-z0-9=&_-]/', '', $_COOKIE[ SETTINGS_COOKIE . $user_id ] );
    967967
    968968                if ( strpos( $cookie, '=' ) ) { // '=' cannot be 1st char
    969969                        parse_str( $cookie, $user_settings );
     
    10331033        }
    10341034
    10351035        update_user_option( $user_id, 'user-settings', '', false );
    1036         setcookie( 'wp-settings-' . $user_id, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
     1036        setcookie( SETTINGS_COOKIE . $user_id, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH );
    10371037}
    10381038
    10391039/**
  • 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 );