Created
August 24, 2023 19:28
-
-
Save westonruter/8c19d87a80a36e8f24db910750162628 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Disable Cache-Control: no-store when remembering | |
* Author: Weston Ruter | |
* Plugin URI: https://gist.github.com/westonruter/8c19d87a80a36e8f24db910750162628 | |
* Update URI: https://gist.github.com/westonruter/8c19d87a80a36e8f24db910750162628 | |
*/ | |
add_filter( | |
'nocache_headers', | |
static function ( $headers ) { | |
if ( ! is_user_logged_in() ) { | |
return $headers; | |
} | |
$session = WP_Session_Tokens::get_instance( get_current_user_id() )->get( wp_get_session_token() ); | |
if ( empty( $session['remember'] ) ) { | |
return $headers; | |
} | |
if ( | |
isset( $headers['Cache-Control'] ) && | |
str_contains( $headers['Cache-Control'], 'no-store' ) | |
) { | |
$directives = array_diff( | |
preg_split( '/\s*,\s*/', $headers['Cache-Control'] ), | |
array( 'no-store' ) | |
); | |
$headers['Cache-Control'] = implode( ', ', $directives ); | |
} | |
return $headers; | |
} | |
); | |
add_filter( | |
'attach_session_information', | |
static function ( $session ) { | |
if ( isset( $_POST['rememberme'] ) ) { | |
$session['remember'] = true; | |
} | |
return $session; | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment