PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / trunk
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization vtrunk
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
assets 2 days ago classes 2 days ago languages 1 month ago nitropack-sdk 2 weeks ago view 2 days ago batcache-compat.php 1 year ago constants.php 2 days ago functions.php 2 days ago helpers.php 1 year ago main.php 2 days ago readme.txt 2 days ago uninstall.php 7 months ago
main.php
153 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.8
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 add_action( 'wp_footer', 'nitropack_print_heartbeat_script' );
82 add_action( 'admin_footer', 'nitropack_print_heartbeat_script' );
83 add_action( 'get_footer', 'nitropack_print_heartbeat_script' );
84
85 add_action( 'wp_footer', 'nitropack_print_cookie_handler_script' );
86 add_action( 'admin_footer', 'nitropack_print_cookie_handler_script' );
87 add_action( 'admin_footer', function () {
88 nitropack_setcookie( "nitroCachedPage", 0, time() - 86400 );
89 } ); // Clear the nitroCachePage cookie
90 add_action( 'get_footer', 'nitropack_print_cookie_handler_script' );
91
92 \NitroPack\WordPress\Admin::getInstance();
93
94 if ( is_admin() ) {
95 add_action( 'wp_ajax_nitropack_dismiss_hosting_notice', 'nitropack_dismiss_hosting_notice' );
96 add_action( 'wp_ajax_nitropack_reconfigure_webhooks', 'nitropack_reconfigure_webhooks' );
97
98 add_action( 'activated_plugin', 'nitropack_upgrade_handler' );
99 add_action( 'deactivated_plugin', 'nitropack_upgrade_handler' );
100 add_action( 'upgrader_process_complete', 'nitropack_upgrade_handler' );
101 add_action( 'update_option_nitropack-enableCompression', 'nitropack_handle_compression_toggle', 10, 2 );
102
103 } else {
104 if ( null !== $nitro = get_nitropack_sdk() ) {
105 $GLOBALS["NitroPack.instance"] = $nitro;
106 if ( get_option( 'nitropack-enableCompression' ) == 1 ) {
107 $nitro->enableCompression();
108 }
109 add_action( 'wp', 'nitropack_init' );
110 }
111 }
112 /**
113 * This function is called when the plugin is activated/deactivated. Works for wp-cli as well.
114 */
115 register_activation_hook( __FILE__, 'nitropack_activate' );
116 register_deactivation_hook( __FILE__, 'nitropack_deactivate' );
117
118 add_action( 'init', function () {
119 if ( current_user_can( 'manage_options' ) ) {
120
121 \NitroPack\PluginStateHandler::init();
122
123 add_action( 'in_admin_header', function () {
124 $screen = get_current_screen();
125 if ( $screen->id === 'toplevel_page_nitropack' ) {
126 remove_all_actions( 'user_admin_notices' );
127 remove_all_actions( 'admin_notices' );
128 remove_all_actions( 'all_admin_notices' );
129 }
130 }, 10 );
131 }
132 ( new \NitroPack\WordPress\Cron() )->schedule_events();
133 } );
134
135 /**
136 * Load text domain for translations
137 * http://stackoverflow.com/questions/79198701/notice-function-load-textdomain-just-in-time-was-called-incorrectly - for WP 6.7
138 * @return void
139 */
140 function nitropack_load_textdomain() {
141 global $l10n;
142
143 $domain = 'nitropack';
144
145 if ( isset( $l10n[ $domain ] ) ) {
146 return;
147 }
148
149 load_plugin_textdomain( $domain, false, basename( dirname( __FILE__ ) ) . '/languages/' );
150 }
151
152 add_action( 'init', 'nitropack_load_textdomain' );
153