diff --git a/src/wp-includes/class-wp-recovery-mode-cookie-service.php b/src/wp-includes/class-wp-recovery-mode-cookie-service.php
index c42dbb105c..eed4839cb4 100644
|
a
|
b
|
|
| 13 | 13 | */ |
| 14 | 14 | final class WP_Recovery_Mode_Cookie_Service { |
| 15 | 15 | |
| 16 | | /** |
| 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 | 16 | /** |
| 80 | 17 | * Checks whether the recovery mode cookie is set. |
| 81 | 18 | * |
| … |
… |
final class WP_Recovery_Mode_Cookie_Service { |
| 84 | 21 | * @return bool True if the cookie is set, false otherwise. |
| 85 | 22 | */ |
| 86 | 23 | public function is_cookie_set() { |
| 87 | | return ! empty( $_COOKIE[ $this->name ] ); |
| | 24 | return ! empty( $_COOKIE[ RECOVERY_MODE_COOKIE ] ); |
| 88 | 25 | } |
| 89 | 26 | |
| 90 | 27 | /** |
| … |
… |
final class WP_Recovery_Mode_Cookie_Service { |
| 98 | 35 | |
| 99 | 36 | $value = $this->generate_cookie(); |
| 100 | 37 | |
| 101 | | setcookie( $this->name, $value, 0, $this->path, $this->domain, is_ssl(), true ); |
| | 38 | setcookie( RECOVERY_MODE_COOKIE, $value, 0, COOKIEPATH, COOKIE_DOMAIN, is_ssl(), true ); |
| 102 | 39 | |
| 103 | | if ( $this->path !== $this->site_path ) { |
| 104 | | setcookie( $this->name, $value, 0, $this->site_path, $this->domain, is_ssl(), true ); |
| | 40 | if ( COOKIEPATH !== SITECOOKIEPATH ) { |
| | 41 | setcookie( RECOVERY_MODE_COOKIE, $value, 0, SITECOOKIEPATH, COOKIE_DOMAIN, is_ssl(), true ); |
| 105 | 42 | } |
| 106 | 43 | } |
| 107 | 44 | |
| … |
… |
final class WP_Recovery_Mode_Cookie_Service { |
| 111 | 48 | * @since 5.2.0 |
| 112 | 49 | */ |
| 113 | 50 | 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 ); |
| 116 | 53 | } |
| 117 | 54 | |
| 118 | 55 | /** |
| … |
… |
final class WP_Recovery_Mode_Cookie_Service { |
| 127 | 64 | public function validate_cookie( $cookie = '' ) { |
| 128 | 65 | |
| 129 | 66 | if ( ! $cookie ) { |
| 130 | | if ( empty( $_COOKIE[ $this->name ] ) ) { |
| | 67 | if ( empty( $_COOKIE[ RECOVERY_MODE_COOKIE ] ) ) { |
| 131 | 68 | return new WP_Error( 'no_cookie', __( 'No cookie present.' ) ); |
| 132 | 69 | } |
| 133 | 70 | |
| 134 | | $cookie = $_COOKIE[ $this->name ]; |
| | 71 | $cookie = $_COOKIE[ RECOVERY_MODE_COOKIE ]; |
| 135 | 72 | } |
| 136 | 73 | |
| 137 | 74 | $parts = $this->parse_cookie( $cookie ); |
| … |
… |
final class WP_Recovery_Mode_Cookie_Service { |
| 182 | 119 | */ |
| 183 | 120 | public function get_session_id_from_cookie( $cookie = '' ) { |
| 184 | 121 | if ( ! $cookie ) { |
| 185 | | if ( empty( $_COOKIE[ $this->name ] ) ) { |
| | 122 | if ( empty( $_COOKIE[ RECOVERY_MODE_COOKIE ] ) ) { |
| 186 | 123 | return new WP_Error( 'no_cookie', __( 'No cookie present.' ) ); |
| 187 | 124 | } |
| 188 | 125 | |
| 189 | | $cookie = $_COOKIE[ $this->name ]; |
| | 126 | $cookie = $_COOKIE[ RECOVERY_MODE_COOKIE ]; |
| 190 | 127 | } |
| 191 | 128 | |
| 192 | 129 | $parts = $this->parse_cookie( $cookie ); |