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