@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Wraps base plugin logic/hooks and handles activation/deactivation/uninstall. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 6 | +if (!defined('ABSPATH')) { |
|
| 7 | 7 | exit; |
| 8 | 8 | } |
| 9 | 9 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | * @param string $version Version. |
| 34 | 34 | * @param string $filepath Filepath. Needed for activation/deactivation/uninstall hooks. |
| 35 | 35 | */ |
| 36 | - public function __construct( $version, $filepath ) |
|
| 36 | + public function __construct($version, $filepath) |
|
| 37 | 37 | { |
| 38 | 38 | $this->version = $version; |
| 39 | 39 | $this->filepath = $filepath; |
@@ -50,94 +50,94 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | protected function add_hooks() |
| 52 | 52 | { |
| 53 | - add_action( 'plugins_loaded', array( $this, 'setup' ) ); |
|
| 53 | + add_action('plugins_loaded', array($this, 'setup')); |
|
| 54 | 54 | |
| 55 | - add_action( 'autoptimize_setup_done', array( $this, 'version_upgrades_check' ) ); |
|
| 56 | - add_action( 'autoptimize_setup_done', array( $this, 'check_cache_and_run' ) ); |
|
| 57 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_ao_extra' ) ); |
|
| 58 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_partners_tab' ) ); |
|
| 55 | + add_action('autoptimize_setup_done', array($this, 'version_upgrades_check')); |
|
| 56 | + add_action('autoptimize_setup_done', array($this, 'check_cache_and_run')); |
|
| 57 | + add_action('autoptimize_setup_done', array($this, 'maybe_run_ao_extra')); |
|
| 58 | + add_action('autoptimize_setup_done', array($this, 'maybe_run_partners_tab')); |
|
| 59 | 59 | |
| 60 | - add_action( 'init', array( $this, 'load_textdomain' ) ); |
|
| 61 | - add_action( 'plugins_loaded', array( $this, 'hook_page_cache_purge' ) ); |
|
| 62 | - add_action( 'admin_init', array( 'PAnD', 'init' ) ); |
|
| 60 | + add_action('init', array($this, 'load_textdomain')); |
|
| 61 | + add_action('plugins_loaded', array($this, 'hook_page_cache_purge')); |
|
| 62 | + add_action('admin_init', array('PAnD', 'init')); |
|
| 63 | 63 | |
| 64 | - register_activation_hook( $this->filepath, array( $this, 'on_activate' ) ); |
|
| 64 | + register_activation_hook($this->filepath, array($this, 'on_activate')); |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | public function on_activate() |
| 68 | 68 | { |
| 69 | - register_uninstall_hook( $this->filepath, 'autoptimizeMain::on_uninstall' ); |
|
| 69 | + register_uninstall_hook($this->filepath, 'autoptimizeMain::on_uninstall'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | public function load_textdomain() |
| 73 | 73 | { |
| 74 | - load_plugin_textdomain( 'autoptimize' ); |
|
| 74 | + load_plugin_textdomain('autoptimize'); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | public function setup() |
| 78 | 78 | { |
| 79 | 79 | // Do we gzip in php when caching or is the webserver doing it? |
| 80 | - define( 'AUTOPTIMIZE_CACHE_NOGZIP', (bool) get_option( 'autoptimize_cache_nogzip' ) ); |
|
| 80 | + define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) get_option('autoptimize_cache_nogzip')); |
|
| 81 | 81 | |
| 82 | 82 | // These can be overridden by specifying them in wp-config.php or such. |
| 83 | - if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_NAME' ) ) { |
|
| 84 | - define( 'AUTOPTIMIZE_WP_CONTENT_NAME', '/' . wp_basename( WP_CONTENT_DIR ) ); |
|
| 83 | + if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) { |
|
| 84 | + define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR)); |
|
| 85 | 85 | } |
| 86 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_CHILD_DIR' ) ) { |
|
| 87 | - define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/' ); |
|
| 86 | + if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) { |
|
| 87 | + define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/'); |
|
| 88 | 88 | } |
| 89 | - if ( ! defined( 'AUTOPTIMIZE_CACHEFILE_PREFIX' ) ) { |
|
| 90 | - define( 'AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_' ); |
|
| 89 | + if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) { |
|
| 90 | + define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_'); |
|
| 91 | 91 | } |
| 92 | 92 | // Note: trailing slash is not optional! |
| 93 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) { |
|
| 94 | - define( 'AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname() ); |
|
| 93 | + if (!defined('AUTOPTIMIZE_CACHE_DIR')) { |
|
| 94 | + define('AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname()); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - define( 'WP_ROOT_DIR', substr( WP_CONTENT_DIR, 0, strlen( WP_CONTENT_DIR ) - strlen( AUTOPTIMIZE_WP_CONTENT_NAME ) ) ); |
|
| 97 | + define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME))); |
|
| 98 | 98 | |
| 99 | - if ( ! defined( 'AUTOPTIMIZE_WP_SITE_URL' ) ) { |
|
| 100 | - if ( function_exists( 'domain_mapping_siteurl' ) ) { |
|
| 101 | - define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) ); |
|
| 99 | + if (!defined('AUTOPTIMIZE_WP_SITE_URL')) { |
|
| 100 | + if (function_exists('domain_mapping_siteurl')) { |
|
| 101 | + define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id())); |
|
| 102 | 102 | } else { |
| 103 | - define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() ); |
|
| 103 | + define('AUTOPTIMIZE_WP_SITE_URL', site_url()); |
|
| 104 | 104 | } |
| 105 | 105 | } |
| 106 | - if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_URL' ) ) { |
|
| 107 | - if ( function_exists( 'domain_mapping_siteurl' ) ) { |
|
| 108 | - define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) ); |
|
| 106 | + if (!defined('AUTOPTIMIZE_WP_CONTENT_URL')) { |
|
| 107 | + if (function_exists('domain_mapping_siteurl')) { |
|
| 108 | + define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url())); |
|
| 109 | 109 | } else { |
| 110 | - define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() ); |
|
| 110 | + define('AUTOPTIMIZE_WP_CONTENT_URL', content_url()); |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_URL' ) ) { |
|
| 114 | - if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) { |
|
| 113 | + if (!defined('AUTOPTIMIZE_CACHE_URL')) { |
|
| 114 | + if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) { |
|
| 115 | 115 | $blog_id = get_current_blog_id(); |
| 116 | - define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR . $blog_id . '/' ); |
|
| 116 | + define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/'); |
|
| 117 | 117 | } else { |
| 118 | - define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR ); |
|
| 118 | + define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | - if ( ! defined( 'AUTOPTIMIZE_WP_ROOT_URL' ) ) { |
|
| 122 | - define( 'AUTOPTIMIZE_WP_ROOT_URL', str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL ) ); |
|
| 121 | + if (!defined('AUTOPTIMIZE_WP_ROOT_URL')) { |
|
| 122 | + define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL)); |
|
| 123 | 123 | } |
| 124 | - if ( ! defined( 'AUTOPTIMIZE_HASH' ) ) { |
|
| 125 | - define( 'AUTOPTIMIZE_HASH', wp_hash( AUTOPTIMIZE_CACHE_URL ) ); |
|
| 124 | + if (!defined('AUTOPTIMIZE_HASH')) { |
|
| 125 | + define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_URL)); |
|
| 126 | 126 | } |
| 127 | - if ( ! defined( 'AUTOPTIMIZE_SITE_DOMAIN' ) ) { |
|
| 128 | - define( 'AUTOPTIMIZE_SITE_DOMAIN', parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ); |
|
| 127 | + if (!defined('AUTOPTIMIZE_SITE_DOMAIN')) { |
|
| 128 | + define('AUTOPTIMIZE_SITE_DOMAIN', parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Multibyte-capable string replacements are available with a filter. |
| 132 | 132 | // Also requires 'mbstring' extension. |
| 133 | - $with_mbstring = apply_filters( 'autoptimize_filter_with_mbstring', false ); |
|
| 134 | - if ( $with_mbstring ) { |
|
| 135 | - autoptimizeUtils::mbstring_available( \extensions_loaded( 'mbstring' ) ); |
|
| 133 | + $with_mbstring = apply_filters('autoptimize_filter_with_mbstring', false); |
|
| 134 | + if ($with_mbstring) { |
|
| 135 | + autoptimizeUtils::mbstring_available(\extensions_loaded('mbstring')); |
|
| 136 | 136 | } else { |
| 137 | - autoptimizeUtils::mbstring_available( false ); |
|
| 137 | + autoptimizeUtils::mbstring_available(false); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - do_action( 'autoptimize_setup_done' ); |
|
| 140 | + do_action('autoptimize_setup_done'); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -147,52 +147,52 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | public function version_upgrades_check() |
| 149 | 149 | { |
| 150 | - autoptimizeVersionUpdatesHandler::check_installed_and_update( $this->version ); |
|
| 150 | + autoptimizeVersionUpdatesHandler::check_installed_and_update($this->version); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | public function check_cache_and_run() |
| 154 | 154 | { |
| 155 | - if ( autoptimizeCache::cacheavail() ) { |
|
| 155 | + if (autoptimizeCache::cacheavail()) { |
|
| 156 | 156 | $conf = autoptimizeConfig::instance(); |
| 157 | - if ( $conf->get( 'autoptimize_html' ) || $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) ) { |
|
| 157 | + if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css')) { |
|
| 158 | 158 | // Hook into WordPress frontend. |
| 159 | - if ( defined( 'AUTOPTIMIZE_INIT_EARLIER' ) ) { |
|
| 159 | + if (defined('AUTOPTIMIZE_INIT_EARLIER')) { |
|
| 160 | 160 | add_action( |
| 161 | 161 | 'init', |
| 162 | - array( $this, 'start_buffering' ), |
|
| 162 | + array($this, 'start_buffering'), |
|
| 163 | 163 | self::INIT_EARLIER_PRIORITY |
| 164 | 164 | ); |
| 165 | 165 | } else { |
| 166 | - if ( ! defined( 'AUTOPTIMIZE_HOOK_INTO' ) ) { |
|
| 167 | - define( 'AUTOPTIMIZE_HOOK_INTO', 'template_redirect' ); |
|
| 166 | + if (!defined('AUTOPTIMIZE_HOOK_INTO')) { |
|
| 167 | + define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect'); |
|
| 168 | 168 | } |
| 169 | 169 | add_action( |
| 170 | - constant( 'AUTOPTIMIZE_HOOK_INTO' ), |
|
| 171 | - array( $this, 'start_buffering' ), |
|
| 170 | + constant('AUTOPTIMIZE_HOOK_INTO'), |
|
| 171 | + array($this, 'start_buffering'), |
|
| 172 | 172 | self::DEFAULT_HOOK_PRIORITY |
| 173 | 173 | ); |
| 174 | 174 | } |
| 175 | 175 | } |
| 176 | 176 | } else { |
| 177 | - add_action( 'admin_notices', 'autoptimizeMain::notice_cache_unavailable' ); |
|
| 177 | + add_action('admin_notices', 'autoptimizeMain::notice_cache_unavailable'); |
|
| 178 | 178 | } |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | public function maybe_run_ao_extra() |
| 182 | 182 | { |
| 183 | - if ( apply_filters( 'autoptimize_filter_extra_activate', true ) ) { |
|
| 183 | + if (apply_filters('autoptimize_filter_extra_activate', true)) { |
|
| 184 | 184 | $ao_extra = new autoptimizeExtra(); |
| 185 | 185 | $ao_extra->run(); |
| 186 | 186 | |
| 187 | 187 | // And show the imgopt notice. |
| 188 | - add_action( 'admin_notices', 'autoptimizeMain::notice_plug_imgopt' ); |
|
| 188 | + add_action('admin_notices', 'autoptimizeMain::notice_plug_imgopt'); |
|
| 189 | 189 | } |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | public function maybe_run_partners_tab() |
| 193 | 193 | { |
| 194 | 194 | // Loads partners tab code if in admin (and not in admin-ajax.php)! |
| 195 | - if ( autoptimizeConfig::is_admin_and_not_ajax() ) { |
|
| 195 | + if (autoptimizeConfig::is_admin_and_not_ajax()) { |
|
| 196 | 196 | new autoptimizePartners(); |
| 197 | 197 | } |
| 198 | 198 | } |
@@ -200,7 +200,7 @@ discard block |
||
| 200 | 200 | public function hook_page_cache_purge() |
| 201 | 201 | { |
| 202 | 202 | // hook into a collection of page cache purge actions if filter allows. |
| 203 | - if ( apply_filters( 'autoptimize_filter_main_hookpagecachepurge', true ) ) { |
|
| 203 | + if (apply_filters('autoptimize_filter_main_hookpagecachepurge', true)) { |
|
| 204 | 204 | $page_cache_purge_actions = array( |
| 205 | 205 | 'after_rocket_clean_domain', // exists. |
| 206 | 206 | 'hyper_cache_purged', // Stefano confirmed this will be added. |
@@ -212,9 +212,9 @@ discard block |
||
| 212 | 212 | 'wpfc_delete_cache', // Emre confirmed this will be added this. |
| 213 | 213 | 'swift_performance_after_clear_all_cache', // swift perf. yeah! |
| 214 | 214 | ); |
| 215 | - $page_cache_purge_actions = apply_filters( 'autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions ); |
|
| 216 | - foreach ( $page_cache_purge_actions as $purge_action ) { |
|
| 217 | - add_action( $purge_action, 'autoptimizeCache::clearall_actionless' ); |
|
| 215 | + $page_cache_purge_actions = apply_filters('autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions); |
|
| 216 | + foreach ($page_cache_purge_actions as $purge_action) { |
|
| 217 | + add_action($purge_action, 'autoptimizeCache::clearall_actionless'); |
|
| 218 | 218 | } |
| 219 | 219 | } |
| 220 | 220 | } |
@@ -226,38 +226,38 @@ discard block |
||
| 226 | 226 | */ |
| 227 | 227 | public function start_buffering() |
| 228 | 228 | { |
| 229 | - if ( $this->should_buffer() ) { |
|
| 229 | + if ($this->should_buffer()) { |
|
| 230 | 230 | |
| 231 | 231 | // Load speedupper conditionally (true by default). |
| 232 | - if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) { |
|
| 232 | + if (apply_filters('autoptimize_filter_speedupper', true)) { |
|
| 233 | 233 | $ao_speedupper = new autoptimizeSpeedupper(); |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | $conf = autoptimizeConfig::instance(); |
| 237 | 237 | |
| 238 | - if ( $conf->get( 'autoptimize_js' ) ) { |
|
| 239 | - if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) { |
|
| 240 | - define( 'CONCATENATE_SCRIPTS', false ); |
|
| 238 | + if ($conf->get('autoptimize_js')) { |
|
| 239 | + if (!defined('CONCATENATE_SCRIPTS')) { |
|
| 240 | + define('CONCATENATE_SCRIPTS', false); |
|
| 241 | 241 | } |
| 242 | - if ( ! defined( 'COMPRESS_SCRIPTS' ) ) { |
|
| 243 | - define( 'COMPRESS_SCRIPTS', false ); |
|
| 242 | + if (!defined('COMPRESS_SCRIPTS')) { |
|
| 243 | + define('COMPRESS_SCRIPTS', false); |
|
| 244 | 244 | } |
| 245 | 245 | } |
| 246 | 246 | |
| 247 | - if ( $conf->get( 'autoptimize_css' ) ) { |
|
| 248 | - if ( ! defined( 'COMPRESS_CSS' ) ) { |
|
| 249 | - define( 'COMPRESS_CSS', false ); |
|
| 247 | + if ($conf->get('autoptimize_css')) { |
|
| 248 | + if (!defined('COMPRESS_CSS')) { |
|
| 249 | + define('COMPRESS_CSS', false); |
|
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - if ( apply_filters( 'autoptimize_filter_obkiller', false ) ) { |
|
| 254 | - while ( ob_get_level() > 0 ) { |
|
| 253 | + if (apply_filters('autoptimize_filter_obkiller', false)) { |
|
| 254 | + while (ob_get_level() > 0) { |
|
| 255 | 255 | ob_end_clean(); |
| 256 | 256 | } |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | // Now, start the real thing! |
| 260 | - ob_start( array( $this, 'end_buffering' ) ); |
|
| 260 | + ob_start(array($this, 'end_buffering')); |
|
| 261 | 261 | } |
| 262 | 262 | } |
| 263 | 263 | |
@@ -268,31 +268,31 @@ discard block |
||
| 268 | 268 | * deciding once per request (for use in tests). |
| 269 | 269 | * @return bool |
| 270 | 270 | */ |
| 271 | - public function should_buffer( $doing_tests = false ) |
|
| 271 | + public function should_buffer($doing_tests = false) |
|
| 272 | 272 | { |
| 273 | 273 | static $do_buffering = null; |
| 274 | 274 | |
| 275 | 275 | // Only check once in case we're called multiple times by others but |
| 276 | 276 | // still allows multiple calls when doing tests. |
| 277 | - if ( null === $do_buffering || $doing_tests ) { |
|
| 277 | + if (null === $do_buffering || $doing_tests) { |
|
| 278 | 278 | |
| 279 | 279 | $ao_noptimize = false; |
| 280 | 280 | |
| 281 | 281 | // Checking for DONOTMINIFY constant as used by e.g. WooCommerce POS. |
| 282 | - if ( defined( 'DONOTMINIFY' ) && ( constant( 'DONOTMINIFY' ) === true || constant( 'DONOTMINIFY' ) === 'true' ) ) { |
|
| 282 | + if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === 'true')) { |
|
| 283 | 283 | $ao_noptimize = true; |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | // Skip checking query strings if they're disabled. |
| 287 | - if ( apply_filters( 'autoptimize_filter_honor_qs_noptimize', true ) ) { |
|
| 287 | + if (apply_filters('autoptimize_filter_honor_qs_noptimize', true)) { |
|
| 288 | 288 | // Check for `ao_noptimize` (and other) keys in the query string |
| 289 | 289 | // to get non-optimized page for debugging. |
| 290 | 290 | $keys = array( |
| 291 | 291 | 'ao_noptimize', |
| 292 | 292 | 'ao_noptirocket', |
| 293 | 293 | ); |
| 294 | - foreach ( $keys as $key ) { |
|
| 295 | - if ( array_key_exists( $key, $_GET ) && '1' === $_GET[ $key ] ) { |
|
| 294 | + foreach ($keys as $key) { |
|
| 295 | + if (array_key_exists($key, $_GET) && '1' === $_GET[$key]) { |
|
| 296 | 296 | $ao_noptimize = true; |
| 297 | 297 | break; |
| 298 | 298 | } |
@@ -300,15 +300,15 @@ discard block |
||
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | // If setting says not to optimize logged in user and user is logged in... |
| 303 | - if ( 'on' !== get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) { |
|
| 303 | + if ('on' !== get_option('autoptimize_optimize_logged', 'on') && is_user_logged_in() && current_user_can('edit_posts')) { |
|
| 304 | 304 | $ao_noptimize = true; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // If setting says not to optimize cart/checkout. |
| 308 | - if ( 'on' !== get_option( 'autoptimize_optimize_checkout', 'on' ) ) { |
|
| 308 | + if ('on' !== get_option('autoptimize_optimize_checkout', 'on')) { |
|
| 309 | 309 | // Checking for woocommerce, easy digital downloads and wp ecommerce... |
| 310 | - foreach ( array( 'is_checkout', 'is_cart', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) { |
|
| 311 | - if ( function_exists( $func ) && $func() ) { |
|
| 310 | + foreach (array('is_checkout', 'is_cart', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout') as $func) { |
|
| 311 | + if (function_exists($func) && $func()) { |
|
| 312 | 312 | $ao_noptimize = true; |
| 313 | 313 | break; |
| 314 | 314 | } |
@@ -316,11 +316,11 @@ discard block |
||
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | // Allows blocking of autoptimization on your own terms regardless of above decisions. |
| 319 | - $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize ); |
|
| 319 | + $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize); |
|
| 320 | 320 | |
| 321 | 321 | // Check for site being previewed in the Customizer (available since WP 4.0). |
| 322 | 322 | $is_customize_preview = false; |
| 323 | - if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) { |
|
| 323 | + if (function_exists('is_customize_preview') && is_customize_preview()) { |
|
| 324 | 324 | $is_customize_preview = is_customize_preview(); |
| 325 | 325 | } |
| 326 | 326 | |
@@ -331,7 +331,7 @@ discard block |
||
| 331 | 331 | * while the main query hasn't been ran yet. Thats why we use |
| 332 | 332 | * AUTOPTIMIZE_INIT_EARLIER in tests. |
| 333 | 333 | */ |
| 334 | - $do_buffering = ( ! is_admin() && ! is_feed() && ! $ao_noptimize && ! $is_customize_preview ); |
|
| 334 | + $do_buffering = (!is_admin() && !is_feed() && !$ao_noptimize && !$is_customize_preview); |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | return $do_buffering; |
@@ -344,24 +344,24 @@ discard block |
||
| 344 | 344 | * |
| 345 | 345 | * @return bool |
| 346 | 346 | */ |
| 347 | - public function is_valid_buffer( $content ) |
|
| 347 | + public function is_valid_buffer($content) |
|
| 348 | 348 | { |
| 349 | 349 | // Defaults to true. |
| 350 | 350 | $valid = true; |
| 351 | 351 | |
| 352 | - $has_no_html_tag = ( false === stripos( $content, '<html' ) ); |
|
| 353 | - $has_xsl_stylesheet = ( false !== stripos( $content, '<xsl:stylesheet' ) ); |
|
| 354 | - $has_html5_doctype = ( preg_match( '/^<!DOCTYPE.+html>/i', $content ) > 0 ); |
|
| 352 | + $has_no_html_tag = (false === stripos($content, '<html')); |
|
| 353 | + $has_xsl_stylesheet = (false !== stripos($content, '<xsl:stylesheet')); |
|
| 354 | + $has_html5_doctype = (preg_match('/^<!DOCTYPE.+html>/i', $content) > 0); |
|
| 355 | 355 | |
| 356 | - if ( $has_no_html_tag ) { |
|
| 356 | + if ($has_no_html_tag) { |
|
| 357 | 357 | // Can't be valid amp markup without an html tag preceding it. |
| 358 | 358 | $is_amp_markup = false; |
| 359 | 359 | } else { |
| 360 | - $is_amp_markup = self::is_amp_markup( $content ); |
|
| 360 | + $is_amp_markup = self::is_amp_markup($content); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | // If it's not html, or if it's amp or contains xsl stylesheets we don't touch it. |
| 364 | - if ( $has_no_html_tag && ! $has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet ) { |
|
| 364 | + if ($has_no_html_tag && !$has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet) { |
|
| 365 | 365 | $valid = false; |
| 366 | 366 | } |
| 367 | 367 | |
@@ -376,9 +376,9 @@ discard block |
||
| 376 | 376 | * |
| 377 | 377 | * @return bool |
| 378 | 378 | */ |
| 379 | - public static function is_amp_markup( $content ) |
|
| 379 | + public static function is_amp_markup($content) |
|
| 380 | 380 | { |
| 381 | - $is_amp_markup = preg_match( '/<html[^>]*(?:amp|⚡)/i', $content ); |
|
| 381 | + $is_amp_markup = preg_match('/<html[^>]*(?:amp|⚡)/i', $content); |
|
| 382 | 382 | |
| 383 | 383 | return (bool) $is_amp_markup; |
| 384 | 384 | } |
@@ -391,10 +391,10 @@ discard block |
||
| 391 | 391 | * |
| 392 | 392 | * @return string |
| 393 | 393 | */ |
| 394 | - public function end_buffering( $content ) |
|
| 394 | + public function end_buffering($content) |
|
| 395 | 395 | { |
| 396 | 396 | // Bail early without modifying anything if we can't handle the content. |
| 397 | - if ( ! $this->is_valid_buffer( $content ) ) { |
|
| 397 | + if (!$this->is_valid_buffer($content)) { |
|
| 398 | 398 | return $content; |
| 399 | 399 | } |
| 400 | 400 | |
@@ -402,57 +402,57 @@ discard block |
||
| 402 | 402 | |
| 403 | 403 | // Determine what needs to be ran. |
| 404 | 404 | $classes = array(); |
| 405 | - if ( $conf->get( 'autoptimize_js' ) ) { |
|
| 405 | + if ($conf->get('autoptimize_js')) { |
|
| 406 | 406 | $classes[] = 'autoptimizeScripts'; |
| 407 | 407 | } |
| 408 | - if ( $conf->get( 'autoptimize_css' ) ) { |
|
| 408 | + if ($conf->get('autoptimize_css')) { |
|
| 409 | 409 | $classes[] = 'autoptimizeStyles'; |
| 410 | 410 | } |
| 411 | - if ( $conf->get( 'autoptimize_html' ) ) { |
|
| 411 | + if ($conf->get('autoptimize_html')) { |
|
| 412 | 412 | $classes[] = 'autoptimizeHTML'; |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | $classoptions = array( |
| 416 | 416 | 'autoptimizeScripts' => array( |
| 417 | - 'aggregate' => $conf->get( 'autoptimize_js_aggregate' ), |
|
| 418 | - 'justhead' => $conf->get( 'autoptimize_js_justhead' ), |
|
| 419 | - 'forcehead' => $conf->get( 'autoptimize_js_forcehead' ), |
|
| 420 | - 'trycatch' => $conf->get( 'autoptimize_js_trycatch' ), |
|
| 421 | - 'js_exclude' => $conf->get( 'autoptimize_js_exclude' ), |
|
| 422 | - 'cdn_url' => $conf->get( 'autoptimize_cdn_url' ), |
|
| 423 | - 'include_inline' => $conf->get( 'autoptimize_js_include_inline' ), |
|
| 417 | + 'aggregate' => $conf->get('autoptimize_js_aggregate'), |
|
| 418 | + 'justhead' => $conf->get('autoptimize_js_justhead'), |
|
| 419 | + 'forcehead' => $conf->get('autoptimize_js_forcehead'), |
|
| 420 | + 'trycatch' => $conf->get('autoptimize_js_trycatch'), |
|
| 421 | + 'js_exclude' => $conf->get('autoptimize_js_exclude'), |
|
| 422 | + 'cdn_url' => $conf->get('autoptimize_cdn_url'), |
|
| 423 | + 'include_inline' => $conf->get('autoptimize_js_include_inline'), |
|
| 424 | 424 | ), |
| 425 | 425 | 'autoptimizeStyles' => array( |
| 426 | - 'aggregate' => $conf->get( 'autoptimize_css_aggregate' ), |
|
| 427 | - 'justhead' => $conf->get( 'autoptimize_css_justhead' ), |
|
| 428 | - 'datauris' => $conf->get( 'autoptimize_css_datauris' ), |
|
| 429 | - 'defer' => $conf->get( 'autoptimize_css_defer' ), |
|
| 430 | - 'defer_inline' => $conf->get( 'autoptimize_css_defer_inline' ), |
|
| 431 | - 'inline' => $conf->get( 'autoptimize_css_inline' ), |
|
| 432 | - 'css_exclude' => $conf->get( 'autoptimize_css_exclude' ), |
|
| 433 | - 'cdn_url' => $conf->get( 'autoptimize_cdn_url' ), |
|
| 434 | - 'include_inline' => $conf->get( 'autoptimize_css_include_inline' ), |
|
| 435 | - 'nogooglefont' => $conf->get( 'autoptimize_css_nogooglefont' ), |
|
| 426 | + 'aggregate' => $conf->get('autoptimize_css_aggregate'), |
|
| 427 | + 'justhead' => $conf->get('autoptimize_css_justhead'), |
|
| 428 | + 'datauris' => $conf->get('autoptimize_css_datauris'), |
|
| 429 | + 'defer' => $conf->get('autoptimize_css_defer'), |
|
| 430 | + 'defer_inline' => $conf->get('autoptimize_css_defer_inline'), |
|
| 431 | + 'inline' => $conf->get('autoptimize_css_inline'), |
|
| 432 | + 'css_exclude' => $conf->get('autoptimize_css_exclude'), |
|
| 433 | + 'cdn_url' => $conf->get('autoptimize_cdn_url'), |
|
| 434 | + 'include_inline' => $conf->get('autoptimize_css_include_inline'), |
|
| 435 | + 'nogooglefont' => $conf->get('autoptimize_css_nogooglefont'), |
|
| 436 | 436 | ), |
| 437 | 437 | 'autoptimizeHTML' => array( |
| 438 | - 'keepcomments' => $conf->get( 'autoptimize_html_keepcomments' ), |
|
| 438 | + 'keepcomments' => $conf->get('autoptimize_html_keepcomments'), |
|
| 439 | 439 | ), |
| 440 | 440 | ); |
| 441 | 441 | |
| 442 | - $content = apply_filters( 'autoptimize_filter_html_before_minify', $content ); |
|
| 442 | + $content = apply_filters('autoptimize_filter_html_before_minify', $content); |
|
| 443 | 443 | |
| 444 | 444 | // Run the classes! |
| 445 | - foreach ( $classes as $name ) { |
|
| 446 | - $instance = new $name( $content ); |
|
| 447 | - if ( $instance->read( $classoptions[ $name ] ) ) { |
|
| 445 | + foreach ($classes as $name) { |
|
| 446 | + $instance = new $name($content); |
|
| 447 | + if ($instance->read($classoptions[$name])) { |
|
| 448 | 448 | $instance->minify(); |
| 449 | 449 | $instance->cache(); |
| 450 | 450 | $content = $instance->getcontent(); |
| 451 | 451 | } |
| 452 | - unset( $instance ); |
|
| 452 | + unset($instance); |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | - $content = apply_filters( 'autoptimize_html_after_minify', $content ); |
|
| 455 | + $content = apply_filters('autoptimize_html_after_minify', $content); |
|
| 456 | 456 | |
| 457 | 457 | return $content; |
| 458 | 458 | } |
@@ -494,25 +494,25 @@ discard block |
||
| 494 | 494 | 'autoptimize_imgopt_launched', |
| 495 | 495 | ); |
| 496 | 496 | |
| 497 | - if ( ! is_multisite() ) { |
|
| 498 | - foreach ( $delete_options as $del_opt ) { |
|
| 499 | - delete_option( $del_opt ); |
|
| 497 | + if (!is_multisite()) { |
|
| 498 | + foreach ($delete_options as $del_opt) { |
|
| 499 | + delete_option($del_opt); |
|
| 500 | 500 | } |
| 501 | 501 | } else { |
| 502 | 502 | global $wpdb; |
| 503 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
| 503 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
| 504 | 504 | $original_blog_id = get_current_blog_id(); |
| 505 | - foreach ( $blog_ids as $blog_id ) { |
|
| 506 | - switch_to_blog( $blog_id ); |
|
| 507 | - foreach ( $delete_options as $del_opt ) { |
|
| 508 | - delete_option( $del_opt ); |
|
| 505 | + foreach ($blog_ids as $blog_id) { |
|
| 506 | + switch_to_blog($blog_id); |
|
| 507 | + foreach ($delete_options as $del_opt) { |
|
| 508 | + delete_option($del_opt); |
|
| 509 | 509 | } |
| 510 | 510 | } |
| 511 | - switch_to_blog( $original_blog_id ); |
|
| 511 | + switch_to_blog($original_blog_id); |
|
| 512 | 512 | } |
| 513 | 513 | |
| 514 | - if ( wp_get_schedule( 'ao_cachechecker' ) ) { |
|
| 515 | - wp_clear_scheduled_hook( 'ao_cachechecker' ); |
|
| 514 | + if (wp_get_schedule('ao_cachechecker')) { |
|
| 515 | + wp_clear_scheduled_hook('ao_cachechecker'); |
|
| 516 | 516 | } |
| 517 | 517 | } |
| 518 | 518 | |
@@ -520,41 +520,41 @@ discard block |
||
| 520 | 520 | { |
| 521 | 521 | echo '<div class="error"><p>'; |
| 522 | 522 | // Translators: %s is the cache directory location. |
| 523 | - printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR ); |
|
| 523 | + printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR); |
|
| 524 | 524 | echo '</p></div>'; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | 527 | public static function notice_installed() |
| 528 | 528 | { |
| 529 | 529 | echo '<div class="updated"><p>'; |
| 530 | - _e( 'Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' ); |
|
| 530 | + _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize'); |
|
| 531 | 531 | echo '</p></div>'; |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | public static function notice_updated() |
| 535 | 535 | { |
| 536 | 536 | echo '<div class="updated"><p>'; |
| 537 | - _e( 'Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' ); |
|
| 537 | + _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize'); |
|
| 538 | 538 | echo '</p></div>'; |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | public static function notice_plug_imgopt() |
| 542 | 542 | { |
| 543 | 543 | // Translators: the URL added points to the Autopmize Extra settings. |
| 544 | - $_ao_imgopt_plug_notice = sprintf( __( 'Did you know Autoptimize includes on-the-fly image optimization and CDN via ShortPixel? Check out the %1$sAutoptimize Extra settings%2$s to activate this option.', 'autoptimize' ), '<a href="options-general.php?page=autoptimize_extra">', '</a>' ); |
|
| 545 | - $_ao_imgopt_plug_notice = apply_filters( 'autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice ); |
|
| 544 | + $_ao_imgopt_plug_notice = sprintf(__('Did you know Autoptimize includes on-the-fly image optimization and CDN via ShortPixel? Check out the %1$sAutoptimize Extra settings%2$s to activate this option.', 'autoptimize'), '<a href="options-general.php?page=autoptimize_extra">', '</a>'); |
|
| 545 | + $_ao_imgopt_plug_notice = apply_filters('autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice); |
|
| 546 | 546 | $_ao_imgopt_launch_ok = autoptimizeExtra::imgopt_launch_ok_wrapper(); |
| 547 | 547 | $_ao_imgopt_plug_dismissible = 'ao-img-opt-plug-123'; |
| 548 | 548 | |
| 549 | 549 | // check if AO is optimizing images already. |
| 550 | 550 | $_ao_imgopt_active = false; |
| 551 | - $_ao_extra_options = get_option( 'autoptimize_extra_settings', '' ); |
|
| 552 | - if ( is_array( $_ao_extra_options ) && array_key_exists( 'autoptimize_extra_checkbox_field_5', $_ao_extra_options ) && ! empty( $_ao_extra_options['autoptimize_extra_checkbox_field_5'] ) ) { |
|
| 551 | + $_ao_extra_options = get_option('autoptimize_extra_settings', ''); |
|
| 552 | + if (is_array($_ao_extra_options) && array_key_exists('autoptimize_extra_checkbox_field_5', $_ao_extra_options) && !empty($_ao_extra_options['autoptimize_extra_checkbox_field_5'])) { |
|
| 553 | 553 | $_ao_imgopt_active = true; |
| 554 | 554 | } |
| 555 | 555 | |
| 556 | - if ( '' !== $_ao_imgopt_plug_notice && ! $_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active( $_ao_imgopt_plug_dismissible ) ) { |
|
| 557 | - echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_imgopt_plug_dismissible . '"><p>'; |
|
| 556 | + if ('' !== $_ao_imgopt_plug_notice && !$_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active($_ao_imgopt_plug_dismissible)) { |
|
| 557 | + echo '<div class="notice notice-info is-dismissible" data-dismissible="'.$_ao_imgopt_plug_dismissible.'"><p>'; |
|
| 558 | 558 | echo $_ao_imgopt_plug_notice; |
| 559 | 559 | echo '</p></div>'; |
| 560 | 560 | } |