nitropack
Last commit date
classes
3 years ago
languages
3 years ago
nitropack-sdk
3 years ago
view
3 years ago
advanced-cache.php
3 years ago
batcache-compat.php
4 years ago
cf-helper.php
5 years ago
constants.php
3 years ago
diagnostics.php
3 years ago
functions.php
3 years ago
helpers.php
3 years ago
integrations.php
4 years ago
main.php
3 years ago
readme.txt
3 years ago
uninstall.php
4 years ago
wp-cli.php
3 years ago
main.php
213 lines
| 1 | <?php |
| 2 | /* |
| 3 | Plugin Name: NitroPack |
| 4 | Plugin URI: https://nitropack.io/platform/wordpress |
| 5 | Description: Everything you need for a fast website. Simple set up, easy to use, awesome support. Caching, Lazy Loading, Minification, Defer CSS/JS, CDN and more! |
| 6 | Version: 1.6.1 |
| 7 | Author: NitroPack LLC |
| 8 | Author URI: https://nitropack.io/ |
| 9 | License: GPL2 |
| 10 | License URI: https://www.gnu.org/licenses/gpl-2.0.html |
| 11 | Text Domain: nitropack |
| 12 | Domain Path: /languages |
| 13 | */ |
| 14 | |
| 15 | defined( 'ABSPATH' ) or die( 'No script kiddies please!' ); |
| 16 | |
| 17 | $np_basePath = dirname(__FILE__) . '/'; |
| 18 | require_once $np_basePath . 'functions.php'; |
| 19 | require_once $np_basePath . 'helpers.php'; |
| 20 | require_once $np_basePath . 'diagnostics.php'; |
| 21 | |
| 22 | if (nitropack_is_wp_cli()) { |
| 23 | require_once $np_basePath . 'wp-cli.php'; |
| 24 | } |
| 25 | |
| 26 | if ( \NitroPack\Integration\Plugin\Ezoic::isActive() ) { |
| 27 | if (!nitropack_is_optimizer_request()) { |
| 28 | // We need to serve the cached content after Ezoic's output buffering has started at plugins_loaded,0 |
| 29 | add_action( 'plugins_loaded', function() { |
| 30 | add_filter( 'home_url', ['\NitroPack\Integration\Plugin\Ezoic', 'getHomeUrl'] ); |
| 31 | nitropack_handle_request("plugin-ezoic"); |
| 32 | remove_filter( 'home_url', ['\NitroPack\Integration\Plugin\Ezoic', 'getHomeUrl'] ); |
| 33 | }, 1 ); |
| 34 | } else { |
| 35 | add_action( 'plugins_loaded', ['\NitroPack\Integration\Plugin\Ezoic', 'disable'], 1); |
| 36 | } |
| 37 | } else { |
| 38 | nitropack_handle_request("plugin"); |
| 39 | } |
| 40 | |
| 41 | add_filter( 'nitro_script_output', function($script) { |
| 42 | // Make sure we don't accidentally print a non-amp compatible script to an amp page |
| 43 | if (nitropack_is_amp_page()) { |
| 44 | return ""; |
| 45 | } else { |
| 46 | return $script; |
| 47 | } |
| 48 | }); |
| 49 | add_action( 'pre_post_update', 'nitropack_log_post_pre_update', 10, 3); |
| 50 | add_action( 'transition_post_status', 'nitropack_handle_post_transition', 10, 3); |
| 51 | add_action('set_object_terms', 'nitropack_handle_first_publish', 10, 6); |
| 52 | add_action( 'transition_comment_status', 'nitropack_handle_comment_transition', 10, 3); |
| 53 | add_action( 'comment_post', 'nitropack_handle_comment_post', 10, 2); |
| 54 | add_action( 'switch_theme', 'nitropack_theme_handler' ); |
| 55 | register_shutdown_function('nitropack_execute_purges'); |
| 56 | register_shutdown_function('nitropack_execute_invalidations'); |
| 57 | register_shutdown_function('nitropack_execute_warmups'); |
| 58 | |
| 59 | add_action( 'woocommerce_product_object_updated_props', 'nitropack_handle_product_updates', 0, 2); |
| 60 | add_action( 'woocommerce_rest_insert_product', function($post, $request, $creating) { |
| 61 | if (!$creating) { |
| 62 | nitropack_clean_post_cache($post); |
| 63 | } |
| 64 | }, 10, 3); |
| 65 | add_action( 'woocommerce_rest_insert_product_object', function($product, $request, $creating) { |
| 66 | if (!$creating) { |
| 67 | $post = get_post($product->id); |
| 68 | nitropack_clean_post_cache($post); |
| 69 | } |
| 70 | }, 10, 3); |
| 71 | |
| 72 | add_action('wcml_set_client_currency', function($currency) { |
| 73 | setcookie('np_wc_currency', $currency, time() + (86400 * 7), "/"); |
| 74 | }); |
| 75 | |
| 76 | if (nitropack_has_advanced_cache()) { |
| 77 | // Handle automated updates |
| 78 | if (!defined("NITROPACK_ADVANCED_CACHE_VERSION") || NITROPACK_VERSION != NITROPACK_ADVANCED_CACHE_VERSION) { |
| 79 | add_action( 'plugins_loaded', 'nitropack_install_advanced_cache' ); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | add_action('wp_footer', 'nitropack_print_heartbeat_script'); |
| 84 | add_action('admin_footer', 'nitropack_print_heartbeat_script'); |
| 85 | add_action('get_footer', 'nitropack_print_heartbeat_script'); |
| 86 | |
| 87 | add_action('wp_footer', 'nitropack_print_cookie_handler_script'); |
| 88 | add_action('admin_footer', 'nitropack_print_cookie_handler_script'); |
| 89 | add_action('admin_footer', function() { |
| 90 | nitropack_setcookie("nitroCachedPage", 0, time() - 86400); |
| 91 | }); // Clear the nitroCachePage cookie |
| 92 | add_action('get_footer', 'nitropack_print_cookie_handler_script'); |
| 93 | |
| 94 | if ( is_admin() ) { |
| 95 | add_action( 'admin_menu', 'nitropack_menu' ); |
| 96 | add_action( 'admin_init', 'register_nitropack_settings' ); |
| 97 | add_action( 'admin_notices', 'nitropack_admin_notices' ); |
| 98 | add_action( 'network_admin_notices', 'nitropack_admin_notices' ); |
| 99 | add_action( 'wp_ajax_nitropack_purge_cache', 'nitropack_purge_cache' ); |
| 100 | add_action( 'wp_ajax_nitropack_invalidate_cache', 'nitropack_invalidate_cache' ); |
| 101 | add_action( 'wp_ajax_nitropack_clear_residual_cache', 'nitropack_clear_residual_cache' ); |
| 102 | add_action( 'wp_ajax_nitropack_verify_connect', 'nitropack_verify_connect_ajax' ); |
| 103 | add_action( 'wp_ajax_nitropack_disconnect', 'nitropack_disconnect' ); |
| 104 | add_action( 'wp_ajax_nitropack_test_compression_ajax', 'nitropack_test_compression_ajax' ); |
| 105 | add_action( 'wp_ajax_nitropack_set_compression_ajax', 'nitropack_set_compression_ajax' ); |
| 106 | add_action( 'wp_ajax_nitropack_set_auto_cache_purge_ajax', 'nitropack_set_auto_cache_purge_ajax' ); |
| 107 | add_action( 'wp_ajax_nitropack_set_cart_cache_ajax', 'nitropack_set_cart_cache_ajax' ); |
| 108 | add_action( 'wp_ajax_nitropack_set_bb_cache_purge_sync_ajax', 'nitropack_set_bb_cache_purge_sync_ajax' ); |
| 109 | add_action( 'wp_ajax_nitropack_set_cacheable_post_types', 'nitropack_set_cacheable_post_types' ); |
| 110 | add_action( 'wp_ajax_nitropack_enable_warmup', 'nitropack_enable_warmup' ); |
| 111 | add_action( 'wp_ajax_nitropack_disable_warmup', 'nitropack_disable_warmup' ); |
| 112 | add_action( 'wp_ajax_nitropack_warmup_stats', 'nitropack_warmup_stats' ); |
| 113 | add_action( 'wp_ajax_nitropack_estimate_warmup', 'nitropack_estimate_warmup' ); |
| 114 | add_action( 'wp_ajax_nitropack_run_warmup', 'nitropack_run_warmup' ); |
| 115 | add_action( 'wp_ajax_nitropack_purge_single_cache', 'nitropack_purge_single_cache' ); |
| 116 | add_action( 'wp_ajax_nitropack_invalidate_single_cache', 'nitropack_invalidate_single_cache' ); |
| 117 | add_action( 'wp_ajax_nitropack_dismiss_hosting_notice', 'nitropack_dismiss_hosting_notice' ); |
| 118 | add_action( 'wp_ajax_nitropack_dismiss_woocommerce_notice', 'nitropack_dismiss_woocommerce_notice' ); |
| 119 | add_action( 'wp_ajax_nitropack_reconfigure_webhooks', 'nitropack_reconfigure_webhooks' ); |
| 120 | add_action( 'wp_ajax_nitropack_generate_report', 'nitropack_generate_report' );//diag_ajax_hook |
| 121 | add_action( 'wp_ajax_nitropack_enable_safemode', 'nitropack_enable_safemode' ); |
| 122 | add_action( 'wp_ajax_nitropack_disable_safemode', 'nitropack_disable_safemode' ); |
| 123 | add_action( 'wp_ajax_nitropack_safemode_status', 'nitropack_safemode_status' ); |
| 124 | add_action( 'wp_ajax_nitropack_rml_notification', 'nitropack_rml_notification' ); |
| 125 | add_action( 'activated_plugin', 'nitropack_upgrade_handler' ); |
| 126 | add_action( 'deactivated_plugin', 'nitropack_upgrade_handler' ); |
| 127 | add_action( 'upgrader_process_complete', 'nitropack_upgrade_handler'); |
| 128 | add_action( 'update_option_nitropack-enableCompression', 'nitropack_handle_compression_toggle', 10, 2 ); |
| 129 | add_action( 'add_meta_boxes', 'nitropack_add_meta_box' ); |
| 130 | add_action( 'plugins_loaded', 'nitropack_offer_safemode'); |
| 131 | |
| 132 | add_filter('get_nitropack_notifications', 'nitropack_ignore_dismissed_notifications', 10, 2); |
| 133 | |
| 134 | register_activation_hook( __FILE__, 'nitropack_activate' ); |
| 135 | register_deactivation_hook( __FILE__, 'nitropack_deactivate' ); |
| 136 | } else { |
| 137 | if (null !== $nitro = get_nitropack_sdk()) { |
| 138 | $GLOBALS["NitroPack.instance"] = $nitro; |
| 139 | if (get_option('nitropack-enableCompression') == 1) { |
| 140 | $nitro->enableCompression(); |
| 141 | } |
| 142 | add_action( 'wp', 'nitropack_init' ); |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | function nitropack_menu() { |
| 147 | add_options_page( 'NitroPack Options', 'NitroPack', 'manage_options', 'nitropack', 'nitropack_options' ); |
| 148 | add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), 'nitropack_action_links' ); |
| 149 | } |
| 150 | |
| 151 | function nitropack_action_links ( $links ) { |
| 152 | $nitroLinks = array( |
| 153 | '<a href="' . admin_url( 'options-general.php?page=nitropack' ) . '">Settings</a>', |
| 154 | ); |
| 155 | return array_merge( $nitroLinks, $links ); |
| 156 | } |
| 157 | |
| 158 | add_action( 'init', function() { |
| 159 | if (current_user_can( 'manage_options' )) { |
| 160 | |
| 161 | // Enqueue font awesome |
| 162 | add_action( 'wp_enqueue_scripts', 'nitropack_enqueue_load_fa'); |
| 163 | add_action( 'admin_enqueue_scripts', 'nitropack_enqueue_load_fa'); |
| 164 | |
| 165 | // Enqueue admin bar menu custom stylesheet |
| 166 | add_action( 'wp_enqueue_scripts', 'enqueue_nitropack_admin_bar_menu_stylesheet'); |
| 167 | add_action( 'admin_enqueue_scripts', 'enqueue_nitropack_admin_bar_menu_stylesheet'); |
| 168 | |
| 169 | // Enqueue admin menu custom javascript |
| 170 | add_action( 'wp_enqueue_scripts', 'nitropack_admin_bar_script' ); |
| 171 | |
| 172 | // Add our admin menu bar entry |
| 173 | add_action('admin_bar_menu', 'nitropack_admin_bar_menu', 50); |
| 174 | add_action('plugins_loaded', 'nitropack_plugin_notices'); // Run the checks early, because we need to set some headers. The results from the checks will be cached, so future calls will work as expected. |
| 175 | |
| 176 | add_action( 'updated_option', 'nitropack_updated_option', ~PHP_INT_MAX, 3 ); |
| 177 | |
| 178 | \NitroPack\PluginStateHandler::init(); |
| 179 | |
| 180 | add_action( 'admin_enqueue_scripts', function() { |
| 181 | wp_enqueue_script('nitropack_notices_js', plugin_dir_url(__FILE__) . 'view/javascript/np_notices.js?np_v=' . NITROPACK_VERSION); |
| 182 | }); |
| 183 | |
| 184 | add_action('in_admin_header', function() { |
| 185 | $screen = get_current_screen(); |
| 186 | if ($screen->id === 'settings_page_nitropack') { |
| 187 | remove_all_actions( 'user_admin_notices' ); |
| 188 | remove_all_actions( 'admin_notices' ); |
| 189 | remove_all_actions( 'all_admin_notices' ); |
| 190 | } |
| 191 | }, 99); |
| 192 | } |
| 193 | }); |
| 194 | |
| 195 | /** |
| 196 | * Load text domain for translations |
| 197 | * |
| 198 | * @return void |
| 199 | */ |
| 200 | function nitropack_load_textdomain() { |
| 201 | global $l10n; |
| 202 | |
| 203 | $domain = 'nitropack'; |
| 204 | |
| 205 | if ( isset( $l10n[ $domain ] ) ) { |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | load_plugin_textdomain( $domain, false, basename( dirname( __FILE__ ) ) . '/languages/' ); |
| 210 | } |
| 211 | |
| 212 | add_action( 'plugins_loaded','nitropack_load_textdomain' ); |
| 213 |