PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.19.4
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.19.4
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / main.php
nitropack Last commit date
classes 2 months ago languages 4 months ago nitropack-sdk 3 months ago view 2 months ago advanced-cache.php 1 year ago batcache-compat.php 1 year ago constants.php 2 months ago functions.php 2 months ago helpers.php 1 year ago main.php 2 months ago readme.txt 2 months ago uninstall.php 7 months ago
main.php
165 lines
1 <?php
2 /*
3 Plugin Name: NitroPack
4 Plugin URI: https://nitropack.io/platform/wordpress
5 Description: Automatic optimization for site speed and Core Web Vitals. Use 35+ features, including Caching, image optimization, critical CSS, and Cloudflare CDN.
6 Version: 1.19.4
7 Author: NitroPack Inc.
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 if ( ! defined( 'NITROPACK_BASENAME' ) ) {
18 define( 'NITROPACK_BASENAME', plugin_basename( __FILE__ ) );
19 }
20
21 $np_basePath = dirname( __FILE__ ) . '/';
22
23 require_once $np_basePath . 'functions.php';
24 require_once $np_basePath . 'helpers.php';
25
26 new NitroPack\PageSpeedBoost();
27
28 if ( nitropack_is_wp_cli() ) {
29 $nitropack_cli = new \NitroPack\WordPress\CLI();
30 $nitropack_cli->init();
31 }
32
33 if ( \NitroPack\Integration\Plugin\Ezoic::isActive() ) {
34 if ( ! nitropack_is_optimizer_request() ) {
35 // We need to serve the cached content after Ezoic's output buffering has started at plugins_loaded,0
36 add_action( 'plugins_loaded', function () {
37 add_filter( 'home_url', [ '\NitroPack\Integration\Plugin\Ezoic', 'getHomeUrl' ] );
38 nitropack_handle_request( "plugin-ezoic" );
39 remove_filter( 'home_url', [ '\NitroPack\Integration\Plugin\Ezoic', 'getHomeUrl' ] );
40 }, 1 );
41 } else {
42 add_action( 'plugins_loaded', [ '\NitroPack\Integration\Plugin\Ezoic', 'disable' ], 1 );
43 }
44 } else {
45 nitropack_handle_request( "plugin" );
46 }
47
48 add_filter( 'nitro_script_output', function ( $script ) {
49 $isPrefetch = isset( $_SERVER['HTTP_SEC_FETCH_DEST'] )
50 && $_SERVER['HTTP_SEC_FETCH_DEST'] === 'empty'
51 && (
52 ( isset( $_SERVER['HTTP_SEC_PURPOSE'] ) && $_SERVER['HTTP_SEC_PURPOSE'] === 'prefetch' )
53 ||
54 ( isset( $_SERVER['HTTP_PURPOSE'] ) && $_SERVER['HTTP_PURPOSE'] === 'prefetch' )
55 );
56
57 $canPrintScripts = ! nitropack_is_amp_page() // Make sure we don't accidentally print a non-amp compatible script to an amp page
58 && ( ! isset( $_SERVER['HTTP_SEC_FETCH_DEST'] ) || $_SERVER['HTTP_SEC_FETCH_DEST'] === 'document' || $isPrefetch )
59 && ( ! isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) || strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) !== 'xmlhttprequest' );
60
61 if ( $canPrintScripts ) {
62 return $script;
63 } else {
64 return "";
65 }
66 } );
67
68 add_action( 'pre_post_update', 'nitropack_log_post_pre_update', 10, 3 );
69 add_filter( 'woocommerce_rest_pre_insert_product_object', 'nitropack_log_product_pre_api_update', 10, 3 );
70 add_action( 'transition_post_status', 'nitropack_handle_post_transition', 10, 3 );
71 add_action( 'transition_comment_status', 'nitropack_handle_comment_transition', 10, 3 );
72 add_action( 'comment_post', 'nitropack_handle_comment_post', 10, 2 );
73 add_action( 'switch_theme', 'nitropack_theme_handler' );
74 //add invalidations
75 \NitroPack\WordPress\Invalidations::getInstance();
76
77 register_shutdown_function( 'nitropack_execute_purges' );
78 register_shutdown_function( 'nitropack_execute_invalidations' );
79 register_shutdown_function( 'nitropack_execute_warmups' );
80
81
82
83 if ( nitropack_has_advanced_cache() ) {
84 // Handle automated updates
85 if ( ! defined( "NITROPACK_ADVANCED_CACHE_VERSION" ) || NITROPACK_VERSION != NITROPACK_ADVANCED_CACHE_VERSION ) {
86 add_action( 'plugins_loaded', 'nitropack_install_advanced_cache' );
87 }
88 }
89
90 add_action( 'wp_footer', 'nitropack_print_heartbeat_script' );
91 add_action( 'admin_footer', 'nitropack_print_heartbeat_script' );
92 add_action( 'get_footer', 'nitropack_print_heartbeat_script' );
93
94 add_action( 'wp_footer', 'nitropack_print_cookie_handler_script' );
95 add_action( 'admin_footer', 'nitropack_print_cookie_handler_script' );
96 add_action( 'admin_footer', function () {
97 nitropack_setcookie( "nitroCachedPage", 0, time() - 86400 );
98 } ); // Clear the nitroCachePage cookie
99 add_action( 'get_footer', 'nitropack_print_cookie_handler_script' );
100
101 \NitroPack\WordPress\Admin::getInstance();
102
103 if ( is_admin() ) {
104 add_action( 'wp_ajax_nitropack_verify_connect', 'nitropack_verify_connect_ajax' );
105 add_action( 'wp_ajax_nitropack_disconnect', 'nitropack_disconnect' );
106
107 add_action( 'wp_ajax_nitropack_dismiss_hosting_notice', 'nitropack_dismiss_hosting_notice' );
108 add_action( 'wp_ajax_nitropack_reconfigure_webhooks', 'nitropack_reconfigure_webhooks' );
109
110 add_action( 'activated_plugin', 'nitropack_upgrade_handler' );
111 add_action( 'deactivated_plugin', 'nitropack_upgrade_handler' );
112 add_action( 'upgrader_process_complete', 'nitropack_upgrade_handler' );
113 add_action( 'update_option_nitropack-enableCompression', 'nitropack_handle_compression_toggle', 10, 2 );
114
115 } else {
116 if ( null !== $nitro = get_nitropack_sdk() ) {
117 $GLOBALS["NitroPack.instance"] = $nitro;
118 if ( get_option( 'nitropack-enableCompression' ) == 1 ) {
119 $nitro->enableCompression();
120 }
121 add_action( 'wp', 'nitropack_init' );
122 }
123 }
124 /**
125 * This function is called when the plugin is activated/deactivated. Works for wp-cli as well.
126 */
127 register_activation_hook( __FILE__, 'nitropack_activate' );
128 register_deactivation_hook( __FILE__, 'nitropack_deactivate' );
129
130 add_action( 'init', function () {
131 if ( current_user_can( 'manage_options' ) ) {
132
133 \NitroPack\PluginStateHandler::init();
134
135 add_action( 'in_admin_header', function () {
136 $screen = get_current_screen();
137 if ( $screen->id === 'toplevel_page_nitropack' ) {
138 remove_all_actions( 'user_admin_notices' );
139 remove_all_actions( 'admin_notices' );
140 remove_all_actions( 'all_admin_notices' );
141 }
142 }, 10 );
143 }
144 ( new \NitroPack\WordPress\Cron() )->schedule_events();
145 } );
146
147 /**
148 * Load text domain for translations
149 * http://stackoverflow.com/questions/79198701/notice-function-load-textdomain-just-in-time-was-called-incorrectly - for WP 6.7
150 * @return void
151 */
152 function nitropack_load_textdomain() {
153 global $l10n;
154
155 $domain = 'nitropack';
156
157 if ( isset( $l10n[ $domain ] ) ) {
158 return;
159 }
160
161 load_plugin_textdomain( $domain, false, basename( dirname( __FILE__ ) ) . '/languages/' );
162 }
163
164 add_action( 'init', 'nitropack_load_textdomain' );
165