| 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.7.0 |
| 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.7.0' ); |
| 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 |
if ( isset( $_SERVER['REQUEST_URI'] ) ) { |
| 145 |
// phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized |
| 146 |
$request_path = explode( '?', wp_unslash( $_SERVER['REQUEST_URI'] ) )[0]; |
| 147 |
|
| 148 |
// Handling JETPACK_BOOST_STATIC_PREFIX constant inline to avoid loading the minify module until we know we want it. |
| 149 |
$static_prefix = defined( 'JETPACK_BOOST_STATIC_PREFIX' ) ? JETPACK_BOOST_STATIC_PREFIX : '/_jb_static/'; |
| 150 |
if ( $static_prefix === substr( $request_path, -strlen( $static_prefix ) ) ) { |
| 151 |
define( 'JETPACK_BOOST_CONCAT_USE_WP', true ); |
| 152 |
|
| 153 |
require_once JETPACK_BOOST_DIR_PATH . '/serve-minified-content.php'; |
| 154 |
exit( 0 ); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
require plugin_dir_path( __FILE__ ) . 'app/class-jetpack-boost.php'; |
| 159 |
|
| 160 |
/** |
| 161 |
* Begins execution of the plugin. |
| 162 |
* |
| 163 |
* @since 0.1.0 |
| 164 |
*/ |
| 165 |
function run_jetpack_boost() { |
| 166 |
new Jetpack_Boost(); |
| 167 |
} |
| 168 |
|
| 169 |
add_action( 'plugins_loaded', '\Automattic\Jetpack_Boost\run_jetpack_boost', 1 ); |
| 170 |
|
| 171 |
register_activation_hook( __FILE__, array( 'Automattic\Jetpack_Boost\Jetpack_Boost', 'activate' ) ); |
| 172 |
|
| 173 |
// Redirect to plugin page when the plugin is activated. |
| 174 |
add_action( 'activated_plugin', __NAMESPACE__ . '\jetpack_boost_plugin_activation' ); |
| 175 |
|
| 176 |
/** |
| 177 |
* Redirects to plugin page when the plugin is activated |
| 178 |
* |
| 179 |
* @access public |
| 180 |
* @static |
| 181 |
* |
| 182 |
* @param string $plugin Path to the plugin file relative to the plugins directory. |
| 183 |
*/ |
| 184 |
function jetpack_boost_plugin_activation( $plugin ) { |
| 185 |
if ( |
| 186 |
JETPACK_BOOST_PLUGIN_BASE === $plugin && |
| 187 |
( new \Automattic\Jetpack\Paths() )->is_current_request_activating_plugin_from_plugins_screen( JETPACK_BOOST_PLUGIN_BASE ) |
| 188 |
) { |
| 189 |
wp_safe_redirect( esc_url( admin_url( 'admin.php?page=jetpack-boost' ) ) ); |
| 190 |
exit( 0 ); |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Extra tweaks to make Jetpack Boost work better with others, that need to be loaded early. |
| 196 |
*/ |
| 197 |
function include_compatibility_files_early() { |
| 198 |
// Since Page Optimize allows its functionality to be disabled on plugins_loaded (10) |
| 199 |
// we need to do this earlier. |
| 200 |
if ( function_exists( 'page_optimize_init' ) ) { |
| 201 |
require_once __DIR__ . '/compatibility/page-optimize.php'; |
| 202 |
} |
| 203 |
} |
| 204 |
|
| 205 |
add_action( 'plugins_loaded', __NAMESPACE__ . '\include_compatibility_files_early', 1 ); |
| 206 |
|
| 207 |
/** |
| 208 |
* Extra tweaks to make Jetpack Boost work better with others. |
| 209 |
*/ |
| 210 |
function include_compatibility_files() { |
| 211 |
if ( class_exists( 'Jetpack' ) ) { |
| 212 |
require_once __DIR__ . '/compatibility/jetpack.php'; |
| 213 |
} |
| 214 |
|
| 215 |
if ( class_exists( 'WooCommerce' ) ) { |
| 216 |
require_once __DIR__ . '/compatibility/woocommerce.php'; |
| 217 |
} |
| 218 |
|
| 219 |
if ( class_exists( '\Google\Web_Stories\Plugin' ) ) { |
| 220 |
require_once __DIR__ . '/compatibility/web-stories.php'; |
| 221 |
} |
| 222 |
|
| 223 |
if ( defined( '\Elementor\TemplateLibrary\Source_Local::CPT' ) || defined( '\Elementor\Modules\LandingPages\Module::CPT' ) || defined( '\Elementor\Modules\FloatingButtons\Module::CPT_FLOATING_BUTTONS' ) ) { |
| 224 |
require_once __DIR__ . '/compatibility/elementor.php'; |
| 225 |
} |
| 226 |
|
| 227 |
if ( function_exists( 'amp_is_request' ) ) { |
| 228 |
require_once __DIR__ . '/compatibility/class-amp.php'; |
| 229 |
} |
| 230 |
|
| 231 |
if ( function_exists( 'wp_cache_is_enabled' ) ) { |
| 232 |
require_once __DIR__ . '/compatibility/wp-super-cache.php'; |
| 233 |
} |
| 234 |
|
| 235 |
if ( class_exists( '\Yoast\WP\SEO\Main' ) ) { |
| 236 |
require_once __DIR__ . '/compatibility/yoast.php'; |
| 237 |
} |
| 238 |
|
| 239 |
if ( function_exists( 'aioseo' ) ) { |
| 240 |
require_once __DIR__ . '/compatibility/aioseo.php'; |
| 241 |
} |
| 242 |
|
| 243 |
// Exclude Beaver Builder custom post types. |
| 244 |
if ( class_exists( 'FLBuilderLoader' ) ) { |
| 245 |
require_once __DIR__ . '/compatibility/beaver-builder.php'; |
| 246 |
} |
| 247 |
|
| 248 |
// Exclude Breakdance custom post types. |
| 249 |
if ( defined( 'BREAKDANCE_ALL_EDITABLE_POST_TYPES' ) ) { |
| 250 |
require_once __DIR__ . '/compatibility/breakdance.php'; |
| 251 |
} |
| 252 |
|
| 253 |
// Compatibility with Divi by Elegant Themes. |
| 254 |
require_once __DIR__ . '/compatibility/divi.php'; |
| 255 |
|
| 256 |
// Exclude known scripts that causes problem when concatenated. |
| 257 |
require_once __DIR__ . '/compatibility/js-concatenate.php'; |
| 258 |
|
| 259 |
// Migrate from WP Super Cache |
| 260 |
require_once __DIR__ . '/compatibility/wp-super-cache-migration.php'; |
| 261 |
|
| 262 |
require_once __DIR__ . '/compatibility/revslider.php'; |
| 263 |
} |
| 264 |
|
| 265 |
add_action( 'plugins_loaded', __NAMESPACE__ . '\include_compatibility_files' ); |
| 266 |
|
| 267 |
register_uninstall_hook( __FILE__, 'Automattic\Jetpack_Boost\jetpack_boost_uninstall' ); |
| 268 |
/** |
| 269 |
* Clean up when uninstalling Jetpack Boost |
| 270 |
*/ |
| 271 |
function jetpack_boost_uninstall() { |
| 272 |
$boost = new Jetpack_Boost(); |
| 273 |
$boost->uninstall(); |
| 274 |
} |
| 275 |
|
| 276 |
/** |
| 277 |
* Initialize Data Sync |
| 278 |
*/ |
| 279 |
require_once __DIR__ . '/wp-js-data-sync.php'; |
| 280 |
|