Last active
April 5, 2019 00:29
-
-
Save glueckpress/a6c1f7a22a92e8e8bb10 to your computer and use it in GitHub Desktop.
[WordPress][WP Rocket] Prevents WP Rocket’s preload bot from visiting your site.
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 | Disable Cache Preloading | |
* Description: Prevents WP Rocket’s preload bot from visiting your site. | |
* Author: WP Rocket Support Team | |
* Author URI: http://wp-rocket.me/ | |
* Plugin URI: https://gist.github.com/glueckpress/a6c1f7a22a92e8e8bb10 | |
* License: GNU General Public License v3 or later | |
* License URI: http://www.gnu.org/licenses/gpl-3.0.html | |
*/ | |
defined( 'ABSPATH' ) or die( 'Cheatin’ uh?' ); | |
register_activation_hook( __FILE__, 'wp_rocket_disable_preload__activation' ); | |
register_deactivation_hook( __FILE__, 'wp_rocket_disable_preload__deactivation' ); | |
/** | |
* Set up initial admin notice text. | |
* @return void | |
*/ | |
function wp_rocket_disable_preload__activation() { | |
$notice = 'Cache preloading has been disabled. Remember to <strong>deactivate and re-activate WP Rocket once!</strong>'; | |
update_option( 'wp_rocket_disable_preload', $notice ); | |
} | |
/** | |
* Clean house when leaving. | |
* @return void | |
*/ | |
function wp_rocket_disable_preload__deactivation() { | |
delete_option( 'wp_rocket_disable_preload' ); | |
} | |
/** | |
* Render admin notice. | |
* @return void | |
*/ | |
function wp_rocket_disable_preload__render_admin_notice() { | |
if ( ! current_user_can( 'manage_options' ) ) | |
return; | |
$notice = get_option( 'wp_rocket_disable_preload' ); | |
if ( false === $notice ) | |
return; | |
printf( | |
'<div class="notice notice-info"><p>%s</p></div>', | |
$notice | |
); | |
update_option( | |
'wp_rocket_disable_preload', | |
sprintf( | |
'Cache preloading is disabled by <a href="%s">WP Rocket | Disable Cache Preloading</a>.', | |
add_query_arg( 'plugin_status', 'active', admin_url( 'plugins.php' ) ) | |
) | |
); | |
} | |
add_action( 'admin_notices', 'wp_rocket_disable_preload__render_admin_notice' ); | |
/** | |
* Stop dat bot. | |
*/ | |
add_filter( 'do_run_rocket_bot', '__return_false' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @glueckpress, just came across to this page.
Can I just ask what's the point of this? There is a button to enable/disable WP Rocket preload in the plugin settings, right?