Created
September 15, 2017 13:55
-
-
Save remyperona/b07c31d3a4b7bd4d08c4a1c052ef288a to your computer and use it in GitHub Desktop.
This file contains hidden or 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: No cache after logged-in user comment | |
* Description: Don't use cache after a user made a comment | |
* Author: WP Rocket team | |
* License: GNU General Public License v3 or later | |
* License URI: http://www.gnu.org/licenses/gpl-3.0.html | |
*/ | |
// Basic security, prevents file from being loaded directly. | |
defined( 'ABSPATH' ) or die( 'Cheatin’ uh?' ); | |
function wp_rocket_set_loggedin_comment( $comment, $user ) { | |
if ( ! $user->exists() ) { | |
return; | |
} | |
$comment_cookie_lifetime = apply_filters( 'comment_cookie_lifetime', 30000000 ); | |
$secure = ( 'https' === parse_url( home_url(), PHP_URL_SCHEME ) ); | |
setcookie( 'logged_in_comment_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure ); | |
} | |
add_action( 'set_comment_cookies', 'wp_rocket_set_loggedin_comment', 10, 2 ); | |
function wp_rocket_add_cookie( $cookies ) { | |
$cookies[] = 'logged_in_comment_'; | |
return $cookies; | |
} | |
add_filter( 'rocket_cache_reject_cookies', 'wp_rocket_add_cookie' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment