| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: RabbitLoader |
| 5 |
* Plugin URI: https://rabbitloader.com |
| 6 |
* Author: RabbitLoader |
| 7 |
* Author URI: https://rabbitloader.com/ |
| 8 |
* Description: RabbitLoader can improve Google PageSpeed score and get you 100 out of 100 by improving the page load time to just a few milliseconds. It improves the Core Web Vitals score for your pages and boost PageSpeed score to help better search rankings and best the experience for your end user. |
| 9 |
* Version: 3.0.3 |
| 10 |
* Text Domain: rabbit-loader |
| 11 |
*/ |
| 12 |
/* |
| 13 |
RabbitLoader is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or any later version. */ |
| 14 |
|
| 15 |
defined('ABSPATH') or die('ABSPATH not defined'); |
| 16 |
|
| 17 |
$plug_dir = dirname(__FILE__) . '/'; |
| 18 |
include_once($plug_dir . 'autoload.php'); |
| 19 |
|
| 20 |
add_action('save_post', function ($post_ID, $post, $update) { |
| 21 |
if (strcmp($post->post_type, 'nav_menu_item') === 0) { |
| 22 |
RL21UtilWP::onPostChange(RL21UtilWP::POST_ID_ALL); |
| 23 |
} else { |
| 24 |
RL21UtilWP::onPostChange($post_ID); |
| 25 |
} |
| 26 |
}, 10, 3); |
| 27 |
add_action('wp_insert_post', function ($post_ID, $post, $update) { |
| 28 |
RL21UtilWP::onPostChange($post_ID); |
| 29 |
}, 10, 3); |
| 30 |
add_action('draft_to_publish', function ($post) { |
| 31 |
if (!empty($post)) { |
| 32 |
RL21UtilWP::onPostChange($post->ID); |
| 33 |
} |
| 34 |
}, 10, 1); |
| 35 |
add_action('pending_to_publish', function ($post) { |
| 36 |
if (!empty($post)) { |
| 37 |
RL21UtilWP::onPostChange($post->ID); |
| 38 |
} |
| 39 |
}, 10, 1); |
| 40 |
add_action('transition_post_status', function ($new_status, $old_status, $post) { |
| 41 |
//No need to purge if the post was not public before and its not even now |
| 42 |
if ('publish' !== $old_status && 'publish' !== $new_status) { |
| 43 |
return; |
| 44 |
} |
| 45 |
RL21UtilWP::onPostChange($post->ID); |
| 46 |
}, 10, 3); |
| 47 |
add_action('transition_comment_status', function ($new_status, $old_status, $comment) { |
| 48 |
RL21UtilWP::onPostChange($comment->comment_post_ID); |
| 49 |
}, 10, 3); |
| 50 |
add_action('comment_post', function ($comment_ID, $comment_approved, $commentdata) { |
| 51 |
if ($comment_approved == 1) { |
| 52 |
$comment = get_comment($comment_ID); |
| 53 |
RL21UtilWP::onPostChange($comment->comment_post_ID); |
| 54 |
} |
| 55 |
}, 10, 3); |
| 56 |
|
| 57 |
add_action('switch_theme', function () { |
| 58 |
RL21UtilWP::onPostChange('all'); |
| 59 |
}, 10, 0); |
| 60 |
|
| 61 |
add_action('woocommerce_updated_product_stock', function ($product_id) { |
| 62 |
RL21UtilWP::onPostChange($product_id); |
| 63 |
}, 10, 1); |
| 64 |
add_action('woocommerce_updated_product_price', function ($product_id) { |
| 65 |
RL21UtilWP::onPostChange($product_id); |
| 66 |
}, 10, 1); |
| 67 |
add_action('woocommerce_rest_insert_product', function ($post, $request, $creating) { |
| 68 |
RL21UtilWP::onPostChange($post->ID); |
| 69 |
}, 10, 3); |
| 70 |
add_action('woocommerce_rest_insert_product_object', function ($product, $request, $creating) { |
| 71 |
RL21UtilWP::onPostChange($product->id); |
| 72 |
}, 10, 3); |
| 73 |
add_action('woocommerce_product_object_updated_props', function ($product, $updated) { |
| 74 |
RL21UtilWP::onPostChange($product->get_id()); |
| 75 |
}, 0, 2); |
| 76 |
|
| 77 |
register_shutdown_function(function () { |
| 78 |
RL21UtilWP::execute_purge($count); |
| 79 |
}); |
| 80 |
|
| 81 |
register_activation_hook(__FILE__, function () { |
| 82 |
add_option('rabbitloader_do_activation_redirect', true); |
| 83 |
}); |
| 84 |
|
| 85 |
add_action('admin_enqueue_scripts', function() { |
| 86 |
if ( isset($_GET['page']) && $_GET['page'] === 'rabbitloader' ) { |
| 87 |
wp_dequeue_script('wp-commands'); |
| 88 |
wp_dequeue_script('wp-core-commands'); |
| 89 |
} |
| 90 |
}, 100); |
| 91 |
|
| 92 |
|
| 93 |
add_action('admin_init', 'rabbitloader_activation_redirect'); |
| 94 |
|
| 95 |
function rabbitloader_activation_redirect() { |
| 96 |
// Only redirect if our flag is set |
| 97 |
if (!get_option('rabbitloader_do_activation_redirect')) { |
| 98 |
return; |
| 99 |
} |
| 100 |
|
| 101 |
// Delete the flag so it happens only once |
| 102 |
delete_option('rabbitloader_do_activation_redirect'); |
| 103 |
|
| 104 |
// Prevent redirect on bulk activation |
| 105 |
if (isset($_GET['activate-multi'])) { |
| 106 |
return; |
| 107 |
} |
| 108 |
|
| 109 |
// Redirect to your plugin page |
| 110 |
wp_safe_redirect( |
| 111 |
admin_url('admin.php?page=rabbitloader') |
| 112 |
); |
| 113 |
exit; |
| 114 |
} |
| 115 |
|
| 116 |
if (is_admin()) { |
| 117 |
|
| 118 |
register_activation_hook(__FILE__, 'RabbitLoader_21_Admin::activate_advanced_cache'); |
| 119 |
register_deactivation_hook(__FILE__, 'RabbitLoader_21_Admin::plugin_deactivate'); |
| 120 |
register_uninstall_hook(__FILE__, 'RabbitLoader_21_Admin::plugin_uninstall'); |
| 121 |
add_filter('plugin_action_links_rabbit-loader/rabbit-loader.php', 'RabbitLoader_21_Admin::settings_link'); |
| 122 |
|
| 123 |
if (!defined('RABBITLOADER_UNINSTALL_MODE')) { |
| 124 |
RabbitLoader_21_Admin::addActions(); |
| 125 |
} |
| 126 |
} else { |
| 127 |
if (!defined('RABBITLOADER_AC_ACTIVE')) { |
| 128 |
//advance cache failed to work, as a fallback we can intercept requests here |
| 129 |
RabbitLoader_21_Public::process_incoming_request('fallback'); |
| 130 |
} |
| 131 |
RabbitLoader_21_Public::addActions(); |
| 132 |
} |
| 133 |
|
| 134 |
if (defined("WP_CLI") && WP_CLI) { |
| 135 |
include_once($plug_dir . 'wp-cli.php'); |
| 136 |
} |
| 137 |
|