Make WordPress Core


Ignore:
Timestamp:
04/15/2019 10:43:57 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Bootstrap/Load: Remove WP_Recovery_Mode_Cookie_Service constructor to avoid referencing cookie constants before they are defined.

Instantiating WP_Recovery_Mode should no longer have any required timing.

Props TimothyBlynJacobs, lkraav.
Fixes #46882.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-recovery-mode-cookie-service.php

    r44973 r45205  
    1515
    1616    /**
    17      * The cookie name to use.
    18      *
    19      * @since 5.2.0
    20      * @var string
    21      */
    22     private $name;
    23 
    24     /**
    25      * The domain the cookie should be set on, {@see setcookie()}.
    26      *
    27      * @since 5.2.0
    28      * @var string
    29      */
    30     private $domain;
    31 
    32     /**
    33      * The path to limit the cookie to, {@see setcookie()}.
    34      *
    35      * @since 5.2.0
    36      * @var string
    37      */
    38     private $path;
    39 
    40     /**
    41      * The path to use when the home_url and site_url are different.
    42      *
    43      * @since 5.2.0
    44      * @var string
    45      */
    46     private $site_path;
    47 
    48     /**
    49      * WP_Recovery_Mode_Cookie_Service constructor.
    50      *
    51      * @since 5.2.0
    52      *
    53      * @param array $opts {
    54      *     Recovery mode cookie options.
    55      *
    56      *     @type string $name      Cookie name.
    57      *     @type string $domain    Cookie domain.
    58      *     @type string $path      Cookie path.
    59      *     @type string $site_path Site cookie path.
    60      * }
    61      */
    62     public function __construct( array $opts = array() ) {
    63         $opts = wp_parse_args(
    64             $opts,
    65             array(
    66                 'name'      => RECOVERY_MODE_COOKIE,
    67                 'domain'    => COOKIE_DOMAIN,
    68                 'path'      => COOKIEPATH,
    69                 'site_path' => SITECOOKIEPATH,
    70             )
    71         );
    72 
    73         $this->name      = $opts['name'];
    74         $this->domain    = $opts['domain'];
    75         $this->path      = $opts['path'];
    76         $this->site_path = $opts['site_path'];
    77     }
    78 
    79     /**
    8017     * Checks whether the recovery mode cookie is set.
    8118     *
     
    8522     */
    8623    public function is_cookie_set() {
    87         return ! empty( $_COOKIE[ $this->name ] );
     24        return ! empty( $_COOKIE[ RECOVERY_MODE_COOKIE ] );
    8825    }
    8926
     
    9936        $value = $this->generate_cookie();
    10037
    101         setcookie( $this->name, $value, 0, $this->path, $this->domain, is_ssl(), true );
    102 
    103         if ( $this->path !== $this->site_path ) {
    104             setcookie( $this->name, $value, 0, $this->site_path, $this->domain, is_ssl(), true );
     38        setcookie( RECOVERY_MODE_COOKIE, $value, 0, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true );
     39
     40        if ( COOKIEPATH !== SITECOOKIEPATH ) {
     41            setcookie( RECOVERY_MODE_COOKIE, $value, 0, SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl(), true );
    10542        }
    10643    }
     
    11249     */
    11350    public function clear_cookie() {
    114         setcookie( $this->name, ' ', time() - YEAR_IN_SECONDS, $this->path, $this->domain );
    115         setcookie( $this->name, ' ', time() - YEAR_IN_SECONDS, $this->site_path, $this->domain );
     51        setcookie( RECOVERY_MODE_COOKIE, ' ', time() - YEAR_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
     52        setcookie( RECOVERY_MODE_COOKIE, ' ', time() - YEAR_IN_SECONDS, SITECOOKIEPATH, COOKIE_DOMAIN );
    11653    }
    11754
     
    12865
    12966        if ( ! $cookie ) {
    130             if ( empty( $_COOKIE[ $this->name ] ) ) {
     67            if ( empty( $_COOKIE[ RECOVERY_MODE_COOKIE ] ) ) {
    13168                return new WP_Error( 'no_cookie', __( 'No cookie present.' ) );
    13269            }
    13370
    134             $cookie = $_COOKIE[ $this->name ];
     71            $cookie = $_COOKIE[ RECOVERY_MODE_COOKIE ];
    13572        }
    13673
     
    183120    public function get_session_id_from_cookie( $cookie = '' ) {
    184121        if ( ! $cookie ) {
    185             if ( empty( $_COOKIE[ $this->name ] ) ) {
     122            if ( empty( $_COOKIE[ RECOVERY_MODE_COOKIE ] ) ) {
    186123                return new WP_Error( 'no_cookie', __( 'No cookie present.' ) );
    187124            }
    188125
    189             $cookie = $_COOKIE[ $this->name ];
     126            $cookie = $_COOKIE[ RECOVERY_MODE_COOKIE ];
    190127        }
    191128
Note: See TracChangeset for help on using the changeset viewer.