Skip to content

Instantly share code, notes, and snippets.

@glueckpress
Last active April 5, 2019 00:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save glueckpress/a6c1f7a22a92e8e8bb10 to your computer and use it in GitHub Desktop.
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.
<?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&#8217; 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' );
@Joe-Bloggs
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment