@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Handles version updates and should only be instantiated in autoptimize.php if/when needed. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 6 | +if (!defined('ABSPATH')) { |
|
| 7 | 7 | exit; |
| 8 | 8 | } |
| 9 | 9 | |
@@ -16,9 +16,9 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | protected $current_major_version = null; |
| 18 | 18 | |
| 19 | - public function __construct( $current_version ) |
|
| 19 | + public function __construct($current_version) |
|
| 20 | 20 | { |
| 21 | - $this->current_major_version = substr( $current_version, 0, 3 ); |
|
| 21 | + $this->current_major_version = substr($current_version, 0, 3); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | { |
| 30 | 30 | $major_update = false; |
| 31 | 31 | |
| 32 | - switch ( $this->current_major_version ) { |
|
| 32 | + switch ($this->current_major_version) { |
|
| 33 | 33 | case '1.6': |
| 34 | 34 | $this->upgrade_from_1_6(); |
| 35 | 35 | $major_update = true; |
@@ -47,14 +47,14 @@ discard block |
||
| 47 | 47 | $major_update = true; |
| 48 | 48 | // No break, intentionally, so all upgrades are ran during a single request... |
| 49 | 49 | case '2.4': |
| 50 | - if ( get_option( 'autoptimize_version', 'none' ) == '2.4.2' ) { |
|
| 50 | + if (get_option('autoptimize_version', 'none') == '2.4.2') { |
|
| 51 | 51 | $this->upgrade_from_2_4_2(); |
| 52 | 52 | } |
| 53 | 53 | $major_update = false; |
| 54 | 54 | // No break, intentionally, so all upgrades are ran during a single request... |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - if ( true === $major_update ) { |
|
| 57 | + if (true === $major_update) { |
|
| 58 | 58 | $this->on_major_version_update(); |
| 59 | 59 | } |
| 60 | 60 | } |
@@ -66,19 +66,19 @@ discard block |
||
| 66 | 66 | * |
| 67 | 67 | * @param string $target Target version to check against (ie., the currently running one). |
| 68 | 68 | */ |
| 69 | - public static function check_installed_and_update( $target ) |
|
| 69 | + public static function check_installed_and_update($target) |
|
| 70 | 70 | { |
| 71 | - $db_version = get_option( 'autoptimize_version', 'none' ); |
|
| 72 | - if ( $db_version !== $target ) { |
|
| 73 | - if ( 'none' === $db_version ) { |
|
| 74 | - add_action( 'admin_notices', 'autoptimizeMain::notice_installed' ); |
|
| 71 | + $db_version = get_option('autoptimize_version', 'none'); |
|
| 72 | + if ($db_version !== $target) { |
|
| 73 | + if ('none' === $db_version) { |
|
| 74 | + add_action('admin_notices', 'autoptimizeMain::notice_installed'); |
|
| 75 | 75 | } else { |
| 76 | - $updater = new self( $db_version ); |
|
| 76 | + $updater = new self($db_version); |
|
| 77 | 77 | $updater->run_needed_major_upgrades(); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Versions differed, upgrades happened if needed, store the new version. |
| 81 | - update_option( 'autoptimize_version', $target ); |
|
| 81 | + update_option('autoptimize_version', $target); |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | |
@@ -89,10 +89,10 @@ discard block |
||
| 89 | 89 | protected function on_major_version_update() |
| 90 | 90 | { |
| 91 | 91 | // The transients guard here prevents stale object caches from busting the cache on every request. |
| 92 | - if ( false == get_transient( 'autoptimize_stale_option_buster' ) ) { |
|
| 93 | - set_transient( 'autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS ); |
|
| 92 | + if (false == get_transient('autoptimize_stale_option_buster')) { |
|
| 93 | + set_transient('autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS); |
|
| 94 | 94 | autoptimizeCache::clearall(); |
| 95 | - add_action( 'admin_notices', 'autoptimizeMain::notice_updated' ); |
|
| 95 | + add_action('admin_notices', 'autoptimizeMain::notice_updated'); |
|
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | 98 | |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | private function upgrade_from_1_6() |
| 103 | 103 | { |
| 104 | 104 | // If user was on version 1.6.x, force advanced options to be shown by default. |
| 105 | - update_option( 'autoptimize_show_adv', '1' ); |
|
| 105 | + update_option('autoptimize_show_adv', '1'); |
|
| 106 | 106 | |
| 107 | 107 | // And remove old options. |
| 108 | 108 | $to_delete_options = array( |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | 'autoptimize_cdn_img_url', |
| 115 | 115 | 'autoptimize_css_yui', |
| 116 | 116 | ); |
| 117 | - foreach ( $to_delete_options as $del_opt ) { |
|
| 118 | - delete_option( $del_opt ); |
|
| 117 | + foreach ($to_delete_options as $del_opt) { |
|
| 118 | + delete_option($del_opt); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
@@ -126,29 +126,29 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | private function upgrade_from_1_7() |
| 128 | 128 | { |
| 129 | - if ( ! is_multisite() ) { |
|
| 130 | - $css_exclude = get_option( 'autoptimize_css_exclude' ); |
|
| 131 | - if ( empty( $css_exclude ) ) { |
|
| 129 | + if (!is_multisite()) { |
|
| 130 | + $css_exclude = get_option('autoptimize_css_exclude'); |
|
| 131 | + if (empty($css_exclude)) { |
|
| 132 | 132 | $css_exclude = 'admin-bar.min.css, dashicons.min.css'; |
| 133 | - } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) { |
|
| 133 | + } elseif (false === strpos($css_exclude, 'dashicons.min.css')) { |
|
| 134 | 134 | $css_exclude .= ', dashicons.min.css'; |
| 135 | 135 | } |
| 136 | - update_option( 'autoptimize_css_exclude', $css_exclude ); |
|
| 136 | + update_option('autoptimize_css_exclude', $css_exclude); |
|
| 137 | 137 | } else { |
| 138 | 138 | global $wpdb; |
| 139 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
| 139 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
| 140 | 140 | $original_blog_id = get_current_blog_id(); |
| 141 | - foreach ( $blog_ids as $blog_id ) { |
|
| 142 | - switch_to_blog( $blog_id ); |
|
| 143 | - $css_exclude = get_option( 'autoptimize_css_exclude' ); |
|
| 144 | - if ( empty( $css_exclude ) ) { |
|
| 141 | + foreach ($blog_ids as $blog_id) { |
|
| 142 | + switch_to_blog($blog_id); |
|
| 143 | + $css_exclude = get_option('autoptimize_css_exclude'); |
|
| 144 | + if (empty($css_exclude)) { |
|
| 145 | 145 | $css_exclude = 'admin-bar.min.css, dashicons.min.css'; |
| 146 | - } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) { |
|
| 146 | + } elseif (false === strpos($css_exclude, 'dashicons.min.css')) { |
|
| 147 | 147 | $css_exclude .= ', dashicons.min.css'; |
| 148 | 148 | } |
| 149 | - update_option( 'autoptimize_css_exclude', $css_exclude ); |
|
| 149 | + update_option('autoptimize_css_exclude', $css_exclude); |
|
| 150 | 150 | } |
| 151 | - switch_to_blog( $original_blog_id ); |
|
| 151 | + switch_to_blog($original_blog_id); |
|
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | |
@@ -160,19 +160,19 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | private function upgrade_from_1_9() |
| 162 | 162 | { |
| 163 | - if ( ! is_multisite() ) { |
|
| 164 | - update_option( 'autoptimize_css_include_inline', 'on' ); |
|
| 165 | - update_option( 'autoptimize_js_include_inline', 'on' ); |
|
| 163 | + if (!is_multisite()) { |
|
| 164 | + update_option('autoptimize_css_include_inline', 'on'); |
|
| 165 | + update_option('autoptimize_js_include_inline', 'on'); |
|
| 166 | 166 | } else { |
| 167 | 167 | global $wpdb; |
| 168 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
| 168 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
| 169 | 169 | $original_blog_id = get_current_blog_id(); |
| 170 | - foreach ( $blog_ids as $blog_id ) { |
|
| 171 | - switch_to_blog( $blog_id ); |
|
| 172 | - update_option( 'autoptimize_css_include_inline', 'on' ); |
|
| 173 | - update_option( 'autoptimize_js_include_inline', 'on' ); |
|
| 170 | + foreach ($blog_ids as $blog_id) { |
|
| 171 | + switch_to_blog($blog_id); |
|
| 172 | + update_option('autoptimize_css_include_inline', 'on'); |
|
| 173 | + update_option('autoptimize_js_include_inline', 'on'); |
|
| 174 | 174 | } |
| 175 | - switch_to_blog( $original_blog_id ); |
|
| 175 | + switch_to_blog($original_blog_id); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
@@ -183,17 +183,17 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | private function upgrade_from_2_2() |
| 185 | 185 | { |
| 186 | - if ( ! is_multisite() ) { |
|
| 186 | + if (!is_multisite()) { |
|
| 187 | 187 | $this->do_2_2_settings_update(); |
| 188 | 188 | } else { |
| 189 | 189 | global $wpdb; |
| 190 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
| 190 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
| 191 | 191 | $original_blog_id = get_current_blog_id(); |
| 192 | - foreach ( $blog_ids as $blog_id ) { |
|
| 193 | - switch_to_blog( $blog_id ); |
|
| 192 | + foreach ($blog_ids as $blog_id) { |
|
| 193 | + switch_to_blog($blog_id); |
|
| 194 | 194 | $this->do_2_2_settings_update(); |
| 195 | 195 | } |
| 196 | - switch_to_blog( $original_blog_id ); |
|
| 196 | + switch_to_blog($original_blog_id); |
|
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
@@ -202,18 +202,18 @@ discard block |
||
| 202 | 202 | */ |
| 203 | 203 | private function do_2_2_settings_update() |
| 204 | 204 | { |
| 205 | - $nogooglefont = get_option( 'autoptimize_css_nogooglefont', '' ); |
|
| 206 | - $ao_extrasetting = get_option( 'autoptimize_extra_settings', '' ); |
|
| 207 | - if ( ( $nogooglefont ) && ( empty( $ao_extrasetting ) ) ) { |
|
| 208 | - update_option( 'autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options() ); |
|
| 205 | + $nogooglefont = get_option('autoptimize_css_nogooglefont', ''); |
|
| 206 | + $ao_extrasetting = get_option('autoptimize_extra_settings', ''); |
|
| 207 | + if (($nogooglefont) && (empty($ao_extrasetting))) { |
|
| 208 | + update_option('autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options()); |
|
| 209 | 209 | } |
| 210 | - delete_option( 'autoptimize_css_nogooglefont' ); |
|
| 210 | + delete_option('autoptimize_css_nogooglefont'); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
| 214 | 214 | * 2.4.2 introduced too many cronned ao_cachecheckers, make this right |
| 215 | 215 | */ |
| 216 | 216 | private function upgrade_from_2_4_2() { |
| 217 | - wp_clear_scheduled_hook( 'ao_cachechecker' ); |
|
| 217 | + wp_clear_scheduled_hook('ao_cachechecker'); |
|
| 218 | 218 | } |
| 219 | 219 | } |
@@ -6,7 +6,7 @@ discard block |
||
| 6 | 6 | * Checks if cachesize is > 0.5GB (size is filterable), if so, an option is set which controls showing an admin notice. |
| 7 | 7 | */ |
| 8 | 8 | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 9 | +if (!defined('ABSPATH')) { |
|
| 10 | 10 | exit; |
| 11 | 11 | } |
| 12 | 12 | |
@@ -25,51 +25,51 @@ discard block |
||
| 25 | 25 | |
| 26 | 26 | public function add_hooks() |
| 27 | 27 | { |
| 28 | - if ( is_admin() ) { |
|
| 29 | - add_action( 'plugins_loaded', array( $this, 'setup' ) ); |
|
| 28 | + if (is_admin()) { |
|
| 29 | + add_action('plugins_loaded', array($this, 'setup')); |
|
| 30 | 30 | } |
| 31 | - add_action( self::SCHEDULE_HOOK, array( $this, 'cronjob' ) ); |
|
| 32 | - add_action( 'admin_notices', array( $this, 'show_admin_notice' ) ); |
|
| 31 | + add_action(self::SCHEDULE_HOOK, array($this, 'cronjob')); |
|
| 32 | + add_action('admin_notices', array($this, 'show_admin_notice')); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | public function setup() |
| 36 | 36 | { |
| 37 | - $do_cache_check = (bool) apply_filters( 'autoptimize_filter_cachecheck_do', true ); |
|
| 38 | - $schedule = wp_get_schedule( self::SCHEDULE_HOOK ); |
|
| 39 | - $frequency = apply_filters( 'autoptimize_filter_cachecheck_frequency', 'twicedaily' ); |
|
| 40 | - if ( ! in_array( $frequency, array( 'hourly', 'twicedaily', 'daily', 'weekly', 'monthly' ) ) ) { |
|
| 37 | + $do_cache_check = (bool) apply_filters('autoptimize_filter_cachecheck_do', true); |
|
| 38 | + $schedule = wp_get_schedule(self::SCHEDULE_HOOK); |
|
| 39 | + $frequency = apply_filters('autoptimize_filter_cachecheck_frequency', 'twicedaily'); |
|
| 40 | + if (!in_array($frequency, array('hourly', 'twicedaily', 'daily', 'weekly', 'monthly'))) { |
|
| 41 | 41 | $frequency = 'twicedaily'; |
| 42 | 42 | } |
| 43 | - if ( $do_cache_check && ( ! $schedule || $schedule !== $frequency ) ) { |
|
| 44 | - if ( $schedule ) { |
|
| 45 | - wp_clear_scheduled_hook( self::SCHEDULE_HOOK ); |
|
| 43 | + if ($do_cache_check && (!$schedule || $schedule !== $frequency)) { |
|
| 44 | + if ($schedule) { |
|
| 45 | + wp_clear_scheduled_hook(self::SCHEDULE_HOOK); |
|
| 46 | 46 | } |
| 47 | - wp_schedule_event( time(), $frequency, self::SCHEDULE_HOOK ); |
|
| 48 | - } elseif ( $schedule && ! $do_cache_check ) { |
|
| 49 | - wp_clear_scheduled_hook( self::SCHEDULE_HOOK ); |
|
| 47 | + wp_schedule_event(time(), $frequency, self::SCHEDULE_HOOK); |
|
| 48 | + } elseif ($schedule && !$do_cache_check) { |
|
| 49 | + wp_clear_scheduled_hook(self::SCHEDULE_HOOK); |
|
| 50 | 50 | } |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | public function cronjob() |
| 54 | 54 | { |
| 55 | 55 | // Check cachesize and act accordingly. |
| 56 | - $max_size = (int) apply_filters( 'autoptimize_filter_cachecheck_maxsize', 536870912 ); |
|
| 57 | - $do_cache_check = (bool) apply_filters( 'autoptimize_filter_cachecheck_do', true ); |
|
| 56 | + $max_size = (int) apply_filters('autoptimize_filter_cachecheck_maxsize', 536870912); |
|
| 57 | + $do_cache_check = (bool) apply_filters('autoptimize_filter_cachecheck_do', true); |
|
| 58 | 58 | $stat_array = autoptimizeCache::stats(); |
| 59 | - $cache_size = round( $stat_array[1] ); |
|
| 60 | - if ( ( $cache_size > $max_size ) && ( $do_cache_check ) ) { |
|
| 61 | - update_option( 'autoptimize_cachesize_notice', true ); |
|
| 62 | - if ( apply_filters( 'autoptimize_filter_cachecheck_sendmail', true ) ) { |
|
| 63 | - $site_url = esc_url( site_url() ); |
|
| 64 | - $ao_mailto = apply_filters( 'autoptimize_filter_cachecheck_mailto', get_option( 'admin_email', '' ) ); |
|
| 65 | - |
|
| 66 | - $ao_mailsubject = __( 'Autoptimize cache size warning', 'autoptimize' ) . ' (' . $site_url . ')'; |
|
| 67 | - $ao_mailbody = __( 'Autoptimize\'s cache size is getting big, consider purging the cache. Have a look at https://wordpress.org/plugins/autoptimize/faq/ to see how you can keep the cache size under control.', 'autoptimize' ) . ' (site: ' . $site_url . ')'; |
|
| 68 | - |
|
| 69 | - if ( ! empty( $ao_mailto ) ) { |
|
| 70 | - $ao_mailresult = wp_mail( $ao_mailto, $ao_mailsubject, $ao_mailbody ); |
|
| 71 | - if ( ! $ao_mailresult ) { |
|
| 72 | - error_log( 'Autoptimize could not send cache size warning mail.' ); |
|
| 59 | + $cache_size = round($stat_array[1]); |
|
| 60 | + if (($cache_size > $max_size) && ($do_cache_check)) { |
|
| 61 | + update_option('autoptimize_cachesize_notice', true); |
|
| 62 | + if (apply_filters('autoptimize_filter_cachecheck_sendmail', true)) { |
|
| 63 | + $site_url = esc_url(site_url()); |
|
| 64 | + $ao_mailto = apply_filters('autoptimize_filter_cachecheck_mailto', get_option('admin_email', '')); |
|
| 65 | + |
|
| 66 | + $ao_mailsubject = __('Autoptimize cache size warning', 'autoptimize').' ('.$site_url.')'; |
|
| 67 | + $ao_mailbody = __('Autoptimize\'s cache size is getting big, consider purging the cache. Have a look at https://wordpress.org/plugins/autoptimize/faq/ to see how you can keep the cache size under control.', 'autoptimize').' (site: '.$site_url.')'; |
|
| 68 | + |
|
| 69 | + if (!empty($ao_mailto)) { |
|
| 70 | + $ao_mailresult = wp_mail($ao_mailto, $ao_mailsubject, $ao_mailbody); |
|
| 71 | + if (!$ao_mailresult) { |
|
| 72 | + error_log('Autoptimize could not send cache size warning mail.'); |
|
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | } |
@@ -87,16 +87,16 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | public function show_admin_notice() |
| 89 | 89 | { |
| 90 | - if ( (bool) get_option( 'autoptimize_cachesize_notice', false ) && current_user_can( 'manage_options' ) ) { |
|
| 90 | + if ((bool) get_option('autoptimize_cachesize_notice', false) && current_user_can('manage_options')) { |
|
| 91 | 91 | echo '<div class="notice notice-warning"><p>'; |
| 92 | - _e( '<strong>Autoptimize\'s cache size is getting big</strong>, consider purging the cache. Have a look at <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank" rel="noopener noreferrer">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize' ); |
|
| 92 | + _e('<strong>Autoptimize\'s cache size is getting big</strong>, consider purging the cache. Have a look at <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank" rel="noopener noreferrer">the Autoptimize FAQ</a> to see how you can keep the cache size under control.', 'autoptimize'); |
|
| 93 | 93 | echo '</p></div>'; |
| 94 | - update_option( 'autoptimize_cachesize_notice', false ); |
|
| 94 | + update_option('autoptimize_cachesize_notice', false); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | // Notice for image proxy usage. |
| 98 | 98 | $_imgopt_notice = autoptimizeExtra::get_imgopt_status_notice_wrapper(); |
| 99 | - if ( current_user_can( 'manage_options' ) && is_array( $_imgopt_notice ) && array_key_exists( 'status', $_imgopt_notice ) && in_array( $_imgopt_notice['status'], array( 1, -1, -2 ) ) ) { |
|
| 99 | + if (current_user_can('manage_options') && is_array($_imgopt_notice) && array_key_exists('status', $_imgopt_notice) && in_array($_imgopt_notice['status'], array(1, -1, -2))) { |
|
| 100 | 100 | $_dismissible = 'ao-img-opt-notice-'; |
| 101 | 101 | $_hide_notice = '7'; |
| 102 | 102 | |
@@ -104,10 +104,10 @@ discard block |
||
| 104 | 104 | $_hide_notice = '1'; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - $_imgopt_notice_dismissible = apply_filters( 'autoptimize_filter_imgopt_notice_dismissable', $_dismissible . $_hide_notice ); |
|
| 107 | + $_imgopt_notice_dismissible = apply_filters('autoptimize_filter_imgopt_notice_dismissable', $_dismissible.$_hide_notice); |
|
| 108 | 108 | |
| 109 | - if ( $_imgopt_notice && PAnD::is_admin_notice_active( $_imgopt_notice_dismissible ) ) { |
|
| 110 | - echo '<div class="notice notice-warning is-dismissible" data-dismissible="' . $_imgopt_notice_dismissible . '"><p>' . $_imgopt_notice['notice'] . '</p></div>'; |
|
| 109 | + if ($_imgopt_notice && PAnD::is_admin_notice_active($_imgopt_notice_dismissible)) { |
|
| 110 | + echo '<div class="notice notice-warning is-dismissible" data-dismissible="'.$_imgopt_notice_dismissible.'"><p>'.$_imgopt_notice['notice'].'</p></div>'; |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -16,66 +16,66 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | |
| 19 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 19 | +if (!defined('ABSPATH')) { |
|
| 20 | 20 | exit; |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | -define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.4.3' ); |
|
| 23 | +define('AUTOPTIMIZE_PLUGIN_VERSION', '2.4.3'); |
|
| 24 | 24 | |
| 25 | 25 | // plugin_dir_path() returns the trailing slash! |
| 26 | -define( 'AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); |
|
| 27 | -define( 'AUTOPTIMIZE_PLUGIN_FILE', __FILE__ ); |
|
| 26 | +define('AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path(__FILE__)); |
|
| 27 | +define('AUTOPTIMIZE_PLUGIN_FILE', __FILE__); |
|
| 28 | 28 | |
| 29 | 29 | // Bail early if attempting to run on non-supported php versions. |
| 30 | -if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { |
|
| 30 | +if (version_compare(PHP_VERSION, '5.3', '<')) { |
|
| 31 | 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'] ); |
|
| 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 | 35 | } |
| 36 | 36 | } |
| 37 | 37 | function autoptimize_deactivate_self() { |
| 38 | - deactivate_plugins( plugin_basename( AUTOPTIMIZE_PLUGIN_FILE ) ); |
|
| 38 | + deactivate_plugins(plugin_basename(AUTOPTIMIZE_PLUGIN_FILE)); |
|
| 39 | 39 | } |
| 40 | - add_action( 'admin_notices', 'autoptimize_incompatible_admin_notice' ); |
|
| 41 | - add_action( 'admin_init', 'autoptimize_deactivate_self' ); |
|
| 40 | + add_action('admin_notices', 'autoptimize_incompatible_admin_notice'); |
|
| 41 | + add_action('admin_init', 'autoptimize_deactivate_self'); |
|
| 42 | 42 | return; |
| 43 | 43 | } |
| 44 | 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 ) ) { |
|
| 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 | 56 | // One of our "old" classes. |
| 57 | 57 | $file = $class_name; |
| 58 | - $path = dirname( __FILE__ ) . '/classes/'; |
|
| 59 | - $filepath = $path . $file . '.php'; |
|
| 60 | - } elseif ( 'PAnD' === $class_name ) { |
|
| 58 | + $path = dirname(__FILE__).'/classes/'; |
|
| 59 | + $filepath = $path.$file.'.php'; |
|
| 60 | + } elseif ('PAnD' === $class_name) { |
|
| 61 | 61 | $file = 'persist-admin-notices-dismissal'; |
| 62 | - $path = dirname( __FILE__ ) . '/classes/external/php/persist-admin-notices-dismissal/'; |
|
| 63 | - $filepath = $path . $file . '.php'; |
|
| 62 | + $path = dirname(__FILE__).'/classes/external/php/persist-admin-notices-dismissal/'; |
|
| 63 | + $filepath = $path.$file.'.php'; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // If we didn't match one of our rules, bail! |
| 67 | - if ( ! isset( $filepath ) ) { |
|
| 67 | + if (!isset($filepath)) { |
|
| 68 | 68 | return; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | require $filepath; |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | -spl_autoload_register( 'autoptimize_autoload' ); |
|
| 74 | +spl_autoload_register('autoptimize_autoload'); |
|
| 75 | 75 | |
| 76 | 76 | // Load WP CLI command(s) on demand. |
| 77 | -if ( defined( 'WP_CLI' ) && WP_CLI ) { |
|
| 78 | - require AUTOPTIMIZE_PLUGIN_DIR . 'classes/autoptimizeCLI.php'; |
|
| 77 | +if (defined('WP_CLI') && WP_CLI) { |
|
| 78 | + require AUTOPTIMIZE_PLUGIN_DIR.'classes/autoptimizeCLI.php'; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | function autoptimize() { |
| 87 | 87 | static $plugin = null; |
| 88 | 88 | |
| 89 | - if ( null === $plugin ) { |
|
| 90 | - $plugin = new autoptimizeMain( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE ); |
|
| 89 | + if (null === $plugin) { |
|
| 90 | + $plugin = new autoptimizeMain(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE); |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | return $plugin; |