PluginProbe
Jetpack Boost – Website Speed, Performance and Critical CSS / 4.6.1
Jetpack Boost – Website Speed, Performance and Critical CSS v4.6.1
4.7.0 4.7.0-beta 4.6.3 4.6.2 4.6.2-beta 3.12.0 3.12.1 3.13.0 3.13.1 3.2.0 3.2.1 3.2.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.6 3.4.7 3.4.8 3.4.9 3.5.0 3.5.1 All 124 releases
jetpack-boost / jetpack-boost.php

jetpack-boost.php in Jetpack Boost – Website Speed, Performance and Critical CSS 4.6.1, at jetpack-boost.php

281 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Jetpack Boost Plugin
4 *
5 * @link https://automattic.com
6 * @since 0.1.0
7 *
8 * @wordpress-plugin
9 * Plugin Name: Jetpack Boost
10 * Plugin URI: https://jetpack.com/boost
11 * Description: Boost your WordPress site's performance, from the creators of Jetpack
12 * Version: 4.6.1
13 * Author: Automattic - Jetpack Site Speed team
14 * Author URI: https://jetpack.com/boost/
15 * License: GPL-2.0+
16 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
17 * Text Domain: jetpack-boost
18 * Domain Path: /languages
19 * Requires at least: 6.9
20 * Requires PHP: 7.2
21 *
22 * @package automattic/jetpack-boost
23 */
24
25 namespace Automattic\Jetpack_Boost;
26
27 // If this file is called directly, abort.
28 if ( ! defined( 'WPINC' ) ) {
29 die( 0 );
30 }
31
32 define( 'JETPACK_BOOST_VERSION', '4.6.1' );
33 define( 'JETPACK_BOOST_SLUG', 'jetpack-boost' );
34
35 if ( ! defined( 'JETPACK_BOOST_CLIENT_NAME' ) ) {
36 define( 'JETPACK_BOOST_CLIENT_NAME', 'jetpack-boost-wp-plugin' );
37 }
38
39 define( 'JETPACK_BOOST_DIR_PATH', __DIR__ );
40 define( 'JETPACK_BOOST_PATH', __FILE__ );
41
42 if ( ! defined( 'JETPACK_BOOST_PLUGIN_BASE' ) ) {
43 define( 'JETPACK_BOOST_PLUGIN_BASE', plugin_basename( __FILE__ ) );
44 }
45
46 if ( ! defined( 'JETPACK_BOOST_PLUGIN_FILENAME' ) ) {
47 define( 'JETPACK_BOOST_PLUGIN_FILENAME', basename( __FILE__ ) );
48 }
49
50 if ( ! defined( 'JETPACK_BOOST_REST_NAMESPACE' ) ) {
51 define( 'JETPACK_BOOST_REST_NAMESPACE', 'jetpack-boost/v1' );
52 }
53
54 // For use in situations where you want additional namespacing.
55 if ( ! defined( 'JETPACK_BOOST_REST_PREFIX' ) ) {
56 define( 'JETPACK_BOOST_REST_PREFIX', '' );
57 }
58
59 if ( ! defined( 'JETPACK__WPCOM_JSON_API_BASE' ) ) {
60 define( 'JETPACK__WPCOM_JSON_API_BASE', 'https://public-api.wordpress.com' );
61 }
62
63 if ( ! defined( 'JETPACK_BOOST_PLUGINS_DIR_URL' ) ) {
64 define( 'JETPACK_BOOST_PLUGINS_DIR_URL', plugin_dir_url( __FILE__ ) );
65 }
66
67 /**
68 * Setup autoloading
69 */
70 $boost_packages_path = JETPACK_BOOST_DIR_PATH . '/vendor/autoload_packages.php';
71 if ( is_readable( $boost_packages_path ) ) {
72 require_once $boost_packages_path;
73 if ( method_exists( \Automattic\Jetpack\Assets::class, 'alias_textdomains_from_file' ) ) {
74 \Automattic\Jetpack\Assets::alias_textdomains_from_file( JETPACK_BOOST_DIR_PATH . '/jetpack_vendor/i18n-map.php' );
75 }
76 } else {
77 if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
78 /** @noinspection ForgottenDebugOutputInspection */
79 error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
80 sprintf(
81 /* translators: Placeholder is a link to a support document. */
82 __( 'Your installation of Jetpack Boost is incomplete. If you installed Jetpack Boost from GitHub, please refer to this document to set up your development environment: %1$s', 'jetpack-boost' ),
83 'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md'
84 )
85 );
86 }
87
88 // Add a red bubble notification to My Jetpack if the installation is bad.
89 add_filter(
90 'my_jetpack_red_bubble_notification_slugs',
91 function ( $slugs ) {
92 $slugs['jetpack-boost-plugin-bad-installation'] = array(
93 'data' => array(
94 'plugin' => 'Jetpack Boost',
95 ),
96 );
97
98 return $slugs;
99 }
100 );
101
102 /**
103 * Outputs an admin notice for folks running Jetpack Boost without having run composer install.
104 *
105 * @since 1.2.0
106 */
107 function jetpack_boost_admin_missing_files() {
108 if ( get_current_screen()->id !== 'plugins' ) {
109 return;
110 }
111 $message = sprintf(
112 wp_kses(
113 /* translators: Placeholder is a link to a support document. */
114 __( 'Your installation of Jetpack Boost is incomplete. If you installed Jetpack Boost from GitHub, please refer to <a href="%1$s" target="_blank" rel="noopener noreferrer">this document</a> to set up your development environment. Jetpack Boost must have Composer dependencies installed and built via the build command.', 'jetpack-boost' ),
115 array(
116 'a' => array(
117 'href' => array(),
118 'target' => array(),
119 'rel' => array(),
120 ),
121 )
122 ),
123 'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
124 );
125 wp_admin_notice(
126 $message,
127 array(
128 'type' => 'error',
129 'dismissible' => true,
130 )
131 );
132 }
133
134 add_action( 'admin_notices', __NAMESPACE__ . '\\jetpack_boost_admin_missing_files' );
135 return;
136 }
137
138 /**
139 * Setup Minify service.
140 */
141 require_once JETPACK_BOOST_DIR_PATH . '/app/lib/minify/loader.php';
142
143 // Potential improvement: Make concat URL dir configurable
144 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
145 if ( isset( $_SERVER['REQUEST_URI'] ) ) {
146 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
147 $request_path = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) )[0];
148
149 // Handling JETPACK_BOOST_STATIC_PREFIX constant inline to avoid loading the minify module until we know we want it.
150 $static_prefix = defined( 'JETPACK_BOOST_STATIC_PREFIX' ) ? JETPACK_BOOST_STATIC_PREFIX : '/_jb_static/';
151 if ( $static_prefix === substr( $request_path, -strlen( $static_prefix ) ) ) {
152 define( 'JETPACK_BOOST_CONCAT_USE_WP', true );
153
154 require_once JETPACK_BOOST_DIR_PATH . '/serve-minified-content.php';
155 exit( 0 );
156 }
157 }
158
159 require plugin_dir_path( __FILE__ ) . 'app/class-jetpack-boost.php';
160
161 /**
162 * Begins execution of the plugin.
163 *
164 * @since 0.1.0
165 */
166 function run_jetpack_boost() {
167 new Jetpack_Boost();
168 }
169
170 add_action( 'plugins_loaded', '\Automattic\Jetpack_Boost\run_jetpack_boost', 1 );
171
172 register_activation_hook( __FILE__, array( 'Automattic\Jetpack_Boost\Jetpack_Boost', 'activate' ) );
173
174 // Redirect to plugin page when the plugin is activated.
175 add_action( 'activated_plugin', __NAMESPACE__ . '\jetpack_boost_plugin_activation' );
176
177 /**
178 * Redirects to plugin page when the plugin is activated
179 *
180 * @access public
181 * @static
182 *
183 * @param string $plugin Path to the plugin file relative to the plugins directory.
184 */
185 function jetpack_boost_plugin_activation( $plugin ) {
186 if (
187 JETPACK_BOOST_PLUGIN_BASE === $plugin &&
188 ( new \Automattic\Jetpack\Paths() )->is_current_request_activating_plugin_from_plugins_screen( JETPACK_BOOST_PLUGIN_BASE )
189 ) {
190 wp_safe_redirect( esc_url( admin_url( 'admin.php?page=jetpack-boost' ) ) );
191 exit( 0 );
192 }
193 }
194
195 /**
196 * Extra tweaks to make Jetpack Boost work better with others, that need to be loaded early.
197 */
198 function include_compatibility_files_early() {
199 // Since Page Optimize allows its functionality to be disabled on plugins_loaded (10)
200 // we need to do this earlier.
201 if ( function_exists( 'page_optimize_init' ) ) {
202 require_once __DIR__ . '/compatibility/page-optimize.php';
203 }
204 }
205
206 add_action( 'plugins_loaded', __NAMESPACE__ . '\include_compatibility_files_early', 1 );
207
208 /**
209 * Extra tweaks to make Jetpack Boost work better with others.
210 */
211 function include_compatibility_files() {
212 if ( class_exists( 'Jetpack' ) ) {
213 require_once __DIR__ . '/compatibility/jetpack.php';
214 }
215
216 if ( class_exists( 'WooCommerce' ) ) {
217 require_once __DIR__ . '/compatibility/woocommerce.php';
218 }
219
220 if ( class_exists( '\Google\Web_Stories\Plugin' ) ) {
221 require_once __DIR__ . '/compatibility/web-stories.php';
222 }
223
224 if ( defined( '\Elementor\TemplateLibrary\Source_Local::CPT' ) || defined( '\Elementor\Modules\LandingPages\Module::CPT' ) || defined( '\Elementor\Modules\FloatingButtons\Module::CPT_FLOATING_BUTTONS' ) ) {
225 require_once __DIR__ . '/compatibility/elementor.php';
226 }
227
228 if ( function_exists( 'amp_is_request' ) ) {
229 require_once __DIR__ . '/compatibility/class-amp.php';
230 }
231
232 if ( function_exists( 'wp_cache_is_enabled' ) ) {
233 require_once __DIR__ . '/compatibility/wp-super-cache.php';
234 }
235
236 if ( class_exists( '\Yoast\WP\SEO\Main' ) ) {
237 require_once __DIR__ . '/compatibility/yoast.php';
238 }
239
240 if ( function_exists( 'aioseo' ) ) {
241 require_once __DIR__ . '/compatibility/aioseo.php';
242 }
243
244 // Exclude Beaver Builder custom post types.
245 if ( class_exists( 'FLBuilderLoader' ) ) {
246 require_once __DIR__ . '/compatibility/beaver-builder.php';
247 }
248
249 // Exclude Breakdance custom post types.
250 if ( defined( 'BREAKDANCE_ALL_EDITABLE_POST_TYPES' ) ) {
251 require_once __DIR__ . '/compatibility/breakdance.php';
252 }
253
254 // Compatibility with Divi by Elegant Themes.
255 require_once __DIR__ . '/compatibility/divi.php';
256
257 // Exclude known scripts that causes problem when concatenated.
258 require_once __DIR__ . '/compatibility/js-concatenate.php';
259
260 // Migrate from WP Super Cache
261 require_once __DIR__ . '/compatibility/wp-super-cache-migration.php';
262
263 require_once __DIR__ . '/compatibility/revslider.php';
264 }
265
266 add_action( 'plugins_loaded', __NAMESPACE__ . '\include_compatibility_files' );
267
268 register_uninstall_hook( __FILE__, 'Automattic\Jetpack_Boost\jetpack_boost_uninstall' );
269 /**
270 * Clean up when uninstalling Jetpack Boost
271 */
272 function jetpack_boost_uninstall() {
273 $boost = new Jetpack_Boost();
274 $boost->uninstall();
275 }
276
277 /**
278 * Initialize Data Sync
279 */
280 require_once __DIR__ . '/wp-js-data-sync.php';
281