Last active
October 21, 2019 10:08
-
-
Save vmanthos/fb949e14808e1b90612d60b3d55287d1 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: WP Rocket | No Cache for IP | |
* Description: Disable WP Rocket caching and optimizations by IP. | |
* Plugin URI: https://github.com/wp-media/wp-rocket-helpers/tree/master/cache/wp-rocket-no-cache-for-admins/ | |
* Author: WP Rocket Support Team | |
* Author URI: http://wp-rocket.me/ | |
* License: GNU General Public License v2 or later | |
* License URI: http://www.gnu.org/licenses/gpl-2.0.html | |
* | |
* Copyright SAS WP MEDIA 2018 | |
*/ | |
namespace WP_Rocket\Helpers\cache\no_cache_for_ip; | |
// Standard plugin security, keep this line in place. | |
defined( 'ABSPATH' ) or die(); | |
/** | |
* Never serve cached pages for this IP | |
* | |
* @author Sabrina Zeidan | |
*/ | |
function handle_cache_for_IP() { | |
// Only for this IP (Replace example IP with yours) | |
if (!($_SERVER['REMOTE_ADDR'] == 'add_your_IP_here')) { | |
return false; | |
} | |
// Only when WP Rocket is active. | |
if ( ! function_exists( 'get_rocket_option' ) ) { | |
return false; | |
} | |
// Prevent caching for that IP | |
add_action( 'template_redirect', __NAMESPACE__ . '\donotcache' ); | |
} | |
add_action( 'init', __NAMESPACE__ . '\handle_cache_for_IP' ); | |
/** | |
* Prevent caching and optimization. | |
* | |
* @author Caspar Hübinger | |
*/ | |
function donotcache() { | |
define( 'DONOTCACHEPAGE', true ); | |
define( 'DONOTROCKETOPTIMIZE', true ); | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment