| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin Name: Autoptimize |
| 4 |
* Plugin URI: https://autoptimize.com/ |
| 5 |
* Description: Makes your site faster by optimizing CSS, JS, Images, Google fonts and more. |
| 6 |
* Version: 2.9.1 |
| 7 |
* Author: Frank Goossens (futtta) |
| 8 |
* Author URI: https://autoptimize.com/ |
| 9 |
* Text Domain: autoptimize |
| 10 |
* License: GPLv2 |
| 11 |
* Released under the GNU General Public License (GPL) |
| 12 |
* https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt |
| 13 |
*/ |
| 14 |
|
| 15 |
/** |
| 16 |
* Autoptimize main plugin file. |
| 17 |
*/ |
| 18 |
|
| 19 |
|
| 20 |
if ( ! defined( 'ABSPATH' ) ) { |
| 21 |
exit; |
| 22 |
} |
| 23 |
|
| 24 |
define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.9.1' ); |
| 25 |
|
| 26 |
// plugin_dir_path() returns the trailing slash! |
| 27 |
define( 'AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
| 28 |
define( 'AUTOPTIMIZE_PLUGIN_FILE', __FILE__ ); |
| 29 |
|
| 30 |
// Bail early if attempting to run on non-supported php versions. |
| 31 |
if ( version_compare( PHP_VERSION, '5.6', '<' ) ) { |
| 32 |
function autoptimize_incompatible_admin_notice() { |
| 33 |
echo '<div class="error"><p>' . __( 'Autoptimize requires PHP 5.6 (or higher) to function properly. Please upgrade PHP. The Plugin has been auto-deactivated.', 'autoptimize' ) . '</p></div>'; |
| 34 |
if ( isset( $_GET['activate'] ) ) { |
| 35 |
unset( $_GET['activate'] ); |
| 36 |
} |
| 37 |
} |
| 38 |
function autoptimize_deactivate_self() { |
| 39 |
deactivate_plugins( plugin_basename( AUTOPTIMIZE_PLUGIN_FILE ) ); |
| 40 |
} |
| 41 |
add_action( 'admin_notices', 'autoptimize_incompatible_admin_notice' ); |
| 42 |
add_action( 'admin_init', 'autoptimize_deactivate_self' ); |
| 43 |
return; |
| 44 |
} |
| 45 |
|
| 46 |
function autoptimize_autoload( $class_name ) { |
| 47 |
if ( in_array( $class_name, array( 'AO_Minify_HTML', 'JSMin' ) ) ) { |
| 48 |
$file = strtolower( $class_name ); |
| 49 |
$file = str_replace( '_', '-', $file ); |
| 50 |
$path = dirname( __FILE__ ) . '/classes/external/php/'; |
| 51 |
$filepath = $path . $file . '.php'; |
| 52 |
} elseif ( false !== strpos( $class_name, 'Autoptimize\\tubalmartin\\CssMin' ) ) { |
| 53 |
$file = str_replace( 'Autoptimize\\tubalmartin\\CssMin\\', '', $class_name ); |
| 54 |
$path = dirname( __FILE__ ) . '/classes/external/php/yui-php-cssmin-bundled/'; |
| 55 |
$filepath = $path . $file . '.php'; |
| 56 |
} elseif ( 'autoptimize' === substr( $class_name, 0, 11 ) ) { |
| 57 |
// One of our "old" classes. |
| 58 |
$file = $class_name; |
| 59 |
$path = dirname( __FILE__ ) . '/classes/'; |
| 60 |
$filepath = $path . $file . '.php'; |
| 61 |
} elseif ( 'PAnD' === $class_name ) { |
| 62 |
$file = 'persist-admin-notices-dismissal'; |
| 63 |
$path = dirname( __FILE__ ) . '/classes/external/php/persist-admin-notices-dismissal/'; |
| 64 |
$filepath = $path . $file . '.php'; |
| 65 |
} |
| 66 |
|
| 67 |
// If we didn't match one of our rules, bail! |
| 68 |
if ( ! isset( $filepath ) ) { |
| 69 |
return; |
| 70 |
} |
| 71 |
|
| 72 |
require $filepath; |
| 73 |
} |
| 74 |
|
| 75 |
spl_autoload_register( 'autoptimize_autoload' ); |
| 76 |
|
| 77 |
// Load WP CLI command(s) on demand. |
| 78 |
if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 79 |
require AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php'; |
| 80 |
} |
| 81 |
|
| 82 |
/** |
| 83 |
* Retrieve the instance of the main plugin class. |
| 84 |
* |
| 85 |
* @return autoptimizeMain |
| 86 |
*/ |
| 87 |
function autoptimize() { |
| 88 |
static $plugin = null; |
| 89 |
|
| 90 |
if ( null === $plugin ) { |
| 91 |
$plugin = new autoptimizeMain( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE ); |
| 92 |
} |
| 93 |
|
| 94 |
return $plugin; |
| 95 |
} |
| 96 |
|
| 97 |
autoptimize()->run(); |
| 98 |
|