On this page
WP_Recovery_Mode_Cookie_Service::validate_cookie( string $cookie = '' ): true|WP_Error
Validates the recovery mode cookie.
Parameters
$cookiestring Optional-
y specify the cookie string.
If omitted, it will be retrieved from the super global.Default:
''
Return
true|WP_Error True on success, error object on failure.
Source
File: wp-includes/class-wp-recovery-mode-cookie-service.php. View all references
public function validate_cookie( $cookie = '' ) {
if ( ! $cookie ) {
if ( empty( $_COOKIE[ RECOVERY_MODE_COOKIE ] ) ) {
return new WP_Error( 'no_cookie', __( 'No cookie present.' ) );
}
$cookie = $_COOKIE[ RECOVERY_MODE_COOKIE ];
}
$parts = $this->parse_cookie( $cookie );
if ( is_wp_error( $parts ) ) {
return $parts;
}
list( , $created_at, $random, $signature ) = $parts;
if ( ! ctype_digit( $created_at ) ) {
return new WP_Error( 'invalid_created_at', __( 'Invalid cookie format.' ) );
}
/** This filter is documented in wp-includes/class-wp-recovery-mode-cookie-service.php */
$length = apply_filters( 'recovery_mode_cookie_length', WEEK_IN_SECONDS );
if ( time() > $created_at + $length ) {
return new WP_Error( 'expired', __( 'Cookie expired.' ) );
}
$to_sign = sprintf( 'recovery_mode|%s|%s', $created_at, $random );
$hashed = $this->recovery_mode_hash( $to_sign );
if ( ! hash_equals( $signature, $hashed ) ) {
return new WP_Error( 'signature_mismatch', __( 'Invalid cookie.' ) );
}
return true;
}
Hooks
- apply_filters( 'recovery_mode_cookie_length',
int $length ) -
Filters the length of time a Recovery Mode cookie is valid for.
Related
Uses
| Uses | Description |
|---|---|
| WP_Recovery_Mode_Cookie_Service::parse_cookie() wp-includes/class-wp-recovery-mode-cookie-service.php | Parses the cookie into its four parts. |
| WP_Recovery_Mode_Cookie_Service::recovery_mode_hash() wp-includes/class-wp-recovery-mode-cookie-service.php | Gets a form of |
| __() wp-includes/l10n.php | Retrieves the translation of $text. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
| is_wp_error() wp-includes/load.php | Checks whether the given variable is a WordPress Error. |
| WP_Error::__construct() wp-includes/class-wp-error.php | Initializes the error. |
Changelog
| Version | Description |
|---|---|
| 5.2.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_recovery_mode_cookie_service/validate_cookie