| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Plugin Name: JCH Optimize |
| 5 |
* Plugin URI: http://www.jch-optimize.net/ |
| 6 |
* Description: Boost your WordPress site's performance with JCH Optimize as measured on PageSpeed |
| 7 |
* Version: 5.1.4 |
| 8 |
* Author: Samuel Marshall |
| 9 |
* License: GNU/GPLv3 |
| 10 |
* Text Domain: jch-optimize |
| 11 |
* Domain Path: /languages |
| 12 |
* Requires PHP: 8.0 |
| 13 |
* Requires at least: 6.5.0 |
| 14 |
*/ |
| 15 |
|
| 16 |
/** |
| 17 |
* JCH Optimize - Performs several front-end optimizations for fast downloads |
| 18 |
* |
| 19 |
* @package jchoptimize/wordpress-platform |
| 20 |
* @author Samuel Marshall <samuel@jch-optimize.net> |
| 21 |
* @copyright Copyright (c) 2020 Samuel Marshall / JCH Optimize |
| 22 |
* @license GNU/GPLv3, or later. See LICENSE file |
| 23 |
* |
| 24 |
* If LICENSE file missing, see <http://www.gnu.org/licenses/>. |
| 25 |
*/ |
| 26 |
|
| 27 |
use JchOptimize\WordPress\Container\ContainerFactory; |
| 28 |
use JchOptimize\WordPress\Plugin\Loader; |
| 29 |
|
| 30 |
if (version_compare(PHP_VERSION, '8.0', 'lt')) { |
| 31 |
function jchoptimize_update_php_message(): void |
| 32 |
{ |
| 33 |
$message = sprintf( |
| 34 |
__( |
| 35 |
'JCH Optimize requires at least PHP 8.0.' |
| 36 |
. ' Your current version is %s. Please update your PHP version or deactivate the plugin.', |
| 37 |
'jch-optimize' |
| 38 |
), |
| 39 |
PHP_VERSION |
| 40 |
); |
| 41 |
echo <<<HTML |
| 42 |
<div class="notice notice-warning is-dismissible"><p>{$message}</p></div> |
| 43 |
HTML; |
| 44 |
} |
| 45 |
|
| 46 |
add_action('admin_notices', 'jchoptimize_update_php_message'); |
| 47 |
|
| 48 |
$mu_folder = ABSPATH . 'wp-content/mu-plugins'; |
| 49 |
if (defined('WPMU_PLUGIN_DIR') && WPMU_PLUGIN_DIR) { |
| 50 |
$mu_folder = WPMU_PLUGIN_DIR; |
| 51 |
} |
| 52 |
|
| 53 |
$mu_plugin = $mu_folder . '/jch-optimize-mode-switcher.php'; |
| 54 |
|
| 55 |
if (file_exists($mu_plugin)) { |
| 56 |
unlink($mu_plugin); |
| 57 |
} |
| 58 |
|
| 59 |
return; |
| 60 |
} |
| 61 |
|
| 62 |
$jch_no_optimize = false; |
| 63 |
|
| 64 |
define('_WP_EXEC', '1'); |
| 65 |
|
| 66 |
define('JCH_PLUGIN_FILE', __FILE__); |
| 67 |
define('JCH_PLUGIN_URL', plugin_dir_url(JCH_PLUGIN_FILE)); |
| 68 |
define('JCH_PLUGIN_DIR', plugin_dir_path(JCH_PLUGIN_FILE)); |
| 69 |
define('JCH_CACHE_DIR', WP_CONTENT_DIR . '/cache/jch-optimize/'); |
| 70 |
define('JCH_CACHE_URL', content_url() . '/cache/jch-optimize/'); |
| 71 |
|
| 72 |
require_once(JCH_PLUGIN_DIR . 'autoload.php'); |
| 73 |
|
| 74 |
try { |
| 75 |
$container = ContainerFactory::getInstance(); |
| 76 |
$loader = $container->get(Loader::class); |
| 77 |
/** |
| 78 |
* Upgrade settings from versions less than 3.0.0 |
| 79 |
*/ |
| 80 |
$loader->preboot_init(); |
| 81 |
/** |
| 82 |
* Initialize and run plugin |
| 83 |
*/ |
| 84 |
$loader->init(); |
| 85 |
} catch (Exception $e) { |
| 86 |
function jchoptimize_initialize_error(): void |
| 87 |
{ |
| 88 |
$message = __( |
| 89 |
'An error occurred while trying to initialize the JCH Optimize plugin.' |
| 90 |
. ' Please deactivate the plugin and report all errors to the developer.', |
| 91 |
'jch-optimize' |
| 92 |
); |
| 93 |
echo <<<HTML |
| 94 |
<div class="notice notice-error is-dismissible"><p>{$message}</p></div> |
| 95 |
HTML; |
| 96 |
} |
| 97 |
|
| 98 |
add_action('admin_notices', 'jchoptimize_initialize_error'); |
| 99 |
|
| 100 |
return; |
| 101 |
} |
| 102 |
|