Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save westonruter/8c19d87a80a36e8f24db910750162628 to your computer and use it in GitHub Desktop.
Save westonruter/8c19d87a80a36e8f24db910750162628 to your computer and use it in GitHub Desktop.
<?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