@@ -296,7 +296,7 @@ |
||
| 296 | 296 | * |
| 297 | 297 | * @param bool $doing_tests Allows overriding the optimization of only |
| 298 | 298 | * deciding once per request (for use in tests). |
| 299 | - * @return bool |
|
| 299 | + * @return boolean|null |
|
| 300 | 300 | */ |
| 301 | 301 | public static function should_buffer( $doing_tests = false ) |
| 302 | 302 | { |
@@ -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,104 +50,104 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | protected function add_hooks() |
| 52 | 52 | { |
| 53 | - if ( ! defined( 'AUTOPTIMIZE_SETUP_INITHOOK' ) ) { |
|
| 54 | - define( 'AUTOPTIMIZE_SETUP_INITHOOK', 'plugins_loaded' ); |
|
| 53 | + if (!defined('AUTOPTIMIZE_SETUP_INITHOOK')) { |
|
| 54 | + define('AUTOPTIMIZE_SETUP_INITHOOK', 'plugins_loaded'); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'setup' ) ); |
|
| 58 | - add_action( AUTOPTIMIZE_SETUP_INITHOOK, array( $this, 'hook_page_cache_purge' ) ); |
|
| 57 | + add_action(AUTOPTIMIZE_SETUP_INITHOOK, array($this, 'setup')); |
|
| 58 | + add_action(AUTOPTIMIZE_SETUP_INITHOOK, array($this, 'hook_page_cache_purge')); |
|
| 59 | 59 | |
| 60 | - add_action( 'autoptimize_setup_done', array( $this, 'version_upgrades_check' ) ); |
|
| 61 | - add_action( 'autoptimize_setup_done', array( $this, 'check_cache_and_run' ) ); |
|
| 62 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_ao_extra' ) ); |
|
| 63 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_partners_tab' ) ); |
|
| 64 | - add_action( 'autoptimize_setup_done', array( $this, 'maybe_run_criticalcss_tab' ) ); |
|
| 60 | + add_action('autoptimize_setup_done', array($this, 'version_upgrades_check')); |
|
| 61 | + add_action('autoptimize_setup_done', array($this, 'check_cache_and_run')); |
|
| 62 | + add_action('autoptimize_setup_done', array($this, 'maybe_run_ao_extra')); |
|
| 63 | + add_action('autoptimize_setup_done', array($this, 'maybe_run_partners_tab')); |
|
| 64 | + add_action('autoptimize_setup_done', array($this, 'maybe_run_criticalcss_tab')); |
|
| 65 | 65 | |
| 66 | - add_action( 'init', array( $this, 'load_textdomain' ) ); |
|
| 67 | - add_action( 'admin_init', array( 'PAnD', 'init' ) ); |
|
| 66 | + add_action('init', array($this, 'load_textdomain')); |
|
| 67 | + add_action('admin_init', array('PAnD', 'init')); |
|
| 68 | 68 | |
| 69 | - if ( is_multisite() && is_admin() ) { |
|
| 69 | + if (is_multisite() && is_admin()) { |
|
| 70 | 70 | // Only if multisite and if in admin we want to check if we need to save options on network level. |
| 71 | - add_action( 'init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options' ); |
|
| 71 | + add_action('init', 'autoptimizeOptionWrapper::check_multisite_on_saving_options'); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | - register_activation_hook( $this->filepath, array( $this, 'on_activate' ) ); |
|
| 74 | + register_activation_hook($this->filepath, array($this, 'on_activate')); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | public function on_activate() |
| 78 | 78 | { |
| 79 | - register_uninstall_hook( $this->filepath, 'autoptimizeMain::on_uninstall' ); |
|
| 79 | + register_uninstall_hook($this->filepath, 'autoptimizeMain::on_uninstall'); |
|
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | public function load_textdomain() |
| 83 | 83 | { |
| 84 | - load_plugin_textdomain( 'autoptimize' ); |
|
| 84 | + load_plugin_textdomain('autoptimize'); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | public function setup() |
| 88 | 88 | { |
| 89 | 89 | // Do we gzip in php when caching or is the webserver doing it? |
| 90 | - define( 'AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip' ) ); |
|
| 90 | + define('AUTOPTIMIZE_CACHE_NOGZIP', (bool) autoptimizeOptionWrapper::get_option('autoptimize_cache_nogzip')); |
|
| 91 | 91 | |
| 92 | 92 | // These can be overridden by specifying them in wp-config.php or such. |
| 93 | - if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_NAME' ) ) { |
|
| 94 | - define( 'AUTOPTIMIZE_WP_CONTENT_NAME', '/' . wp_basename( WP_CONTENT_DIR ) ); |
|
| 93 | + if (!defined('AUTOPTIMIZE_WP_CONTENT_NAME')) { |
|
| 94 | + define('AUTOPTIMIZE_WP_CONTENT_NAME', '/'.wp_basename(WP_CONTENT_DIR)); |
|
| 95 | 95 | } |
| 96 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_CHILD_DIR' ) ) { |
|
| 97 | - define( 'AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/' ); |
|
| 96 | + if (!defined('AUTOPTIMIZE_CACHE_CHILD_DIR')) { |
|
| 97 | + define('AUTOPTIMIZE_CACHE_CHILD_DIR', '/cache/autoptimize/'); |
|
| 98 | 98 | } |
| 99 | - if ( ! defined( 'AUTOPTIMIZE_CACHEFILE_PREFIX' ) ) { |
|
| 100 | - define( 'AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_' ); |
|
| 99 | + if (!defined('AUTOPTIMIZE_CACHEFILE_PREFIX')) { |
|
| 100 | + define('AUTOPTIMIZE_CACHEFILE_PREFIX', 'autoptimize_'); |
|
| 101 | 101 | } |
| 102 | 102 | // Note: trailing slash is not optional! |
| 103 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_DIR' ) ) { |
|
| 104 | - define( 'AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname() ); |
|
| 103 | + if (!defined('AUTOPTIMIZE_CACHE_DIR')) { |
|
| 104 | + define('AUTOPTIMIZE_CACHE_DIR', autoptimizeCache::get_pathname()); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - define( 'WP_ROOT_DIR', substr( WP_CONTENT_DIR, 0, strlen( WP_CONTENT_DIR ) - strlen( AUTOPTIMIZE_WP_CONTENT_NAME ) ) ); |
|
| 107 | + define('WP_ROOT_DIR', substr(WP_CONTENT_DIR, 0, strlen(WP_CONTENT_DIR) - strlen(AUTOPTIMIZE_WP_CONTENT_NAME))); |
|
| 108 | 108 | |
| 109 | - if ( ! defined( 'AUTOPTIMIZE_WP_SITE_URL' ) ) { |
|
| 110 | - if ( function_exists( 'domain_mapping_siteurl' ) ) { |
|
| 111 | - define( 'AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl( get_current_blog_id() ) ); |
|
| 109 | + if (!defined('AUTOPTIMIZE_WP_SITE_URL')) { |
|
| 110 | + if (function_exists('domain_mapping_siteurl')) { |
|
| 111 | + define('AUTOPTIMIZE_WP_SITE_URL', domain_mapping_siteurl(get_current_blog_id())); |
|
| 112 | 112 | } else { |
| 113 | - define( 'AUTOPTIMIZE_WP_SITE_URL', site_url() ); |
|
| 113 | + define('AUTOPTIMIZE_WP_SITE_URL', site_url()); |
|
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | - if ( ! defined( 'AUTOPTIMIZE_WP_CONTENT_URL' ) ) { |
|
| 117 | - if ( function_exists( 'get_original_url' ) ) { |
|
| 118 | - define( 'AUTOPTIMIZE_WP_CONTENT_URL', str_replace( get_original_url( AUTOPTIMIZE_WP_SITE_URL ), AUTOPTIMIZE_WP_SITE_URL, content_url() ) ); |
|
| 116 | + if (!defined('AUTOPTIMIZE_WP_CONTENT_URL')) { |
|
| 117 | + if (function_exists('get_original_url')) { |
|
| 118 | + define('AUTOPTIMIZE_WP_CONTENT_URL', str_replace(get_original_url(AUTOPTIMIZE_WP_SITE_URL), AUTOPTIMIZE_WP_SITE_URL, content_url())); |
|
| 119 | 119 | } else { |
| 120 | - define( 'AUTOPTIMIZE_WP_CONTENT_URL', content_url() ); |
|
| 120 | + define('AUTOPTIMIZE_WP_CONTENT_URL', content_url()); |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | - if ( ! defined( 'AUTOPTIMIZE_CACHE_URL' ) ) { |
|
| 124 | - if ( is_multisite() && apply_filters( 'autoptimize_separate_blog_caches', true ) ) { |
|
| 123 | + if (!defined('AUTOPTIMIZE_CACHE_URL')) { |
|
| 124 | + if (is_multisite() && apply_filters('autoptimize_separate_blog_caches', true)) { |
|
| 125 | 125 | $blog_id = get_current_blog_id(); |
| 126 | - define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR . $blog_id . '/' ); |
|
| 126 | + define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR.$blog_id.'/'); |
|
| 127 | 127 | } else { |
| 128 | - define( 'AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL . AUTOPTIMIZE_CACHE_CHILD_DIR ); |
|
| 128 | + define('AUTOPTIMIZE_CACHE_URL', AUTOPTIMIZE_WP_CONTENT_URL.AUTOPTIMIZE_CACHE_CHILD_DIR); |
|
| 129 | 129 | } |
| 130 | 130 | } |
| 131 | - if ( ! defined( 'AUTOPTIMIZE_WP_ROOT_URL' ) ) { |
|
| 132 | - define( 'AUTOPTIMIZE_WP_ROOT_URL', str_replace( AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL ) ); |
|
| 131 | + if (!defined('AUTOPTIMIZE_WP_ROOT_URL')) { |
|
| 132 | + define('AUTOPTIMIZE_WP_ROOT_URL', str_replace(AUTOPTIMIZE_WP_CONTENT_NAME, '', AUTOPTIMIZE_WP_CONTENT_URL)); |
|
| 133 | 133 | } |
| 134 | - if ( ! defined( 'AUTOPTIMIZE_HASH' ) ) { |
|
| 135 | - define( 'AUTOPTIMIZE_HASH', wp_hash( AUTOPTIMIZE_CACHE_URL ) ); |
|
| 134 | + if (!defined('AUTOPTIMIZE_HASH')) { |
|
| 135 | + define('AUTOPTIMIZE_HASH', wp_hash(AUTOPTIMIZE_CACHE_URL)); |
|
| 136 | 136 | } |
| 137 | - if ( ! defined( 'AUTOPTIMIZE_SITE_DOMAIN' ) ) { |
|
| 138 | - define( 'AUTOPTIMIZE_SITE_DOMAIN', parse_url( AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST ) ); |
|
| 137 | + if (!defined('AUTOPTIMIZE_SITE_DOMAIN')) { |
|
| 138 | + define('AUTOPTIMIZE_SITE_DOMAIN', parse_url(AUTOPTIMIZE_WP_SITE_URL, PHP_URL_HOST)); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | // Multibyte-capable string replacements are available with a filter. |
| 142 | 142 | // Also requires 'mbstring' extension. |
| 143 | - $with_mbstring = apply_filters( 'autoptimize_filter_main_use_mbstring', false ); |
|
| 144 | - if ( $with_mbstring ) { |
|
| 145 | - autoptimizeUtils::mbstring_available( \extension_loaded( 'mbstring' ) ); |
|
| 143 | + $with_mbstring = apply_filters('autoptimize_filter_main_use_mbstring', false); |
|
| 144 | + if ($with_mbstring) { |
|
| 145 | + autoptimizeUtils::mbstring_available(\extension_loaded('mbstring')); |
|
| 146 | 146 | } else { |
| 147 | - autoptimizeUtils::mbstring_available( false ); |
|
| 147 | + autoptimizeUtils::mbstring_available(false); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - do_action( 'autoptimize_setup_done' ); |
|
| 150 | + do_action('autoptimize_setup_done'); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -157,61 +157,61 @@ discard block |
||
| 157 | 157 | */ |
| 158 | 158 | public function version_upgrades_check() |
| 159 | 159 | { |
| 160 | - autoptimizeVersionUpdatesHandler::check_installed_and_update( $this->version ); |
|
| 160 | + autoptimizeVersionUpdatesHandler::check_installed_and_update($this->version); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | public function check_cache_and_run() |
| 164 | 164 | { |
| 165 | - if ( autoptimizeCache::cacheavail() ) { |
|
| 165 | + if (autoptimizeCache::cacheavail()) { |
|
| 166 | 166 | $conf = autoptimizeConfig::instance(); |
| 167 | - if ( $conf->get( 'autoptimize_html' ) || $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper() ) { |
|
| 168 | - if ( ! defined( 'AUTOPTIMIZE_NOBUFFER_OPTIMIZE' ) ) { |
|
| 167 | + if ($conf->get('autoptimize_html') || $conf->get('autoptimize_js') || $conf->get('autoptimize_css') || autoptimizeImages::imgopt_active() || autoptimizeImages::should_lazyload_wrapper()) { |
|
| 168 | + if (!defined('AUTOPTIMIZE_NOBUFFER_OPTIMIZE')) { |
|
| 169 | 169 | // Hook into WordPress frontend. |
| 170 | - if ( defined( 'AUTOPTIMIZE_INIT_EARLIER' ) ) { |
|
| 170 | + if (defined('AUTOPTIMIZE_INIT_EARLIER')) { |
|
| 171 | 171 | add_action( |
| 172 | 172 | 'init', |
| 173 | - array( $this, 'start_buffering' ), |
|
| 173 | + array($this, 'start_buffering'), |
|
| 174 | 174 | self::INIT_EARLIER_PRIORITY |
| 175 | 175 | ); |
| 176 | 176 | } else { |
| 177 | - if ( ! defined( 'AUTOPTIMIZE_HOOK_INTO' ) ) { |
|
| 178 | - define( 'AUTOPTIMIZE_HOOK_INTO', 'template_redirect' ); |
|
| 177 | + if (!defined('AUTOPTIMIZE_HOOK_INTO')) { |
|
| 178 | + define('AUTOPTIMIZE_HOOK_INTO', 'template_redirect'); |
|
| 179 | 179 | } |
| 180 | 180 | add_action( |
| 181 | - constant( 'AUTOPTIMIZE_HOOK_INTO' ), |
|
| 182 | - array( $this, 'start_buffering' ), |
|
| 181 | + constant('AUTOPTIMIZE_HOOK_INTO'), |
|
| 182 | + array($this, 'start_buffering'), |
|
| 183 | 183 | self::DEFAULT_HOOK_PRIORITY |
| 184 | 184 | ); |
| 185 | 185 | } |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // And disable Jetpack's site accelerator if JS or CSS opt. are active. |
| 189 | - if ( class_exists( 'Jetpack' ) && apply_filters( 'autoptimize_filter_main_disable_jetpack_cdn', true ) && ( $conf->get( 'autoptimize_js' ) || $conf->get( 'autoptimize_css' ) ) ) { |
|
| 190 | - add_filter( 'jetpack_force_disable_site_accelerator', '__return_true' ); |
|
| 189 | + if (class_exists('Jetpack') && apply_filters('autoptimize_filter_main_disable_jetpack_cdn', true) && ($conf->get('autoptimize_js') || $conf->get('autoptimize_css'))) { |
|
| 190 | + add_filter('jetpack_force_disable_site_accelerator', '__return_true'); |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | } else { |
| 194 | - add_action( 'admin_notices', 'autoptimizeMain::notice_cache_unavailable' ); |
|
| 194 | + add_action('admin_notices', 'autoptimizeMain::notice_cache_unavailable'); |
|
| 195 | 195 | } |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | public function maybe_run_ao_extra() |
| 199 | 199 | { |
| 200 | - if ( apply_filters( 'autoptimize_filter_extra_activate', true ) ) { |
|
| 200 | + if (apply_filters('autoptimize_filter_extra_activate', true)) { |
|
| 201 | 201 | $ao_imgopt = new autoptimizeImages(); |
| 202 | 202 | $ao_imgopt->run(); |
| 203 | 203 | $ao_extra = new autoptimizeExtra(); |
| 204 | 204 | $ao_extra->run(); |
| 205 | 205 | |
| 206 | 206 | // And show the imgopt notice. |
| 207 | - add_action( 'admin_notices', 'autoptimizeMain::notice_plug_imgopt' ); |
|
| 207 | + add_action('admin_notices', 'autoptimizeMain::notice_plug_imgopt'); |
|
| 208 | 208 | } |
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | public function maybe_run_partners_tab() |
| 212 | 212 | { |
| 213 | 213 | // Loads partners tab code if in admin (and not in admin-ajax.php)! |
| 214 | - if ( autoptimizeConfig::is_admin_and_not_ajax() ) { |
|
| 214 | + if (autoptimizeConfig::is_admin_and_not_ajax()) { |
|
| 215 | 215 | new autoptimizePartners(); |
| 216 | 216 | } |
| 217 | 217 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | public function maybe_run_criticalcss_tab() |
| 220 | 220 | { |
| 221 | 221 | // Loads criticalcss tab code if in admin (and not in admin-ajax.php)! |
| 222 | - if ( autoptimizeConfig::is_admin_and_not_ajax() && ! autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { |
|
| 222 | + if (autoptimizeConfig::is_admin_and_not_ajax() && !autoptimizeUtils::is_plugin_active('autoptimize-criticalcss/ao_criticss_aas.php')) { |
|
| 223 | 223 | new autoptimizeCriticalCSSSettings(); |
| 224 | 224 | } |
| 225 | 225 | } |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | public function hook_page_cache_purge() |
| 228 | 228 | { |
| 229 | 229 | // hook into a collection of page cache purge actions if filter allows. |
| 230 | - if ( apply_filters( 'autoptimize_filter_main_hookpagecachepurge', true ) ) { |
|
| 230 | + if (apply_filters('autoptimize_filter_main_hookpagecachepurge', true)) { |
|
| 231 | 231 | $page_cache_purge_actions = array( |
| 232 | 232 | 'after_rocket_clean_domain', // exists. |
| 233 | 233 | 'hyper_cache_purged', // Stefano confirmed this will be added. |
@@ -242,9 +242,9 @@ discard block |
||
| 242 | 242 | 'wpo_cache_flush', // wp-optimize. |
| 243 | 243 | 'rt_nginx_helper_after_fastcgi_purge_all', // nginx helper. |
| 244 | 244 | ); |
| 245 | - $page_cache_purge_actions = apply_filters( 'autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions ); |
|
| 246 | - foreach ( $page_cache_purge_actions as $purge_action ) { |
|
| 247 | - add_action( $purge_action, 'autoptimizeCache::clearall_actionless' ); |
|
| 245 | + $page_cache_purge_actions = apply_filters('autoptimize_filter_main_pagecachepurgeactions', $page_cache_purge_actions); |
|
| 246 | + foreach ($page_cache_purge_actions as $purge_action) { |
|
| 247 | + add_action($purge_action, 'autoptimizeCache::clearall_actionless'); |
|
| 248 | 248 | } |
| 249 | 249 | } |
| 250 | 250 | } |
@@ -256,38 +256,38 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | public function start_buffering() |
| 258 | 258 | { |
| 259 | - if ( $this->should_buffer() ) { |
|
| 259 | + if ($this->should_buffer()) { |
|
| 260 | 260 | |
| 261 | 261 | // Load speedupper conditionally (true by default). |
| 262 | - if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) { |
|
| 262 | + if (apply_filters('autoptimize_filter_speedupper', true)) { |
|
| 263 | 263 | $ao_speedupper = new autoptimizeSpeedupper(); |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | $conf = autoptimizeConfig::instance(); |
| 267 | 267 | |
| 268 | - if ( $conf->get( 'autoptimize_js' ) ) { |
|
| 269 | - if ( ! defined( 'CONCATENATE_SCRIPTS' ) ) { |
|
| 270 | - define( 'CONCATENATE_SCRIPTS', false ); |
|
| 268 | + if ($conf->get('autoptimize_js')) { |
|
| 269 | + if (!defined('CONCATENATE_SCRIPTS')) { |
|
| 270 | + define('CONCATENATE_SCRIPTS', false); |
|
| 271 | 271 | } |
| 272 | - if ( ! defined( 'COMPRESS_SCRIPTS' ) ) { |
|
| 273 | - define( 'COMPRESS_SCRIPTS', false ); |
|
| 272 | + if (!defined('COMPRESS_SCRIPTS')) { |
|
| 273 | + define('COMPRESS_SCRIPTS', false); |
|
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | 276 | |
| 277 | - if ( $conf->get( 'autoptimize_css' ) ) { |
|
| 278 | - if ( ! defined( 'COMPRESS_CSS' ) ) { |
|
| 279 | - define( 'COMPRESS_CSS', false ); |
|
| 277 | + if ($conf->get('autoptimize_css')) { |
|
| 278 | + if (!defined('COMPRESS_CSS')) { |
|
| 279 | + define('COMPRESS_CSS', false); |
|
| 280 | 280 | } |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - if ( apply_filters( 'autoptimize_filter_obkiller', false ) ) { |
|
| 284 | - while ( ob_get_level() > 0 ) { |
|
| 283 | + if (apply_filters('autoptimize_filter_obkiller', false)) { |
|
| 284 | + while (ob_get_level() > 0) { |
|
| 285 | 285 | ob_end_clean(); |
| 286 | 286 | } |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | 289 | // Now, start the real thing! |
| 290 | - ob_start( array( $this, 'end_buffering' ) ); |
|
| 290 | + ob_start(array($this, 'end_buffering')); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | |
@@ -298,31 +298,31 @@ discard block |
||
| 298 | 298 | * deciding once per request (for use in tests). |
| 299 | 299 | * @return bool |
| 300 | 300 | */ |
| 301 | - public static function should_buffer( $doing_tests = false ) |
|
| 301 | + public static function should_buffer($doing_tests = false) |
|
| 302 | 302 | { |
| 303 | 303 | static $do_buffering = null; |
| 304 | 304 | |
| 305 | 305 | // Only check once in case we're called multiple times by others but |
| 306 | 306 | // still allows multiple calls when doing tests. |
| 307 | - if ( null === $do_buffering || $doing_tests ) { |
|
| 307 | + if (null === $do_buffering || $doing_tests) { |
|
| 308 | 308 | |
| 309 | 309 | $ao_noptimize = false; |
| 310 | 310 | |
| 311 | 311 | // Checking for DONOTMINIFY constant as used by e.g. WooCommerce POS. |
| 312 | - if ( defined( 'DONOTMINIFY' ) && ( constant( 'DONOTMINIFY' ) === true || constant( 'DONOTMINIFY' ) === 'true' ) ) { |
|
| 312 | + if (defined('DONOTMINIFY') && (constant('DONOTMINIFY') === true || constant('DONOTMINIFY') === 'true')) { |
|
| 313 | 313 | $ao_noptimize = true; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | // Skip checking query strings if they're disabled. |
| 317 | - if ( apply_filters( 'autoptimize_filter_honor_qs_noptimize', true ) ) { |
|
| 317 | + if (apply_filters('autoptimize_filter_honor_qs_noptimize', true)) { |
|
| 318 | 318 | // Check for `ao_noptimize` (and other) keys in the query string |
| 319 | 319 | // to get non-optimized page for debugging. |
| 320 | 320 | $keys = array( |
| 321 | 321 | 'ao_noptimize', |
| 322 | 322 | 'ao_noptirocket', |
| 323 | 323 | ); |
| 324 | - foreach ( $keys as $key ) { |
|
| 325 | - if ( array_key_exists( $key, $_GET ) && '1' === $_GET[ $key ] ) { |
|
| 324 | + foreach ($keys as $key) { |
|
| 325 | + if (array_key_exists($key, $_GET) && '1' === $_GET[$key]) { |
|
| 326 | 326 | $ao_noptimize = true; |
| 327 | 327 | break; |
| 328 | 328 | } |
@@ -331,25 +331,25 @@ discard block |
||
| 331 | 331 | |
| 332 | 332 | // also honor PageSpeed=off parameter as used by mod_pagespeed, in use by some pagebuilders, |
| 333 | 333 | // see https://www.modpagespeed.com/doc/experiment#ModPagespeed for info on that. |
| 334 | - if ( false === $ao_noptimize && array_key_exists( 'PageSpeed', $_GET ) && 'off' === $_GET['PageSpeed'] ) { |
|
| 334 | + if (false === $ao_noptimize && array_key_exists('PageSpeed', $_GET) && 'off' === $_GET['PageSpeed']) { |
|
| 335 | 335 | $ao_noptimize = true; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | // and make sure Thrive editor doesn't get optimized HTML. |
| 339 | - if ( false === $ao_noptimize && array_key_exists( 'tve', $_GET ) && 'true' === $_GET['tve'] ) { |
|
| 339 | + if (false === $ao_noptimize && array_key_exists('tve', $_GET) && 'true' === $_GET['tve']) { |
|
| 340 | 340 | $ao_noptimize = true; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | // If setting says not to optimize logged in user and user is logged in... |
| 344 | - if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) { |
|
| 344 | + if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_logged', 'on') && is_user_logged_in() && current_user_can('edit_posts')) { |
|
| 345 | 345 | $ao_noptimize = true; |
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | // If setting says not to optimize cart/checkout. |
| 349 | - if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', 'off' ) ) { |
|
| 349 | + if (false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_optimize_checkout', 'off')) { |
|
| 350 | 350 | // Checking for woocommerce, easy digital downloads and wp ecommerce... |
| 351 | - foreach ( array( 'is_checkout', 'is_cart', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout' ) as $func ) { |
|
| 352 | - if ( function_exists( $func ) && $func() ) { |
|
| 351 | + foreach (array('is_checkout', 'is_cart', 'edd_is_checkout', 'wpsc_is_cart', 'wpsc_is_checkout') as $func) { |
|
| 352 | + if (function_exists($func) && $func()) { |
|
| 353 | 353 | $ao_noptimize = true; |
| 354 | 354 | break; |
| 355 | 355 | } |
@@ -357,11 +357,11 @@ discard block |
||
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | // Allows blocking of autoptimization on your own terms regardless of above decisions. |
| 360 | - $ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize ); |
|
| 360 | + $ao_noptimize = (bool) apply_filters('autoptimize_filter_noptimize', $ao_noptimize); |
|
| 361 | 361 | |
| 362 | 362 | // Check for site being previewed in the Customizer (available since WP 4.0). |
| 363 | 363 | $is_customize_preview = false; |
| 364 | - if ( function_exists( 'is_customize_preview' ) && is_customize_preview() ) { |
|
| 364 | + if (function_exists('is_customize_preview') && is_customize_preview()) { |
|
| 365 | 365 | $is_customize_preview = is_customize_preview(); |
| 366 | 366 | } |
| 367 | 367 | |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | * while the main query hasn't been ran yet. Thats why we use |
| 373 | 373 | * AUTOPTIMIZE_INIT_EARLIER in tests. |
| 374 | 374 | */ |
| 375 | - $do_buffering = ( ! is_admin() && ! is_feed() && ! is_embed() && ! $ao_noptimize && ! $is_customize_preview ); |
|
| 375 | + $do_buffering = (!is_admin() && !is_feed() && !is_embed() && !$ao_noptimize && !$is_customize_preview); |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | return $do_buffering; |
@@ -385,25 +385,25 @@ discard block |
||
| 385 | 385 | * |
| 386 | 386 | * @return bool |
| 387 | 387 | */ |
| 388 | - public function is_valid_buffer( $content ) |
|
| 388 | + public function is_valid_buffer($content) |
|
| 389 | 389 | { |
| 390 | 390 | // Defaults to true. |
| 391 | 391 | $valid = true; |
| 392 | 392 | |
| 393 | - $has_no_html_tag = ( false === stripos( $content, '<html' ) ); |
|
| 394 | - $has_xsl_stylesheet = ( false !== stripos( $content, '<xsl:stylesheet' ) || false !== stripos( $content, '<?xml-stylesheet' ) ); |
|
| 395 | - $has_html5_doctype = ( preg_match( '/^<!DOCTYPE.+html>/i', ltrim( $content ) ) > 0 ); |
|
| 396 | - $has_noptimize_page = ( false !== stripos( $content, '<!-- noptimize-page -->' ) ); |
|
| 393 | + $has_no_html_tag = (false === stripos($content, '<html')); |
|
| 394 | + $has_xsl_stylesheet = (false !== stripos($content, '<xsl:stylesheet') || false !== stripos($content, '<?xml-stylesheet')); |
|
| 395 | + $has_html5_doctype = (preg_match('/^<!DOCTYPE.+html>/i', ltrim($content)) > 0); |
|
| 396 | + $has_noptimize_page = (false !== stripos($content, '<!-- noptimize-page -->')); |
|
| 397 | 397 | |
| 398 | - if ( $has_no_html_tag ) { |
|
| 398 | + if ($has_no_html_tag) { |
|
| 399 | 399 | // Can't be valid amp markup without an html tag preceding it. |
| 400 | 400 | $is_amp_markup = false; |
| 401 | 401 | } else { |
| 402 | - $is_amp_markup = self::is_amp_markup( $content ); |
|
| 402 | + $is_amp_markup = self::is_amp_markup($content); |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | // If it's not html, or if it's amp or contains xsl stylesheets we don't touch it. |
| 406 | - if ( $has_no_html_tag && ! $has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page ) { |
|
| 406 | + if ($has_no_html_tag && !$has_html5_doctype || $is_amp_markup || $has_xsl_stylesheet || $has_noptimize_page) { |
|
| 407 | 407 | $valid = false; |
| 408 | 408 | } |
| 409 | 409 | |
@@ -418,14 +418,14 @@ discard block |
||
| 418 | 418 | * |
| 419 | 419 | * @return bool |
| 420 | 420 | */ |
| 421 | - public static function is_amp_markup( $content ) |
|
| 421 | + public static function is_amp_markup($content) |
|
| 422 | 422 | { |
| 423 | 423 | // Short-circuit when a function is available to determine whether the response is (or will be) an AMP page. |
| 424 | - if ( function_exists( 'is_amp_endpoint' ) ) { |
|
| 424 | + if (function_exists('is_amp_endpoint')) { |
|
| 425 | 425 | return is_amp_endpoint(); |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | - $is_amp_markup = preg_match( '/<html[^>]*(?:amp|⚡)/i', $content ); |
|
| 428 | + $is_amp_markup = preg_match('/<html[^>]*(?:amp|⚡)/i', $content); |
|
| 429 | 429 | |
| 430 | 430 | return (bool) $is_amp_markup; |
| 431 | 431 | } |
@@ -438,10 +438,10 @@ discard block |
||
| 438 | 438 | * |
| 439 | 439 | * @return string |
| 440 | 440 | */ |
| 441 | - public function end_buffering( $content ) |
|
| 441 | + public function end_buffering($content) |
|
| 442 | 442 | { |
| 443 | 443 | // Bail early without modifying anything if we can't handle the content. |
| 444 | - if ( ! $this->is_valid_buffer( $content ) ) { |
|
| 444 | + if (!$this->is_valid_buffer($content)) { |
|
| 445 | 445 | return $content; |
| 446 | 446 | } |
| 447 | 447 | |
@@ -449,73 +449,73 @@ discard block |
||
| 449 | 449 | |
| 450 | 450 | // Determine what needs to be ran. |
| 451 | 451 | $classes = array(); |
| 452 | - if ( $conf->get( 'autoptimize_js' ) ) { |
|
| 452 | + if ($conf->get('autoptimize_js')) { |
|
| 453 | 453 | $classes[] = 'autoptimizeScripts'; |
| 454 | 454 | } |
| 455 | - if ( $conf->get( 'autoptimize_css' ) ) { |
|
| 455 | + if ($conf->get('autoptimize_css')) { |
|
| 456 | 456 | $classes[] = 'autoptimizeStyles'; |
| 457 | 457 | } |
| 458 | - if ( $conf->get( 'autoptimize_html' ) ) { |
|
| 458 | + if ($conf->get('autoptimize_html')) { |
|
| 459 | 459 | $classes[] = 'autoptimizeHTML'; |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | $classoptions = array( |
| 463 | 463 | 'autoptimizeScripts' => array( |
| 464 | - 'aggregate' => $conf->get( 'autoptimize_js_aggregate' ), |
|
| 465 | - 'justhead' => $conf->get( 'autoptimize_js_justhead' ), |
|
| 466 | - 'forcehead' => $conf->get( 'autoptimize_js_forcehead' ), |
|
| 467 | - 'trycatch' => $conf->get( 'autoptimize_js_trycatch' ), |
|
| 468 | - 'js_exclude' => $conf->get( 'autoptimize_js_exclude' ), |
|
| 469 | - 'cdn_url' => $conf->get( 'autoptimize_cdn_url' ), |
|
| 470 | - 'include_inline' => $conf->get( 'autoptimize_js_include_inline' ), |
|
| 471 | - 'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ), |
|
| 464 | + 'aggregate' => $conf->get('autoptimize_js_aggregate'), |
|
| 465 | + 'justhead' => $conf->get('autoptimize_js_justhead'), |
|
| 466 | + 'forcehead' => $conf->get('autoptimize_js_forcehead'), |
|
| 467 | + 'trycatch' => $conf->get('autoptimize_js_trycatch'), |
|
| 468 | + 'js_exclude' => $conf->get('autoptimize_js_exclude'), |
|
| 469 | + 'cdn_url' => $conf->get('autoptimize_cdn_url'), |
|
| 470 | + 'include_inline' => $conf->get('autoptimize_js_include_inline'), |
|
| 471 | + 'minify_excluded' => $conf->get('autoptimize_minify_excluded'), |
|
| 472 | 472 | ), |
| 473 | 473 | 'autoptimizeStyles' => array( |
| 474 | - 'aggregate' => $conf->get( 'autoptimize_css_aggregate' ), |
|
| 475 | - 'justhead' => $conf->get( 'autoptimize_css_justhead' ), |
|
| 476 | - 'datauris' => $conf->get( 'autoptimize_css_datauris' ), |
|
| 477 | - 'defer' => $conf->get( 'autoptimize_css_defer' ), |
|
| 478 | - 'defer_inline' => $conf->get( 'autoptimize_css_defer_inline' ), |
|
| 479 | - 'inline' => $conf->get( 'autoptimize_css_inline' ), |
|
| 480 | - 'css_exclude' => $conf->get( 'autoptimize_css_exclude' ), |
|
| 481 | - 'cdn_url' => $conf->get( 'autoptimize_cdn_url' ), |
|
| 482 | - 'include_inline' => $conf->get( 'autoptimize_css_include_inline' ), |
|
| 483 | - 'nogooglefont' => $conf->get( 'autoptimize_css_nogooglefont' ), |
|
| 484 | - 'minify_excluded' => $conf->get( 'autoptimize_minify_excluded' ), |
|
| 474 | + 'aggregate' => $conf->get('autoptimize_css_aggregate'), |
|
| 475 | + 'justhead' => $conf->get('autoptimize_css_justhead'), |
|
| 476 | + 'datauris' => $conf->get('autoptimize_css_datauris'), |
|
| 477 | + 'defer' => $conf->get('autoptimize_css_defer'), |
|
| 478 | + 'defer_inline' => $conf->get('autoptimize_css_defer_inline'), |
|
| 479 | + 'inline' => $conf->get('autoptimize_css_inline'), |
|
| 480 | + 'css_exclude' => $conf->get('autoptimize_css_exclude'), |
|
| 481 | + 'cdn_url' => $conf->get('autoptimize_cdn_url'), |
|
| 482 | + 'include_inline' => $conf->get('autoptimize_css_include_inline'), |
|
| 483 | + 'nogooglefont' => $conf->get('autoptimize_css_nogooglefont'), |
|
| 484 | + 'minify_excluded' => $conf->get('autoptimize_minify_excluded'), |
|
| 485 | 485 | ), |
| 486 | 486 | 'autoptimizeHTML' => array( |
| 487 | - 'keepcomments' => $conf->get( 'autoptimize_html_keepcomments' ), |
|
| 487 | + 'keepcomments' => $conf->get('autoptimize_html_keepcomments'), |
|
| 488 | 488 | ), |
| 489 | 489 | ); |
| 490 | 490 | |
| 491 | - $content = apply_filters( 'autoptimize_filter_html_before_minify', $content ); |
|
| 491 | + $content = apply_filters('autoptimize_filter_html_before_minify', $content); |
|
| 492 | 492 | |
| 493 | 493 | // Run the classes! |
| 494 | - foreach ( $classes as $name ) { |
|
| 495 | - $instance = new $name( $content ); |
|
| 496 | - if ( $instance->read( $classoptions[ $name ] ) ) { |
|
| 494 | + foreach ($classes as $name) { |
|
| 495 | + $instance = new $name($content); |
|
| 496 | + if ($instance->read($classoptions[$name])) { |
|
| 497 | 497 | $instance->minify(); |
| 498 | 498 | $instance->cache(); |
| 499 | 499 | $content = $instance->getcontent(); |
| 500 | 500 | } |
| 501 | - unset( $instance ); |
|
| 501 | + unset($instance); |
|
| 502 | 502 | } |
| 503 | 503 | |
| 504 | - $content = apply_filters( 'autoptimize_html_after_minify', $content ); |
|
| 504 | + $content = apply_filters('autoptimize_html_after_minify', $content); |
|
| 505 | 505 | |
| 506 | 506 | return $content; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - public static function autoptimize_nobuffer_optimize( $html_in ) { |
|
| 509 | + public static function autoptimize_nobuffer_optimize($html_in) { |
|
| 510 | 510 | $html_out = $html_in; |
| 511 | 511 | |
| 512 | - if ( apply_filters( 'autoptimize_filter_speedupper', true ) ) { |
|
| 512 | + if (apply_filters('autoptimize_filter_speedupper', true)) { |
|
| 513 | 513 | $ao_speedupper = new autoptimizeSpeedupper(); |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | - $self = new self( AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE ); |
|
| 517 | - if ( $self->should_buffer() ) { |
|
| 518 | - $html_out = $self->end_buffering( $html_in ); |
|
| 516 | + $self = new self(AUTOPTIMIZE_PLUGIN_VERSION, AUTOPTIMIZE_PLUGIN_FILE); |
|
| 517 | + if ($self->should_buffer()) { |
|
| 518 | + $html_out = $self->end_buffering($html_in); |
|
| 519 | 519 | } |
| 520 | 520 | return $html_out; |
| 521 | 521 | } |
@@ -560,25 +560,25 @@ discard block |
||
| 560 | 560 | 'autoptimize_minify_excluded', |
| 561 | 561 | ); |
| 562 | 562 | |
| 563 | - if ( ! is_multisite() ) { |
|
| 564 | - foreach ( $delete_options as $del_opt ) { |
|
| 565 | - delete_option( $del_opt ); |
|
| 563 | + if (!is_multisite()) { |
|
| 564 | + foreach ($delete_options as $del_opt) { |
|
| 565 | + delete_option($del_opt); |
|
| 566 | 566 | } |
| 567 | 567 | } else { |
| 568 | 568 | global $wpdb; |
| 569 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
| 569 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
| 570 | 570 | $original_blog_id = get_current_blog_id(); |
| 571 | - foreach ( $blog_ids as $blog_id ) { |
|
| 572 | - switch_to_blog( $blog_id ); |
|
| 573 | - foreach ( $delete_options as $del_opt ) { |
|
| 574 | - delete_option( $del_opt ); |
|
| 571 | + foreach ($blog_ids as $blog_id) { |
|
| 572 | + switch_to_blog($blog_id); |
|
| 573 | + foreach ($delete_options as $del_opt) { |
|
| 574 | + delete_option($del_opt); |
|
| 575 | 575 | } |
| 576 | 576 | } |
| 577 | - switch_to_blog( $original_blog_id ); |
|
| 577 | + switch_to_blog($original_blog_id); |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | - if ( wp_get_schedule( 'ao_cachechecker' ) ) { |
|
| 581 | - wp_clear_scheduled_hook( 'ao_cachechecker' ); |
|
| 580 | + if (wp_get_schedule('ao_cachechecker')) { |
|
| 581 | + wp_clear_scheduled_hook('ao_cachechecker'); |
|
| 582 | 582 | } |
| 583 | 583 | } |
| 584 | 584 | |
@@ -586,35 +586,35 @@ discard block |
||
| 586 | 586 | { |
| 587 | 587 | echo '<div class="error"><p>'; |
| 588 | 588 | // Translators: %s is the cache directory location. |
| 589 | - printf( __( 'Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize' ), AUTOPTIMIZE_CACHE_DIR ); |
|
| 589 | + printf(__('Autoptimize cannot write to the cache directory (%s), please fix to enable CSS/ JS optimization!', 'autoptimize'), AUTOPTIMIZE_CACHE_DIR); |
|
| 590 | 590 | echo '</p></div>'; |
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | public static function notice_installed() |
| 594 | 594 | { |
| 595 | 595 | echo '<div class="updated"><p>'; |
| 596 | - _e( 'Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize' ); |
|
| 596 | + _e('Thank you for installing and activating Autoptimize. Please configure it under "Settings" -> "Autoptimize" to start improving your site\'s performance.', 'autoptimize'); |
|
| 597 | 597 | echo '</p></div>'; |
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | public static function notice_updated() |
| 601 | 601 | { |
| 602 | 602 | echo '<div class="updated"><p>'; |
| 603 | - _e( 'Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize' ); |
|
| 603 | + _e('Autoptimize has just been updated. Please <strong>test your site now</strong> and adapt Autoptimize config if needed.', 'autoptimize'); |
|
| 604 | 604 | echo '</p></div>'; |
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | public static function notice_plug_imgopt() |
| 608 | 608 | { |
| 609 | 609 | // Translators: the URL added points to the Autopmize Extra settings. |
| 610 | - $_ao_imgopt_plug_notice = sprintf( __( 'Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize' ), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>' ); |
|
| 611 | - $_ao_imgopt_plug_notice = apply_filters( 'autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice ); |
|
| 610 | + $_ao_imgopt_plug_notice = sprintf(__('Did you know Autoptimize includes on-the-fly image optimization (with support for WebP) and CDN via ShortPixel? Check out the %1$sAutoptimize Image settings%2$s to activate this option.', 'autoptimize'), '<a href="options-general.php?page=autoptimize_imgopt">', '</a>'); |
|
| 611 | + $_ao_imgopt_plug_notice = apply_filters('autoptimize_filter_main_imgopt_plug_notice', $_ao_imgopt_plug_notice); |
|
| 612 | 612 | $_ao_imgopt_launch_ok = autoptimizeImages::launch_ok_wrapper(); |
| 613 | 613 | $_ao_imgopt_plug_dismissible = 'ao-img-opt-plug-123'; |
| 614 | 614 | $_ao_imgopt_active = autoptimizeImages::imgopt_active(); |
| 615 | 615 | |
| 616 | - if ( current_user_can( 'manage_options' ) && '' !== $_ao_imgopt_plug_notice && ! $_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active( $_ao_imgopt_plug_dismissible ) ) { |
|
| 617 | - echo '<div class="notice notice-info is-dismissible" data-dismissible="' . $_ao_imgopt_plug_dismissible . '"><p>'; |
|
| 616 | + if (current_user_can('manage_options') && '' !== $_ao_imgopt_plug_notice && !$_ao_imgopt_active && $_ao_imgopt_launch_ok && PAnD::is_admin_notice_active($_ao_imgopt_plug_dismissible)) { |
|
| 617 | + echo '<div class="notice notice-info is-dismissible" data-dismissible="'.$_ao_imgopt_plug_dismissible.'"><p>'; |
|
| 618 | 618 | echo $_ao_imgopt_plug_notice; |
| 619 | 619 | echo '</p></div>'; |
| 620 | 620 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Handles autoptimizeExtra frontend features + admin options page |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 6 | +if (!defined('ABSPATH')) { |
|
| 7 | 7 | exit; |
| 8 | 8 | } |
| 9 | 9 | |
@@ -28,9 +28,9 @@ discard block |
||
| 28 | 28 | * |
| 29 | 29 | * @param array $options Optional. Allows overriding options without having to specify them via admin options page. |
| 30 | 30 | */ |
| 31 | - public function __construct( $options = array() ) |
|
| 31 | + public function __construct($options = array()) |
|
| 32 | 32 | { |
| 33 | - if ( empty( $options ) ) { |
|
| 33 | + if (empty($options)) { |
|
| 34 | 34 | $options = self::fetch_options(); |
| 35 | 35 | } |
| 36 | 36 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | */ |
| 48 | 48 | public static function instance() |
| 49 | 49 | { |
| 50 | - if ( null === self::$instance ) { |
|
| 50 | + if (null === self::$instance) { |
|
| 51 | 51 | self::$instance = new self(); |
| 52 | 52 | } |
| 53 | 53 | |
@@ -56,19 +56,19 @@ discard block |
||
| 56 | 56 | |
| 57 | 57 | public function run() |
| 58 | 58 | { |
| 59 | - if ( is_admin() ) { |
|
| 60 | - if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
| 61 | - add_action( 'network_admin_menu', array( $this, 'admin_menu' ) ); |
|
| 59 | + if (is_admin()) { |
|
| 60 | + if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
| 61 | + add_action('network_admin_menu', array($this, 'admin_menu')); |
|
| 62 | 62 | } else { |
| 63 | - add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
|
| 63 | + add_action('admin_menu', array($this, 'admin_menu')); |
|
| 64 | 64 | } |
| 65 | - add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_extra_tab' ) ); |
|
| 65 | + add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_extra_tab')); |
|
| 66 | 66 | } else { |
| 67 | 67 | $this->run_on_frontend(); |
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - public function set_options( array $options ) |
|
| 71 | + public function set_options(array $options) |
|
| 72 | 72 | { |
| 73 | 73 | $this->options = $options; |
| 74 | 74 | |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | |
| 78 | 78 | public static function fetch_options() |
| 79 | 79 | { |
| 80 | - $value = autoptimizeOptionWrapper::get_option( 'autoptimize_extra_settings' ); |
|
| 81 | - if ( empty( $value ) ) { |
|
| 80 | + $value = autoptimizeOptionWrapper::get_option('autoptimize_extra_settings'); |
|
| 81 | + if (empty($value)) { |
|
| 82 | 82 | // Fallback to returning defaults when no stored option exists yet. |
| 83 | 83 | $value = autoptimizeConfig::get_ao_extra_default_options(); |
| 84 | 84 | } |
@@ -89,55 +89,55 @@ discard block |
||
| 89 | 89 | public function disable_emojis() |
| 90 | 90 | { |
| 91 | 91 | // Removing all actions related to emojis! |
| 92 | - remove_action( 'admin_print_styles', 'print_emoji_styles' ); |
|
| 93 | - remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); |
|
| 94 | - remove_action( 'admin_print_scripts', 'print_emoji_detection_script' ); |
|
| 95 | - remove_action( 'wp_print_styles', 'print_emoji_styles' ); |
|
| 96 | - remove_filter( 'wp_mail', 'wp_staticize_emoji_for_email' ); |
|
| 97 | - remove_filter( 'the_content_feed', 'wp_staticize_emoji' ); |
|
| 98 | - remove_filter( 'comment_text_rss', 'wp_staticize_emoji' ); |
|
| 92 | + remove_action('admin_print_styles', 'print_emoji_styles'); |
|
| 93 | + remove_action('wp_head', 'print_emoji_detection_script', 7); |
|
| 94 | + remove_action('admin_print_scripts', 'print_emoji_detection_script'); |
|
| 95 | + remove_action('wp_print_styles', 'print_emoji_styles'); |
|
| 96 | + remove_filter('wp_mail', 'wp_staticize_emoji_for_email'); |
|
| 97 | + remove_filter('the_content_feed', 'wp_staticize_emoji'); |
|
| 98 | + remove_filter('comment_text_rss', 'wp_staticize_emoji'); |
|
| 99 | 99 | |
| 100 | 100 | // Removes TinyMCE emojis. |
| 101 | - add_filter( 'tiny_mce_plugins', array( $this, 'filter_disable_emojis_tinymce' ) ); |
|
| 101 | + add_filter('tiny_mce_plugins', array($this, 'filter_disable_emojis_tinymce')); |
|
| 102 | 102 | |
| 103 | 103 | // Removes emoji dns-preftech. |
| 104 | - add_filter( 'wp_resource_hints', array( $this, 'filter_remove_emoji_dns_prefetch' ), 10, 2 ); |
|
| 104 | + add_filter('wp_resource_hints', array($this, 'filter_remove_emoji_dns_prefetch'), 10, 2); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - public function filter_disable_emojis_tinymce( $plugins ) |
|
| 107 | + public function filter_disable_emojis_tinymce($plugins) |
|
| 108 | 108 | { |
| 109 | - if ( is_array( $plugins ) ) { |
|
| 110 | - return array_diff( $plugins, array( 'wpemoji' ) ); |
|
| 109 | + if (is_array($plugins)) { |
|
| 110 | + return array_diff($plugins, array('wpemoji')); |
|
| 111 | 111 | } else { |
| 112 | 112 | return array(); |
| 113 | 113 | } |
| 114 | 114 | } |
| 115 | 115 | |
| 116 | - public function filter_remove_qs( $src ) |
|
| 116 | + public function filter_remove_qs($src) |
|
| 117 | 117 | { |
| 118 | - if ( strpos( $src, '?ver=' ) ) { |
|
| 119 | - $src = remove_query_arg( 'ver', $src ); |
|
| 118 | + if (strpos($src, '?ver=')) { |
|
| 119 | + $src = remove_query_arg('ver', $src); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | return $src; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - public function extra_async_js( $in ) |
|
| 125 | + public function extra_async_js($in) |
|
| 126 | 126 | { |
| 127 | 127 | $exclusions = array(); |
| 128 | - if ( ! empty( $in ) ) { |
|
| 129 | - $exclusions = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $in ) ) ), '' ); |
|
| 128 | + if (!empty($in)) { |
|
| 129 | + $exclusions = array_fill_keys(array_filter(array_map('trim', explode(',', $in))), ''); |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | $settings = $this->options['autoptimize_extra_text_field_3']; |
| 133 | - $async = array_fill_keys( array_filter( array_map( 'trim', explode( ',', $settings ) ) ), '' ); |
|
| 134 | - $attr = apply_filters( 'autoptimize_filter_extra_async', 'async' ); |
|
| 135 | - foreach ( $async as $k => $v ) { |
|
| 136 | - $async[ $k ] = $attr; |
|
| 133 | + $async = array_fill_keys(array_filter(array_map('trim', explode(',', $settings))), ''); |
|
| 134 | + $attr = apply_filters('autoptimize_filter_extra_async', 'async'); |
|
| 135 | + foreach ($async as $k => $v) { |
|
| 136 | + $async[$k] = $attr; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // Merge exclusions & asyncs in one array and return to AO API. |
| 140 | - $merged = array_merge( $exclusions, $async ); |
|
| 140 | + $merged = array_merge($exclusions, $async); |
|
| 141 | 141 | |
| 142 | 142 | return $merged; |
| 143 | 143 | } |
@@ -147,61 +147,61 @@ discard block |
||
| 147 | 147 | $options = $this->options; |
| 148 | 148 | |
| 149 | 149 | // Disable emojis if specified. |
| 150 | - if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) ) { |
|
| 150 | + if (!empty($options['autoptimize_extra_checkbox_field_1'])) { |
|
| 151 | 151 | $this->disable_emojis(); |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | // Remove version query parameters. |
| 155 | - if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) ) { |
|
| 156 | - add_filter( 'script_loader_src', array( $this, 'filter_remove_qs' ), 15, 1 ); |
|
| 157 | - add_filter( 'style_loader_src', array( $this, 'filter_remove_qs' ), 15, 1 ); |
|
| 155 | + if (!empty($options['autoptimize_extra_checkbox_field_0'])) { |
|
| 156 | + add_filter('script_loader_src', array($this, 'filter_remove_qs'), 15, 1); |
|
| 157 | + add_filter('style_loader_src', array($this, 'filter_remove_qs'), 15, 1); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | // Avoiding conflicts of interest when async-javascript plugin is active! |
| 161 | - $async_js_plugin_active = autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ); |
|
| 162 | - if ( ! empty( $options['autoptimize_extra_text_field_3'] ) && ! $async_js_plugin_active ) { |
|
| 163 | - add_filter( 'autoptimize_filter_js_exclude', array( $this, 'extra_async_js' ), 10, 1 ); |
|
| 161 | + $async_js_plugin_active = autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php'); |
|
| 162 | + if (!empty($options['autoptimize_extra_text_field_3']) && !$async_js_plugin_active) { |
|
| 163 | + add_filter('autoptimize_filter_js_exclude', array($this, 'extra_async_js'), 10, 1); |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | // Optimize google fonts! |
| 167 | - if ( ! empty( $options['autoptimize_extra_radio_field_4'] ) && ( '1' !== $options['autoptimize_extra_radio_field_4'] ) ) { |
|
| 168 | - add_filter( 'wp_resource_hints', array( $this, 'filter_remove_gfonts_dnsprefetch' ), 10, 2 ); |
|
| 169 | - add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_optimize_google_fonts' ), 10, 1 ); |
|
| 170 | - add_filter( 'autoptimize_extra_filter_tobepreconn', array( $this, 'filter_preconnect_google_fonts' ), 10, 1 ); |
|
| 167 | + if (!empty($options['autoptimize_extra_radio_field_4']) && ('1' !== $options['autoptimize_extra_radio_field_4'])) { |
|
| 168 | + add_filter('wp_resource_hints', array($this, 'filter_remove_gfonts_dnsprefetch'), 10, 2); |
|
| 169 | + add_filter('autoptimize_html_after_minify', array($this, 'filter_optimize_google_fonts'), 10, 1); |
|
| 170 | + add_filter('autoptimize_extra_filter_tobepreconn', array($this, 'filter_preconnect_google_fonts'), 10, 1); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // Preconnect! |
| 174 | - if ( ! empty( $options['autoptimize_extra_text_field_2'] ) || has_filter( 'autoptimize_extra_filter_tobepreconn' ) ) { |
|
| 175 | - add_filter( 'wp_resource_hints', array( $this, 'filter_preconnect' ), 10, 2 ); |
|
| 174 | + if (!empty($options['autoptimize_extra_text_field_2']) || has_filter('autoptimize_extra_filter_tobepreconn')) { |
|
| 175 | + add_filter('wp_resource_hints', array($this, 'filter_preconnect'), 10, 2); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | // Preload! |
| 179 | - if ( ! empty( $options['autoptimize_extra_text_field_7'] ) ) { |
|
| 180 | - add_filter( 'autoptimize_html_after_minify', array( $this, 'filter_preload' ), 10, 2 ); |
|
| 179 | + if (!empty($options['autoptimize_extra_text_field_7'])) { |
|
| 180 | + add_filter('autoptimize_html_after_minify', array($this, 'filter_preload'), 10, 2); |
|
| 181 | 181 | } |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - public function filter_remove_emoji_dns_prefetch( $urls, $relation_type ) |
|
| 184 | + public function filter_remove_emoji_dns_prefetch($urls, $relation_type) |
|
| 185 | 185 | { |
| 186 | - $emoji_svg_url = apply_filters( 'emoji_svg_url', 'https://s.w.org/images/core/emoji/' ); |
|
| 186 | + $emoji_svg_url = apply_filters('emoji_svg_url', 'https://s.w.org/images/core/emoji/'); |
|
| 187 | 187 | |
| 188 | - return $this->filter_remove_dns_prefetch( $urls, $relation_type, $emoji_svg_url ); |
|
| 188 | + return $this->filter_remove_dns_prefetch($urls, $relation_type, $emoji_svg_url); |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - public function filter_remove_gfonts_dnsprefetch( $urls, $relation_type ) |
|
| 191 | + public function filter_remove_gfonts_dnsprefetch($urls, $relation_type) |
|
| 192 | 192 | { |
| 193 | - return $this->filter_remove_dns_prefetch( $urls, $relation_type, 'fonts.googleapis.com' ); |
|
| 193 | + return $this->filter_remove_dns_prefetch($urls, $relation_type, 'fonts.googleapis.com'); |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - public function filter_remove_dns_prefetch( $urls, $relation_type, $url_to_remove ) |
|
| 196 | + public function filter_remove_dns_prefetch($urls, $relation_type, $url_to_remove) |
|
| 197 | 197 | { |
| 198 | 198 | $url_to_remove = (string) $url_to_remove; |
| 199 | 199 | |
| 200 | - if ( ! empty( $url_to_remove ) && 'dns-prefetch' === $relation_type ) { |
|
| 200 | + if (!empty($url_to_remove) && 'dns-prefetch' === $relation_type) { |
|
| 201 | 201 | $cnt = 0; |
| 202 | - foreach ( $urls as $url ) { |
|
| 203 | - if ( false !== strpos( $url, $url_to_remove ) ) { |
|
| 204 | - unset( $urls[ $cnt ] ); |
|
| 202 | + foreach ($urls as $url) { |
|
| 203 | + if (false !== strpos($url, $url_to_remove)) { |
|
| 204 | + unset($urls[$cnt]); |
|
| 205 | 205 | } |
| 206 | 206 | $cnt++; |
| 207 | 207 | } |
@@ -210,152 +210,152 @@ discard block |
||
| 210 | 210 | return $urls; |
| 211 | 211 | } |
| 212 | 212 | |
| 213 | - public function filter_optimize_google_fonts( $in ) |
|
| 213 | + public function filter_optimize_google_fonts($in) |
|
| 214 | 214 | { |
| 215 | 215 | // Extract fonts, partly based on wp rocket's extraction code. |
| 216 | - $markup = preg_replace( '/<!--(.*)-->/Uis', '', $in ); |
|
| 217 | - preg_match_all( '#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches ); |
|
| 216 | + $markup = preg_replace('/<!--(.*)-->/Uis', '', $in); |
|
| 217 | + preg_match_all('#<link(?:\s+(?:(?!href\s*=\s*)[^>])+)?(?:\s+href\s*=\s*([\'"])((?:https?:)?\/\/fonts\.googleapis\.com\/css(?:(?!\1).)+)\1)(?:\s+[^>]*)?>#iU', $markup, $matches); |
|
| 218 | 218 | |
| 219 | 219 | $fonts_collection = array(); |
| 220 | - if ( ! $matches[2] ) { |
|
| 220 | + if (!$matches[2]) { |
|
| 221 | 221 | return $in; |
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | // Store them in $fonts array. |
| 225 | 225 | $i = 0; |
| 226 | - foreach ( $matches[2] as $font ) { |
|
| 227 | - if ( ! preg_match( '/rel=["\']dns-prefetch["\']/', $matches[0][ $i ] ) ) { |
|
| 226 | + foreach ($matches[2] as $font) { |
|
| 227 | + if (!preg_match('/rel=["\']dns-prefetch["\']/', $matches[0][$i])) { |
|
| 228 | 228 | // Get fonts name. |
| 229 | - $font = str_replace( array( '%7C', '%7c' ), '|', $font ); |
|
| 230 | - $font = explode( 'family=', $font ); |
|
| 231 | - $font = ( isset( $font[1] ) ) ? explode( '&', $font[1] ) : array(); |
|
| 229 | + $font = str_replace(array('%7C', '%7c'), '|', $font); |
|
| 230 | + $font = explode('family=', $font); |
|
| 231 | + $font = (isset($font[1])) ? explode('&', $font[1]) : array(); |
|
| 232 | 232 | // Add font to $fonts[$i] but make sure not to pollute with an empty family! |
| 233 | - $_thisfont = array_values( array_filter( explode( '|', reset( $font ) ) ) ); |
|
| 234 | - if ( ! empty( $_thisfont ) ) { |
|
| 235 | - $fonts_collection[ $i ]['fonts'] = $_thisfont; |
|
| 233 | + $_thisfont = array_values(array_filter(explode('|', reset($font)))); |
|
| 234 | + if (!empty($_thisfont)) { |
|
| 235 | + $fonts_collection[$i]['fonts'] = $_thisfont; |
|
| 236 | 236 | // And add subset if any! |
| 237 | - $subset = ( is_array( $font ) ) ? end( $font ) : ''; |
|
| 238 | - if ( false !== strpos( $subset, 'subset=' ) ) { |
|
| 239 | - $subset = str_replace( array( '%2C', '%2c' ), ',', $subset ); |
|
| 240 | - $subset = explode( 'subset=', $subset ); |
|
| 241 | - $fonts_collection[ $i ]['subsets'] = explode( ',', $subset[1] ); |
|
| 237 | + $subset = (is_array($font)) ? end($font) : ''; |
|
| 238 | + if (false !== strpos($subset, 'subset=')) { |
|
| 239 | + $subset = str_replace(array('%2C', '%2c'), ',', $subset); |
|
| 240 | + $subset = explode('subset=', $subset); |
|
| 241 | + $fonts_collection[$i]['subsets'] = explode(',', $subset[1]); |
|
| 242 | 242 | } |
| 243 | 243 | } |
| 244 | 244 | // And remove Google Fonts. |
| 245 | - $in = str_replace( $matches[0][ $i ], '', $in ); |
|
| 245 | + $in = str_replace($matches[0][$i], '', $in); |
|
| 246 | 246 | } |
| 247 | 247 | $i++; |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | $options = $this->options; |
| 251 | 251 | $fonts_markup = ''; |
| 252 | - if ( '2' === $options['autoptimize_extra_radio_field_4'] ) { |
|
| 252 | + if ('2' === $options['autoptimize_extra_radio_field_4']) { |
|
| 253 | 253 | // Remove Google Fonts. |
| 254 | - unset( $fonts_collection ); |
|
| 254 | + unset($fonts_collection); |
|
| 255 | 255 | return $in; |
| 256 | - } elseif ( '3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4'] ) { |
|
| 256 | + } elseif ('3' === $options['autoptimize_extra_radio_field_4'] || '5' === $options['autoptimize_extra_radio_field_4']) { |
|
| 257 | 257 | // Aggregate & link! |
| 258 | 258 | $fonts_string = ''; |
| 259 | 259 | $subset_string = ''; |
| 260 | - foreach ( $fonts_collection as $font ) { |
|
| 261 | - $fonts_string .= '|' . trim( implode( '|', $font['fonts'] ), '|' ); |
|
| 262 | - if ( ! empty( $font['subsets'] ) ) { |
|
| 263 | - $subset_string .= ',' . trim( implode( ',', $font['subsets'] ), ',' ); |
|
| 260 | + foreach ($fonts_collection as $font) { |
|
| 261 | + $fonts_string .= '|'.trim(implode('|', $font['fonts']), '|'); |
|
| 262 | + if (!empty($font['subsets'])) { |
|
| 263 | + $subset_string .= ','.trim(implode(',', $font['subsets']), ','); |
|
| 264 | 264 | } |
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - if ( ! empty( $subset_string ) ) { |
|
| 268 | - $subset_string = str_replace( ',', '%2C', ltrim( $subset_string, ',' ) ); |
|
| 269 | - $fonts_string = $fonts_string . '&subset=' . $subset_string; |
|
| 267 | + if (!empty($subset_string)) { |
|
| 268 | + $subset_string = str_replace(',', '%2C', ltrim($subset_string, ',')); |
|
| 269 | + $fonts_string = $fonts_string.'&subset='.$subset_string; |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - $fonts_string = apply_filters( 'autoptimize_filter_extra_gfont_fontstring', str_replace( '|', '%7C', ltrim( $fonts_string, '|' ) ) ); |
|
| 272 | + $fonts_string = apply_filters('autoptimize_filter_extra_gfont_fontstring', str_replace('|', '%7C', ltrim($fonts_string, '|'))); |
|
| 273 | 273 | // only add display parameter if there is none in $fonts_string (by virtue of the filter). |
| 274 | - if ( strpos( $fonts_string, 'display=' ) === false ) { |
|
| 275 | - $fonts_string .= apply_filters( 'autoptimize_filter_extra_gfont_display', '&display=swap' ); |
|
| 274 | + if (strpos($fonts_string, 'display=') === false) { |
|
| 275 | + $fonts_string .= apply_filters('autoptimize_filter_extra_gfont_display', '&display=swap'); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | - if ( ! empty( $fonts_string ) ) { |
|
| 279 | - if ( '5' === $options['autoptimize_extra_radio_field_4'] ) { |
|
| 280 | - $rel_string = 'rel="preload" as="style" onload="' . autoptimizeConfig::get_ao_css_preload_onload() . '"'; |
|
| 278 | + if (!empty($fonts_string)) { |
|
| 279 | + if ('5' === $options['autoptimize_extra_radio_field_4']) { |
|
| 280 | + $rel_string = 'rel="preload" as="style" onload="'.autoptimizeConfig::get_ao_css_preload_onload().'"'; |
|
| 281 | 281 | } else { |
| 282 | 282 | $rel_string = 'rel="stylesheet"'; |
| 283 | 283 | } |
| 284 | - $fonts_markup = '<link ' . $rel_string . ' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family=' . $fonts_string . '" />'; |
|
| 284 | + $fonts_markup = '<link '.$rel_string.' id="ao_optimized_gfonts" href="https://fonts.googleapis.com/css?family='.$fonts_string.'" />'; |
|
| 285 | 285 | } |
| 286 | - } elseif ( '4' === $options['autoptimize_extra_radio_field_4'] ) { |
|
| 286 | + } elseif ('4' === $options['autoptimize_extra_radio_field_4']) { |
|
| 287 | 287 | // Aggregate & load async (webfont.js impl.)! |
| 288 | 288 | $fonts_array = array(); |
| 289 | - foreach ( $fonts_collection as $_fonts ) { |
|
| 290 | - if ( ! empty( $_fonts['subsets'] ) ) { |
|
| 291 | - $_subset = implode( ',', $_fonts['subsets'] ); |
|
| 292 | - foreach ( $_fonts['fonts'] as $key => $_one_font ) { |
|
| 293 | - $_one_font = $_one_font . ':' . $_subset; |
|
| 294 | - $_fonts['fonts'][ $key ] = $_one_font; |
|
| 289 | + foreach ($fonts_collection as $_fonts) { |
|
| 290 | + if (!empty($_fonts['subsets'])) { |
|
| 291 | + $_subset = implode(',', $_fonts['subsets']); |
|
| 292 | + foreach ($_fonts['fonts'] as $key => $_one_font) { |
|
| 293 | + $_one_font = $_one_font.':'.$_subset; |
|
| 294 | + $_fonts['fonts'][$key] = $_one_font; |
|
| 295 | 295 | } |
| 296 | 296 | } |
| 297 | - $fonts_array = array_merge( $fonts_array, $_fonts['fonts'] ); |
|
| 297 | + $fonts_array = array_merge($fonts_array, $_fonts['fonts']); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - $fonts_array = array_map( 'urldecode', $fonts_array ); |
|
| 300 | + $fonts_array = array_map('urldecode', $fonts_array); |
|
| 301 | 301 | $fonts_array = array_map( |
| 302 | - function( $_f ) { |
|
| 303 | - return trim( $_f, ',' ); |
|
| 302 | + function($_f) { |
|
| 303 | + return trim($_f, ','); |
|
| 304 | 304 | }, |
| 305 | 305 | $fonts_array |
| 306 | 306 | ); |
| 307 | 307 | |
| 308 | 308 | // type attrib on <script not added by default. |
| 309 | 309 | $type_js = ''; |
| 310 | - if ( apply_filters( 'autoptimize_filter_cssjs_addtype', false ) ) { |
|
| 310 | + if (apply_filters('autoptimize_filter_cssjs_addtype', false)) { |
|
| 311 | 311 | $type_js = 'type="text/javascript" '; |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - $fonts_markup = '<script ' . $type_js . 'data-cfasync="false" id="ao_optimized_gfonts_config">WebFontConfig={google:{families:' . wp_json_encode( $fonts_array ) . ' },classes:false, events:false, timeout:1500};</script>'; |
|
| 315 | - $fonts_library_markup = '<script ' . $type_js . 'data-cfasync="false" id="ao_optimized_gfonts_webfontloader">(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>'; |
|
| 316 | - $in = substr_replace( $in, $fonts_library_markup . '</head>', strpos( $in, '</head>' ), strlen( '</head>' ) ); |
|
| 314 | + $fonts_markup = '<script '.$type_js.'data-cfasync="false" id="ao_optimized_gfonts_config">WebFontConfig={google:{families:'.wp_json_encode($fonts_array).' },classes:false, events:false, timeout:1500};</script>'; |
|
| 315 | + $fonts_library_markup = '<script '.$type_js.'data-cfasync="false" id="ao_optimized_gfonts_webfontloader">(function() {var wf = document.createElement(\'script\');wf.src=\'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js\';wf.type=\'text/javascript\';wf.async=\'true\';var s=document.getElementsByTagName(\'script\')[0];s.parentNode.insertBefore(wf, s);})();</script>'; |
|
| 316 | + $in = substr_replace($in, $fonts_library_markup.'</head>', strpos($in, '</head>'), strlen('</head>')); |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | // Replace back in markup. |
| 320 | - $inject_point = apply_filters( 'autoptimize_filter_extra_gfont_injectpoint', '<link' ); |
|
| 321 | - $out = substr_replace( $in, $fonts_markup . $inject_point, strpos( $in, $inject_point ), strlen( $inject_point ) ); |
|
| 322 | - unset( $fonts_collection ); |
|
| 320 | + $inject_point = apply_filters('autoptimize_filter_extra_gfont_injectpoint', '<link'); |
|
| 321 | + $out = substr_replace($in, $fonts_markup.$inject_point, strpos($in, $inject_point), strlen($inject_point)); |
|
| 322 | + unset($fonts_collection); |
|
| 323 | 323 | |
| 324 | 324 | // and insert preload polyfill if "link preload" and if the polyfill isn't there yet (courtesy of inline&defer). |
| 325 | 325 | $preload_polyfill = autoptimizeConfig::get_ao_css_preload_polyfill(); |
| 326 | - if ( '5' === $options['autoptimize_extra_radio_field_4'] && strpos( $out, $preload_polyfill ) === false ) { |
|
| 327 | - $out = str_replace( '</body>', $preload_polyfill . '</body>', $out ); |
|
| 326 | + if ('5' === $options['autoptimize_extra_radio_field_4'] && strpos($out, $preload_polyfill) === false) { |
|
| 327 | + $out = str_replace('</body>', $preload_polyfill.'</body>', $out); |
|
| 328 | 328 | } |
| 329 | 329 | return $out; |
| 330 | 330 | } |
| 331 | 331 | |
| 332 | - public function filter_preconnect( $hints, $relation_type ) |
|
| 332 | + public function filter_preconnect($hints, $relation_type) |
|
| 333 | 333 | { |
| 334 | 334 | $options = $this->options; |
| 335 | 335 | $preconns = array(); |
| 336 | 336 | |
| 337 | 337 | // Get settings and store in array. |
| 338 | - if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) { |
|
| 339 | - $preconns = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_2'] ) ) ); |
|
| 338 | + if (array_key_exists('autoptimize_extra_text_field_2', $options)) { |
|
| 339 | + $preconns = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_2']))); |
|
| 340 | 340 | } |
| 341 | - $preconns = apply_filters( 'autoptimize_extra_filter_tobepreconn', $preconns ); |
|
| 341 | + $preconns = apply_filters('autoptimize_extra_filter_tobepreconn', $preconns); |
|
| 342 | 342 | |
| 343 | 343 | // Walk array, extract domain and add to new array with crossorigin attribute. |
| 344 | - foreach ( $preconns as $preconn ) { |
|
| 344 | + foreach ($preconns as $preconn) { |
|
| 345 | 345 | $domain = ''; |
| 346 | - $parsed = parse_url( $preconn ); |
|
| 347 | - if ( is_array( $parsed ) && ! empty( $parsed['host'] ) && empty( $parsed['scheme'] ) ) { |
|
| 348 | - $domain = '//' . $parsed['host']; |
|
| 349 | - } elseif ( is_array( $parsed ) && ! empty( $parsed['host'] ) ) { |
|
| 350 | - $domain = $parsed['scheme'] . '://' . $parsed['host']; |
|
| 346 | + $parsed = parse_url($preconn); |
|
| 347 | + if (is_array($parsed) && !empty($parsed['host']) && empty($parsed['scheme'])) { |
|
| 348 | + $domain = '//'.$parsed['host']; |
|
| 349 | + } elseif (is_array($parsed) && !empty($parsed['host'])) { |
|
| 350 | + $domain = $parsed['scheme'].'://'.$parsed['host']; |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - if ( ! empty( $domain ) ) { |
|
| 354 | - $hint = array( 'href' => $domain ); |
|
| 353 | + if (!empty($domain)) { |
|
| 354 | + $hint = array('href' => $domain); |
|
| 355 | 355 | // Fonts don't get preconnected unless crossorigin flag is set, non-fonts don't get preconnected if origin flag is set |
| 356 | 356 | // so hardcode fonts.gstatic.com to come with crossorigin and have filter to add other domains if needed. |
| 357 | - $crossorigins = apply_filters( 'autoptimize_extra_filter_preconn_crossorigin', array( 'https://fonts.gstatic.com' ) ); |
|
| 358 | - if ( in_array( $domain, $crossorigins ) ) { |
|
| 357 | + $crossorigins = apply_filters('autoptimize_extra_filter_preconn_crossorigin', array('https://fonts.gstatic.com')); |
|
| 358 | + if (in_array($domain, $crossorigins)) { |
|
| 359 | 359 | $hint['crossorigin'] = 'anonymous'; |
| 360 | 360 | } |
| 361 | 361 | $new_hints[] = $hint; |
@@ -363,21 +363,21 @@ discard block |
||
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | // Merge in WP's preconnect hints. |
| 366 | - if ( 'preconnect' === $relation_type && ! empty( $new_hints ) ) { |
|
| 367 | - $hints = array_merge( $hints, $new_hints ); |
|
| 366 | + if ('preconnect' === $relation_type && !empty($new_hints)) { |
|
| 367 | + $hints = array_merge($hints, $new_hints); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | return $hints; |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | - public function filter_preconnect_google_fonts( $in ) |
|
| 373 | + public function filter_preconnect_google_fonts($in) |
|
| 374 | 374 | { |
| 375 | - if ( '2' !== $this->options['autoptimize_extra_radio_field_4'] ) { |
|
| 375 | + if ('2' !== $this->options['autoptimize_extra_radio_field_4']) { |
|
| 376 | 376 | // Preconnect to fonts.gstatic.com unless we remove gfonts. |
| 377 | 377 | $in[] = 'https://fonts.gstatic.com'; |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - if ( '4' === $this->options['autoptimize_extra_radio_field_4'] ) { |
|
| 380 | + if ('4' === $this->options['autoptimize_extra_radio_field_4']) { |
|
| 381 | 381 | // Preconnect even more hosts for webfont.js! |
| 382 | 382 | $in[] = 'https://ajax.googleapis.com'; |
| 383 | 383 | $in[] = 'https://fonts.googleapis.com'; |
@@ -386,75 +386,75 @@ discard block |
||
| 386 | 386 | return $in; |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - public function filter_preload( $in ) { |
|
| 389 | + public function filter_preload($in) { |
|
| 390 | 390 | // make array from comma separated list. |
| 391 | 391 | $options = $this->options; |
| 392 | 392 | $preloads = array(); |
| 393 | - if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) { |
|
| 394 | - $preloads = array_filter( array_map( 'trim', explode( ',', $options['autoptimize_extra_text_field_7'] ) ) ); |
|
| 393 | + if (array_key_exists('autoptimize_extra_text_field_7', $options)) { |
|
| 394 | + $preloads = array_filter(array_map('trim', explode(',', $options['autoptimize_extra_text_field_7']))); |
|
| 395 | 395 | } |
| 396 | - $preloads = apply_filters( 'autoptimize_filter_extra_tobepreloaded', $preloads ); |
|
| 396 | + $preloads = apply_filters('autoptimize_filter_extra_tobepreloaded', $preloads); |
|
| 397 | 397 | |
| 398 | 398 | // immediately return if nothing to be preloaded. |
| 399 | - if ( empty( $preloads ) ) { |
|
| 399 | + if (empty($preloads)) { |
|
| 400 | 400 | return $in; |
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | // iterate through array and add preload link to tmp string. |
| 404 | 404 | $preload_output = ''; |
| 405 | - foreach ( $preloads as $preload ) { |
|
| 405 | + foreach ($preloads as $preload) { |
|
| 406 | 406 | $crossorigin = ''; |
| 407 | 407 | $preload_as = ''; |
| 408 | 408 | $mime_type = ''; |
| 409 | 409 | |
| 410 | - if ( autoptimizeUtils::str_ends_in( $preload, '.css' ) ) { |
|
| 410 | + if (autoptimizeUtils::str_ends_in($preload, '.css')) { |
|
| 411 | 411 | $preload_as = 'style'; |
| 412 | - } elseif ( autoptimizeUtils::str_ends_in( $preload, '.js' ) ) { |
|
| 412 | + } elseif (autoptimizeUtils::str_ends_in($preload, '.js')) { |
|
| 413 | 413 | $preload_as = 'script'; |
| 414 | - } elseif ( autoptimizeUtils::str_ends_in( $preload, '.woff' ) || autoptimizeUtils::str_ends_in( $preload, '.woff2' ) || autoptimizeUtils::str_ends_in( $preload, '.ttf' ) || autoptimizeUtils::str_ends_in( $preload, '.eot' ) ) { |
|
| 414 | + } elseif (autoptimizeUtils::str_ends_in($preload, '.woff') || autoptimizeUtils::str_ends_in($preload, '.woff2') || autoptimizeUtils::str_ends_in($preload, '.ttf') || autoptimizeUtils::str_ends_in($preload, '.eot')) { |
|
| 415 | 415 | $preload_as = 'font'; |
| 416 | 416 | $crossorigin = ' crossorigin'; |
| 417 | - $mime_type = ' type="font/' . pathinfo( $preload, PATHINFO_EXTENSION ) . '"'; |
|
| 418 | - if ( ' type="font/eot"' === $mime_type ) { |
|
| 417 | + $mime_type = ' type="font/'.pathinfo($preload, PATHINFO_EXTENSION).'"'; |
|
| 418 | + if (' type="font/eot"' === $mime_type) { |
|
| 419 | 419 | $mime_type = 'application/vnd.ms-fontobject'; |
| 420 | 420 | } |
| 421 | - } elseif ( autoptimizeUtils::str_ends_in( $preload, '.jpeg' ) || autoptimizeUtils::str_ends_in( $preload, '.jpg' ) || autoptimizeUtils::str_ends_in( $preload, '.webp' ) || autoptimizeUtils::str_ends_in( $preload, '.png' ) || autoptimizeUtils::str_ends_in( $preload, '.gif' ) ) { |
|
| 421 | + } elseif (autoptimizeUtils::str_ends_in($preload, '.jpeg') || autoptimizeUtils::str_ends_in($preload, '.jpg') || autoptimizeUtils::str_ends_in($preload, '.webp') || autoptimizeUtils::str_ends_in($preload, '.png') || autoptimizeUtils::str_ends_in($preload, '.gif')) { |
|
| 422 | 422 | $preload_as = 'image'; |
| 423 | 423 | } else { |
| 424 | 424 | $preload_as = 'other'; |
| 425 | 425 | } |
| 426 | 426 | |
| 427 | - $preload_output .= '<link rel="preload" href="' . $preload . '" as="' . $preload_as . '"' . $mime_type . $crossorigin . '>'; |
|
| 427 | + $preload_output .= '<link rel="preload" href="'.$preload.'" as="'.$preload_as.'"'.$mime_type.$crossorigin.'>'; |
|
| 428 | 428 | } |
| 429 | - $preload_output = apply_filters( 'autoptimize_filter_extra_preload_output', $preload_output ); |
|
| 429 | + $preload_output = apply_filters('autoptimize_filter_extra_preload_output', $preload_output); |
|
| 430 | 430 | |
| 431 | 431 | // add string to head (before first link node by default). |
| 432 | - $preload_inject = apply_filters( 'autoptimize_filter_extra_preload_inject', '<link' ); |
|
| 433 | - $position = autoptimizeUtils::strpos( $in, $preload_inject ); |
|
| 432 | + $preload_inject = apply_filters('autoptimize_filter_extra_preload_inject', '<link'); |
|
| 433 | + $position = autoptimizeUtils::strpos($in, $preload_inject); |
|
| 434 | 434 | |
| 435 | - return autoptimizeUtils::substr_replace( $in, $preload_output . $preload_inject, $position, strlen( $preload_inject ) ); |
|
| 435 | + return autoptimizeUtils::substr_replace($in, $preload_output.$preload_inject, $position, strlen($preload_inject)); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | public function admin_menu() |
| 439 | 439 | { |
| 440 | 440 | // no acces if multisite and not network admin and no site config allowed. |
| 441 | - if ( autoptimizeConfig::should_show_menu_tabs() ) { |
|
| 441 | + if (autoptimizeConfig::should_show_menu_tabs()) { |
|
| 442 | 442 | add_submenu_page( |
| 443 | 443 | null, |
| 444 | 444 | 'autoptimize_extra', |
| 445 | 445 | 'autoptimize_extra', |
| 446 | 446 | 'manage_options', |
| 447 | 447 | 'autoptimize_extra', |
| 448 | - array( $this, 'options_page' ) |
|
| 448 | + array($this, 'options_page') |
|
| 449 | 449 | ); |
| 450 | - register_setting( 'autoptimize_extra_settings', 'autoptimize_extra_settings' ); |
|
| 450 | + register_setting('autoptimize_extra_settings', 'autoptimize_extra_settings'); |
|
| 451 | 451 | } |
| 452 | 452 | } |
| 453 | 453 | |
| 454 | - public function add_extra_tab( $in ) |
|
| 454 | + public function add_extra_tab($in) |
|
| 455 | 455 | { |
| 456 | - if ( autoptimizeConfig::should_show_menu_tabs() ) { |
|
| 457 | - $in = array_merge( $in, array( 'autoptimize_extra' => __( 'Extra', 'autoptimize' ) ) ); |
|
| 456 | + if (autoptimizeConfig::should_show_menu_tabs()) { |
|
| 457 | + $in = array_merge($in, array('autoptimize_extra' => __('Extra', 'autoptimize'))); |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | return $in; |
@@ -474,97 +474,97 @@ discard block |
||
| 474 | 474 | #ao_settings_form .form-table th {font-weight: normal;} |
| 475 | 475 | #autoptimize_extra_descr{font-size: 120%;} |
| 476 | 476 | </style> |
| 477 | - <script>document.title = "Autoptimize: <?php _e( 'Extra', 'autoptimize' ); ?> " + document.title;</script> |
|
| 477 | + <script>document.title = "Autoptimize: <?php _e('Extra', 'autoptimize'); ?> " + document.title;</script> |
|
| 478 | 478 | <div class="wrap"> |
| 479 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
| 479 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
| 480 | 480 | <?php echo autoptimizeConfig::ao_admin_tabs(); ?> |
| 481 | - <?php if ( 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) && ! autoptimizeImages::imgopt_active() ) { ?> |
|
| 481 | + <?php if ('on' !== autoptimizeOptionWrapper::get_option('autoptimize_js') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_css') && 'on' !== autoptimizeOptionWrapper::get_option('autoptimize_html') && !autoptimizeImages::imgopt_active()) { ?> |
|
| 482 | 482 | <div class="notice-warning notice"><p> |
| 483 | - <?php _e( 'Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize' ); ?> |
|
| 483 | + <?php _e('Most of below Extra optimizations require at least one of HTML, JS, CSS or Image autoptimizations being active.', 'autoptimize'); ?> |
|
| 484 | 484 | </p></div> |
| 485 | 485 | <?php } ?> |
| 486 | 486 | |
| 487 | - <form id='ao_settings_form' action='<?php echo admin_url( 'options.php' ); ?>' method='post'> |
|
| 488 | - <?php settings_fields( 'autoptimize_extra_settings' ); ?> |
|
| 489 | - <h2><?php _e( 'Extra Auto-Optimizations', 'autoptimize' ); ?></h2> |
|
| 490 | - <span id='autoptimize_extra_descr'><?php _e( 'The following settings can improve your site\'s performance even more.', 'autoptimize' ); ?></span> |
|
| 487 | + <form id='ao_settings_form' action='<?php echo admin_url('options.php'); ?>' method='post'> |
|
| 488 | + <?php settings_fields('autoptimize_extra_settings'); ?> |
|
| 489 | + <h2><?php _e('Extra Auto-Optimizations', 'autoptimize'); ?></h2> |
|
| 490 | + <span id='autoptimize_extra_descr'><?php _e('The following settings can improve your site\'s performance even more.', 'autoptimize'); ?></span> |
|
| 491 | 491 | <table class="form-table"> |
| 492 | 492 | <tr> |
| 493 | - <th scope="row"><?php _e( 'Google Fonts', 'autoptimize' ); ?></th> |
|
| 493 | + <th scope="row"><?php _e('Google Fonts', 'autoptimize'); ?></th> |
|
| 494 | 494 | <td> |
| 495 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if ( ! in_array( $gfonts, array( 2, 3, 4, 5 ) ) ) { echo 'checked'; } ?> ><?php _e( 'Leave as is', 'autoptimize' ); ?><br/> |
|
| 496 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked( 2, $gfonts, true ); ?> ><?php _e( 'Remove Google Fonts', 'autoptimize' ); ?><br/> |
|
| 495 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="1" <?php if (!in_array($gfonts, array(2, 3, 4, 5))) { echo 'checked'; } ?> ><?php _e('Leave as is', 'autoptimize'); ?><br/> |
|
| 496 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="2" <?php checked(2, $gfonts, true); ?> ><?php _e('Remove Google Fonts', 'autoptimize'); ?><br/> |
|
| 497 | 497 | <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?> |
| 498 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked( 3, $gfonts, true ); ?> ><?php echo __( 'Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize' ) . ', ' . sprintf( __( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?><br/> |
|
| 498 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="3" <?php checked(3, $gfonts, true); ?> ><?php echo __('Combine and link in head (fonts load fast but are render-blocking)', 'autoptimize').', '.sprintf(__('includes %1$sdisplay:swap%2$s.', 'autoptimize'), '<code>', '</code>'); ?><br/> |
|
| 499 | 499 | <?php // translators: "display:swap" should remain untranslated, will be shown in code tags. ?> |
| 500 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked( 5, $gfonts, true ); ?> ><?php echo __( 'Combine and preload in head (fonts load late, but are not render-blocking)', 'autoptimize' ) . ', ' . sprintf( __( 'includes %1$sdisplay:swap%2$s.', 'autoptimize' ), '<code>', '</code>' ); ?><br/> |
|
| 501 | - <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked( 4, $gfonts, true ); ?> ><?php _e( 'Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize' ); ?><br/> |
|
| 500 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="5" <?php checked(5, $gfonts, true); ?> ><?php echo __('Combine and preload in head (fonts load late, but are not render-blocking)', 'autoptimize').', '.sprintf(__('includes %1$sdisplay:swap%2$s.', 'autoptimize'), '<code>', '</code>'); ?><br/> |
|
| 501 | + <input type="radio" name="autoptimize_extra_settings[autoptimize_extra_radio_field_4]" value="4" <?php checked(4, $gfonts, true); ?> ><?php _e('Combine and load fonts asynchronously with <a href="https://github.com/typekit/webfontloader#readme" target="_blank">webfont.js</a>', 'autoptimize'); ?><br/> |
|
| 502 | 502 | </td> |
| 503 | 503 | </tr> |
| 504 | 504 | <tr> |
| 505 | - <th scope="row"><?php _e( 'Remove emojis', 'autoptimize' ); ?></th> |
|
| 505 | + <th scope="row"><?php _e('Remove emojis', 'autoptimize'); ?></th> |
|
| 506 | 506 | <td> |
| 507 | - <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_1'] ) && '1' === $options['autoptimize_extra_checkbox_field_1'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize' ); ?></label> |
|
| 507 | + <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_1]' <?php if (!empty($options['autoptimize_extra_checkbox_field_1']) && '1' === $options['autoptimize_extra_checkbox_field_1']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Removes WordPress\' core emojis\' inline CSS, inline JavaScript, and an otherwise un-autoptimized JavaScript file.', 'autoptimize'); ?></label> |
|
| 508 | 508 | </td> |
| 509 | 509 | </tr> |
| 510 | 510 | <tr> |
| 511 | - <th scope="row"><?php _e( 'Remove query strings from static resources', 'autoptimize' ); ?></th> |
|
| 511 | + <th scope="row"><?php _e('Remove query strings from static resources', 'autoptimize'); ?></th> |
|
| 512 | 512 | <td> |
| 513 | - <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if ( ! empty( $options['autoptimize_extra_checkbox_field_0'] ) && '1' === $options['autoptimize_extra_checkbox_field_0'] ) { echo 'checked="checked"'; } ?> value='1'><?php _e( 'Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize' ); ?></label> |
|
| 513 | + <label><input type='checkbox' name='autoptimize_extra_settings[autoptimize_extra_checkbox_field_0]' <?php if (!empty($options['autoptimize_extra_checkbox_field_0']) && '1' === $options['autoptimize_extra_checkbox_field_0']) { echo 'checked="checked"'; } ?> value='1'><?php _e('Removing query strings (or more specifically the <code>ver</code> parameter) will not improve load time, but might improve performance scores.', 'autoptimize'); ?></label> |
|
| 514 | 514 | </td> |
| 515 | 515 | </tr> |
| 516 | 516 | <tr> |
| 517 | - <th scope="row"><?php _e( 'Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize' ); ?></th> |
|
| 517 | + <th scope="row"><?php _e('Preconnect to 3rd party domains <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
| 518 | 518 | <td> |
| 519 | - <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_2', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_2'] ); } ?>'><br /><?php _e( 'Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize' ); ?></label> |
|
| 519 | + <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_2]' value='<?php if (array_key_exists('autoptimize_extra_text_field_2', $options)) { echo esc_attr($options['autoptimize_extra_text_field_2']); } ?>'><br /><?php _e('Add 3rd party domains you want the browser to <a href="https://www.keycdn.com/support/preconnect/#primary" target="_blank">preconnect</a> to, separated by comma\'s. Make sure to include the correct protocol (HTTP or HTTPS).', 'autoptimize'); ?></label> |
|
| 520 | 520 | </td> |
| 521 | 521 | </tr> |
| 522 | 522 | <tr> |
| 523 | - <th scope="row"><?php _e( 'Preload specific requests <em>(advanced users)</em>', 'autoptimize' ); ?></th> |
|
| 523 | + <th scope="row"><?php _e('Preload specific requests <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
| 524 | 524 | <td> |
| 525 | - <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_7]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_7', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_7'] ); } ?>'><br /><?php _e( 'Comma-separated list with full URL\'s of to to-be-preloaded resources. To be used sparingly!', 'autoptimize' ); ?></label> |
|
| 525 | + <label><input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_7]' value='<?php if (array_key_exists('autoptimize_extra_text_field_7', $options)) { echo esc_attr($options['autoptimize_extra_text_field_7']); } ?>'><br /><?php _e('Comma-separated list with full URL\'s of to to-be-preloaded resources. To be used sparingly!', 'autoptimize'); ?></label> |
|
| 526 | 526 | </td> |
| 527 | 527 | </tr> |
| 528 | 528 | <tr> |
| 529 | - <th scope="row"><?php _e( 'Async Javascript-files <em>(advanced users)</em>', 'autoptimize' ); ?></th> |
|
| 529 | + <th scope="row"><?php _e('Async Javascript-files <em>(advanced users)</em>', 'autoptimize'); ?></th> |
|
| 530 | 530 | <td> |
| 531 | 531 | <?php |
| 532 | - if ( autoptimizeUtils::is_plugin_active( 'async-javascript/async-javascript.php' ) ) { |
|
| 532 | + if (autoptimizeUtils::is_plugin_active('async-javascript/async-javascript.php')) { |
|
| 533 | 533 | // translators: link points Async Javascript settings page. |
| 534 | - printf( __( 'You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize' ), '<a href="' . 'options-general.php?page=async-javascript' . '">', '</a>' ); |
|
| 534 | + printf(__('You have "Async JavaScript" installed, %1$sconfiguration of async javascript is best done there%2$s.', 'autoptimize'), '<a href="'.'options-general.php?page=async-javascript'.'">', '</a>'); |
|
| 535 | 535 | } else { |
| 536 | 536 | ?> |
| 537 | - <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if ( array_key_exists( 'autoptimize_extra_text_field_3', $options ) ) { echo esc_attr( $options['autoptimize_extra_text_field_3'] ); } ?>'> |
|
| 537 | + <input type='text' style='width:80%' name='autoptimize_extra_settings[autoptimize_extra_text_field_3]' value='<?php if (array_key_exists('autoptimize_extra_text_field_3', $options)) { echo esc_attr($options['autoptimize_extra_text_field_3']); } ?>'> |
|
| 538 | 538 | <br /> |
| 539 | 539 | <?php |
| 540 | - _e( 'Comma-separated list of local or 3rd party JS-files that should loaded with the <code>async</code> flag. JS-files from your own site will be automatically excluded if added here. ', 'autoptimize' ); |
|
| 540 | + _e('Comma-separated list of local or 3rd party JS-files that should loaded with the <code>async</code> flag. JS-files from your own site will be automatically excluded if added here. ', 'autoptimize'); |
|
| 541 | 541 | // translators: %s will be replaced by a link to the "async javascript" plugin. |
| 542 | - echo sprintf( __( 'Configuration of async javascript is easier and more flexible using the %s plugin.', 'autoptimize' ), '"<a href="https://wordpress.org/plugins/async-javascript" target="_blank">Async Javascript</a>"' ); |
|
| 543 | - $asj_install_url = network_admin_url() . 'plugin-install.php?s=async+javascript&tab=search&type=term'; |
|
| 544 | - echo sprintf( ' <a href="' . $asj_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) ); |
|
| 542 | + echo sprintf(__('Configuration of async javascript is easier and more flexible using the %s plugin.', 'autoptimize'), '"<a href="https://wordpress.org/plugins/async-javascript" target="_blank">Async Javascript</a>"'); |
|
| 543 | + $asj_install_url = network_admin_url().'plugin-install.php?s=async+javascript&tab=search&type=term'; |
|
| 544 | + echo sprintf(' <a href="'.$asj_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize')); |
|
| 545 | 545 | } |
| 546 | 546 | ?> |
| 547 | 547 | </td> |
| 548 | 548 | </tr> |
| 549 | 549 | <tr> |
| 550 | - <th scope="row"><?php _e( 'Optimize YouTube videos', 'autoptimize' ); ?></th> |
|
| 550 | + <th scope="row"><?php _e('Optimize YouTube videos', 'autoptimize'); ?></th> |
|
| 551 | 551 | <td> |
| 552 | 552 | <?php |
| 553 | - if ( autoptimizeUtils::is_plugin_active( 'wp-youtube-lyte/wp-youtube-lyte.php' ) ) { |
|
| 554 | - _e( 'Great, you have WP YouTube Lyte installed.', 'autoptimize' ); |
|
| 553 | + if (autoptimizeUtils::is_plugin_active('wp-youtube-lyte/wp-youtube-lyte.php')) { |
|
| 554 | + _e('Great, you have WP YouTube Lyte installed.', 'autoptimize'); |
|
| 555 | 555 | $lyte_config_url = 'options-general.php?page=lyte_settings_page'; |
| 556 | - echo sprintf( ' <a href="' . $lyte_config_url . '">%s</a>', __( 'Click here to configure it.', 'autoptimize' ) ); |
|
| 556 | + echo sprintf(' <a href="'.$lyte_config_url.'">%s</a>', __('Click here to configure it.', 'autoptimize')); |
|
| 557 | 557 | } else { |
| 558 | 558 | // translators: %s will be replaced by a link to "wp youtube lyte" plugin. |
| 559 | - echo sprintf( __( '%s allows you to “lazy load” your videos, by inserting responsive “Lite YouTube Embeds". ', 'autoptimize' ), '<a href="https://wordpress.org/plugins/wp-youtube-lyte" target="_blank">WP YouTube Lyte</a>' ); |
|
| 560 | - $lyte_install_url = network_admin_url() . 'plugin-install.php?s=lyte&tab=search&type=term'; |
|
| 561 | - echo sprintf( ' <a href="' . $lyte_install_url . '">%s</a>', __( 'Click here to install and activate it.', 'autoptimize' ) ); |
|
| 559 | + echo sprintf(__('%s allows you to “lazy load” your videos, by inserting responsive “Lite YouTube Embeds". ', 'autoptimize'), '<a href="https://wordpress.org/plugins/wp-youtube-lyte" target="_blank">WP YouTube Lyte</a>'); |
|
| 560 | + $lyte_install_url = network_admin_url().'plugin-install.php?s=lyte&tab=search&type=term'; |
|
| 561 | + echo sprintf(' <a href="'.$lyte_install_url.'">%s</a>', __('Click here to install and activate it.', 'autoptimize')); |
|
| 562 | 562 | } |
| 563 | 563 | ?> |
| 564 | 564 | </td> |
| 565 | 565 | </tr> |
| 566 | 566 | </table> |
| 567 | - <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /></p> |
|
| 567 | + <p class="submit"><input type="submit" name="submit" id="submit" class="button button-primary" value="<?php _e('Save Changes', 'autoptimize'); ?>" /></p> |
|
| 568 | 568 | </form> |
| 569 | 569 | <?php |
| 570 | 570 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Autoptimize options handler. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 6 | +if (!defined('ABSPATH')) { |
|
| 7 | 7 | exit; |
| 8 | 8 | } |
| 9 | 9 | |
@@ -21,8 +21,8 @@ discard block |
||
| 21 | 21 | * Ensure that is_plugin_active_for_network function is declared. |
| 22 | 22 | */ |
| 23 | 23 | public static function maybe_include_plugin_functions() { |
| 24 | - if ( ! function_exists( 'is_plugin_active_for_network' ) ) { |
|
| 25 | - include_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
| 24 | + if (!function_exists('is_plugin_active_for_network')) { |
|
| 25 | + include_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
| 26 | 26 | } |
| 27 | 27 | } |
| 28 | 28 | |
@@ -33,19 +33,19 @@ discard block |
||
| 33 | 33 | * @param mixed $default Optional. Default value to return if the option does not exist. |
| 34 | 34 | * @return mixed Value set for the option. |
| 35 | 35 | */ |
| 36 | - public static function get_option( $option, $default = false ) { |
|
| 36 | + public static function get_option($option, $default = false) { |
|
| 37 | 37 | // This is always a network setting. |
| 38 | - if ( 'autoptimize_enable_site_config' === $option ) { |
|
| 39 | - return get_network_option( get_main_network_id(), $option ); |
|
| 38 | + if ('autoptimize_enable_site_config' === $option) { |
|
| 39 | + return get_network_option(get_main_network_id(), $option); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | // If the plugin is network activated and our per site setting is not on, use the network configuration. |
| 43 | - $configuration_per_site = get_network_option( get_main_network_id(), 'autoptimize_enable_site_config' ); |
|
| 44 | - if ( self::is_ao_active_for_network() && ( 'on' !== $configuration_per_site || is_network_admin() ) ) { |
|
| 45 | - return get_network_option( get_main_network_id(), $option ); |
|
| 43 | + $configuration_per_site = get_network_option(get_main_network_id(), 'autoptimize_enable_site_config'); |
|
| 44 | + if (self::is_ao_active_for_network() && ('on' !== $configuration_per_site || is_network_admin())) { |
|
| 45 | + return get_network_option(get_main_network_id(), $option); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | - return get_option( $option, $default ); |
|
| 48 | + return get_option($option, $default); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -59,11 +59,11 @@ discard block |
||
| 59 | 59 | * the default value is 'yes'. Default null. |
| 60 | 60 | * @return bool False if value was not updated and true if value was updated. |
| 61 | 61 | */ |
| 62 | - public static function update_option( $option, $value, $autoload = null ) { |
|
| 63 | - if ( self::is_ao_active_for_network() && is_network_admin() ) { |
|
| 64 | - return update_network_option( get_main_network_id(), $option, $value ); |
|
| 65 | - } elseif ( 'autoptimize_enable_site_config' !== $option ) { |
|
| 66 | - return update_option( $option, $value, $autoload ); |
|
| 62 | + public static function update_option($option, $value, $autoload = null) { |
|
| 63 | + if (self::is_ao_active_for_network() && is_network_admin()) { |
|
| 64 | + return update_network_option(get_main_network_id(), $option, $value); |
|
| 65 | + } elseif ('autoptimize_enable_site_config' !== $option) { |
|
| 66 | + return update_option($option, $value, $autoload); |
|
| 67 | 67 | } |
| 68 | 68 | } |
| 69 | 69 | |
@@ -72,8 +72,8 @@ discard block |
||
| 72 | 72 | * in that case, take care of multisite case. |
| 73 | 73 | */ |
| 74 | 74 | public static function check_multisite_on_saving_options() { |
| 75 | - if ( self::is_ao_active_for_network() ) { |
|
| 76 | - add_filter( 'pre_update_option', 'autoptimizeOptionWrapper::update_autoptimize_option_on_network', 10, 3 ); |
|
| 75 | + if (self::is_ao_active_for_network()) { |
|
| 76 | + add_filter('pre_update_option', 'autoptimizeOptionWrapper::update_autoptimize_option_on_network', 10, 3); |
|
| 77 | 77 | } |
| 78 | 78 | } |
| 79 | 79 | |
@@ -84,16 +84,16 @@ discard block |
||
| 84 | 84 | * @param string $option Option name. |
| 85 | 85 | * @param string $old_value Old value. |
| 86 | 86 | */ |
| 87 | - public static function update_autoptimize_option_on_network( $value, $option, $old_value ) { |
|
| 88 | - if ( strpos( $option, 'autoptimize_' ) === 0 && self::is_options_from_network_admin() ) { |
|
| 89 | - if ( self::is_ao_active_for_network() ) { |
|
| 90 | - update_network_option( get_main_network_id(), $option, $value ); |
|
| 87 | + public static function update_autoptimize_option_on_network($value, $option, $old_value) { |
|
| 88 | + if (strpos($option, 'autoptimize_') === 0 && self::is_options_from_network_admin()) { |
|
| 89 | + if (self::is_ao_active_for_network()) { |
|
| 90 | + update_network_option(get_main_network_id(), $option, $value); |
|
| 91 | 91 | // Return old value, to stop update_option logic. |
| 92 | 92 | return $old_value; |
| 93 | 93 | } |
| 94 | - if ( apply_filters( 'autoptimize_filter_optionwrapper_wp_cache_delete', false ) ) { |
|
| 94 | + if (apply_filters('autoptimize_filter_optionwrapper_wp_cache_delete', false)) { |
|
| 95 | 95 | // in some (rare) cases options seem to get stuck in WP's Object cache, this should clear it there. |
| 96 | - wp_cache_delete( $option ); |
|
| 96 | + wp_cache_delete($option); |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | return $value; |
@@ -107,8 +107,8 @@ discard block |
||
| 107 | 107 | public static function is_options_from_network_admin() { |
| 108 | 108 | static $_really_is_network_admin = null; |
| 109 | 109 | |
| 110 | - if ( null === $_really_is_network_admin ) { |
|
| 111 | - if ( array_key_exists( '_wp_http_referer', $_POST ) && strpos( network_admin_url( 'settings.php' ), strtok( $_POST['_wp_http_referer'], '?' ) ) !== false ) { |
|
| 110 | + if (null === $_really_is_network_admin) { |
|
| 111 | + if (array_key_exists('_wp_http_referer', $_POST) && strpos(network_admin_url('settings.php'), strtok($_POST['_wp_http_referer'], '?')) !== false) { |
|
| 112 | 112 | $_really_is_network_admin = true; |
| 113 | 113 | } else { |
| 114 | 114 | $_really_is_network_admin = false; |
@@ -123,9 +123,9 @@ discard block |
||
| 123 | 123 | */ |
| 124 | 124 | public static function is_ao_active_for_network() { |
| 125 | 125 | static $_is_ao_active_for_network = null; |
| 126 | - if ( null === $_is_ao_active_for_network || defined( 'TEST_MULTISITE_FORCE_AO_ON_NETWORK' ) ) { |
|
| 126 | + if (null === $_is_ao_active_for_network || defined('TEST_MULTISITE_FORCE_AO_ON_NETWORK')) { |
|
| 127 | 127 | self::maybe_include_plugin_functions(); |
| 128 | - if ( is_plugin_active_for_network( 'autoptimize/autoptimize.php' ) || is_plugin_active_for_network( 'autoptimize-beta/autoptimize.php' ) || defined( 'TEST_MULTISITE_FORCE_AO_ON_NETWORK' ) ) { |
|
| 128 | + if (is_plugin_active_for_network('autoptimize/autoptimize.php') || is_plugin_active_for_network('autoptimize-beta/autoptimize.php') || defined('TEST_MULTISITE_FORCE_AO_ON_NETWORK')) { |
|
| 129 | 129 | $_is_ao_active_for_network = true; |
| 130 | 130 | } else { |
| 131 | 131 | $_is_ao_active_for_network = false; |
@@ -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,7 +47,7 @@ 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 ( autoptimizeOptionWrapper::get_option( 'autoptimize_version', 'none' ) == '2.4.2' ) { |
|
| 50 | + if (autoptimizeOptionWrapper::get_option('autoptimize_version', 'none') == '2.4.2') { |
|
| 51 | 51 | $this->upgrade_from_2_4_2(); |
| 52 | 52 | } |
| 53 | 53 | $this->upgrade_from_2_4(); |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | // No break, intentionally, so all upgrades are ran during a single request... |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - if ( true === $major_update ) { |
|
| 58 | + if (true === $major_update) { |
|
| 59 | 59 | $this->on_major_version_update(); |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -67,19 +67,19 @@ discard block |
||
| 67 | 67 | * |
| 68 | 68 | * @param string $target Target version to check against (ie., the currently running one). |
| 69 | 69 | */ |
| 70 | - public static function check_installed_and_update( $target ) |
|
| 70 | + public static function check_installed_and_update($target) |
|
| 71 | 71 | { |
| 72 | - $db_version = autoptimizeOptionWrapper::get_option( 'autoptimize_version', 'none' ); |
|
| 73 | - if ( $db_version !== $target ) { |
|
| 74 | - if ( 'none' === $db_version ) { |
|
| 75 | - add_action( 'admin_notices', 'autoptimizeMain::notice_installed' ); |
|
| 72 | + $db_version = autoptimizeOptionWrapper::get_option('autoptimize_version', 'none'); |
|
| 73 | + if ($db_version !== $target) { |
|
| 74 | + if ('none' === $db_version) { |
|
| 75 | + add_action('admin_notices', 'autoptimizeMain::notice_installed'); |
|
| 76 | 76 | } else { |
| 77 | - $updater = new self( $db_version ); |
|
| 77 | + $updater = new self($db_version); |
|
| 78 | 78 | $updater->run_needed_major_upgrades(); |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // Versions differed, upgrades happened if needed, store the new version. |
| 82 | - autoptimizeOptionWrapper::update_option( 'autoptimize_version', $target ); |
|
| 82 | + autoptimizeOptionWrapper::update_option('autoptimize_version', $target); |
|
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
@@ -90,10 +90,10 @@ discard block |
||
| 90 | 90 | protected function on_major_version_update() |
| 91 | 91 | { |
| 92 | 92 | // The transients guard here prevents stale object caches from busting the cache on every request. |
| 93 | - if ( false == get_transient( 'autoptimize_stale_option_buster' ) ) { |
|
| 94 | - set_transient( 'autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS ); |
|
| 93 | + if (false == get_transient('autoptimize_stale_option_buster')) { |
|
| 94 | + set_transient('autoptimize_stale_option_buster', 'Mamsie & Liessie zehhe: ZWIJH!', HOUR_IN_SECONDS); |
|
| 95 | 95 | autoptimizeCache::clearall(); |
| 96 | - add_action( 'admin_notices', 'autoptimizeMain::notice_updated' ); |
|
| 96 | + add_action('admin_notices', 'autoptimizeMain::notice_updated'); |
|
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | private function upgrade_from_1_6() |
| 104 | 104 | { |
| 105 | 105 | // If user was on version 1.6.x, force advanced options to be shown by default. |
| 106 | - autoptimizeOptionWrapper::update_option( 'autoptimize_show_adv', '1' ); |
|
| 106 | + autoptimizeOptionWrapper::update_option('autoptimize_show_adv', '1'); |
|
| 107 | 107 | |
| 108 | 108 | // And remove old options. |
| 109 | 109 | $to_delete_options = array( |
@@ -115,8 +115,8 @@ discard block |
||
| 115 | 115 | 'autoptimize_cdn_img_url', |
| 116 | 116 | 'autoptimize_css_yui', |
| 117 | 117 | ); |
| 118 | - foreach ( $to_delete_options as $del_opt ) { |
|
| 119 | - delete_option( $del_opt ); |
|
| 118 | + foreach ($to_delete_options as $del_opt) { |
|
| 119 | + delete_option($del_opt); |
|
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | |
@@ -127,29 +127,29 @@ discard block |
||
| 127 | 127 | */ |
| 128 | 128 | private function upgrade_from_1_7() |
| 129 | 129 | { |
| 130 | - if ( ! is_multisite() ) { |
|
| 131 | - $css_exclude = autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude' ); |
|
| 132 | - if ( empty( $css_exclude ) ) { |
|
| 130 | + if (!is_multisite()) { |
|
| 131 | + $css_exclude = autoptimizeOptionWrapper::get_option('autoptimize_css_exclude'); |
|
| 132 | + if (empty($css_exclude)) { |
|
| 133 | 133 | $css_exclude = 'admin-bar.min.css, dashicons.min.css'; |
| 134 | - } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) { |
|
| 134 | + } elseif (false === strpos($css_exclude, 'dashicons.min.css')) { |
|
| 135 | 135 | $css_exclude .= ', dashicons.min.css'; |
| 136 | 136 | } |
| 137 | - autoptimizeOptionWrapper::update_option( 'autoptimize_css_exclude', $css_exclude ); |
|
| 137 | + autoptimizeOptionWrapper::update_option('autoptimize_css_exclude', $css_exclude); |
|
| 138 | 138 | } else { |
| 139 | 139 | global $wpdb; |
| 140 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
| 140 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
| 141 | 141 | $original_blog_id = get_current_blog_id(); |
| 142 | - foreach ( $blog_ids as $blog_id ) { |
|
| 143 | - switch_to_blog( $blog_id ); |
|
| 144 | - $css_exclude = autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude' ); |
|
| 145 | - if ( empty( $css_exclude ) ) { |
|
| 142 | + foreach ($blog_ids as $blog_id) { |
|
| 143 | + switch_to_blog($blog_id); |
|
| 144 | + $css_exclude = autoptimizeOptionWrapper::get_option('autoptimize_css_exclude'); |
|
| 145 | + if (empty($css_exclude)) { |
|
| 146 | 146 | $css_exclude = 'admin-bar.min.css, dashicons.min.css'; |
| 147 | - } elseif ( false === strpos( $css_exclude, 'dashicons.min.css' ) ) { |
|
| 147 | + } elseif (false === strpos($css_exclude, 'dashicons.min.css')) { |
|
| 148 | 148 | $css_exclude .= ', dashicons.min.css'; |
| 149 | 149 | } |
| 150 | - autoptimizeOptionWrapper::update_option( 'autoptimize_css_exclude', $css_exclude ); |
|
| 150 | + autoptimizeOptionWrapper::update_option('autoptimize_css_exclude', $css_exclude); |
|
| 151 | 151 | } |
| 152 | - switch_to_blog( $original_blog_id ); |
|
| 152 | + switch_to_blog($original_blog_id); |
|
| 153 | 153 | } |
| 154 | 154 | } |
| 155 | 155 | |
@@ -161,19 +161,19 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | private function upgrade_from_1_9() |
| 163 | 163 | { |
| 164 | - if ( ! is_multisite() ) { |
|
| 165 | - autoptimizeOptionWrapper::update_option( 'autoptimize_css_include_inline', 'on' ); |
|
| 166 | - autoptimizeOptionWrapper::update_option( 'autoptimize_js_include_inline', 'on' ); |
|
| 164 | + if (!is_multisite()) { |
|
| 165 | + autoptimizeOptionWrapper::update_option('autoptimize_css_include_inline', 'on'); |
|
| 166 | + autoptimizeOptionWrapper::update_option('autoptimize_js_include_inline', 'on'); |
|
| 167 | 167 | } else { |
| 168 | 168 | global $wpdb; |
| 169 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
| 169 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
| 170 | 170 | $original_blog_id = get_current_blog_id(); |
| 171 | - foreach ( $blog_ids as $blog_id ) { |
|
| 172 | - switch_to_blog( $blog_id ); |
|
| 173 | - autoptimizeOptionWrapper::update_option( 'autoptimize_css_include_inline', 'on' ); |
|
| 174 | - autoptimizeOptionWrapper::update_option( 'autoptimize_js_include_inline', 'on' ); |
|
| 171 | + foreach ($blog_ids as $blog_id) { |
|
| 172 | + switch_to_blog($blog_id); |
|
| 173 | + autoptimizeOptionWrapper::update_option('autoptimize_css_include_inline', 'on'); |
|
| 174 | + autoptimizeOptionWrapper::update_option('autoptimize_js_include_inline', 'on'); |
|
| 175 | 175 | } |
| 176 | - switch_to_blog( $original_blog_id ); |
|
| 176 | + switch_to_blog($original_blog_id); |
|
| 177 | 177 | } |
| 178 | 178 | } |
| 179 | 179 | |
@@ -184,17 +184,17 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | private function upgrade_from_2_2() |
| 186 | 186 | { |
| 187 | - if ( ! is_multisite() ) { |
|
| 187 | + if (!is_multisite()) { |
|
| 188 | 188 | $this->do_2_2_settings_update(); |
| 189 | 189 | } else { |
| 190 | 190 | global $wpdb; |
| 191 | - $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" ); |
|
| 191 | + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs"); |
|
| 192 | 192 | $original_blog_id = get_current_blog_id(); |
| 193 | - foreach ( $blog_ids as $blog_id ) { |
|
| 194 | - switch_to_blog( $blog_id ); |
|
| 193 | + foreach ($blog_ids as $blog_id) { |
|
| 194 | + switch_to_blog($blog_id); |
|
| 195 | 195 | $this->do_2_2_settings_update(); |
| 196 | 196 | } |
| 197 | - switch_to_blog( $original_blog_id ); |
|
| 197 | + switch_to_blog($original_blog_id); |
|
| 198 | 198 | } |
| 199 | 199 | } |
| 200 | 200 | |
@@ -203,12 +203,12 @@ discard block |
||
| 203 | 203 | */ |
| 204 | 204 | private function do_2_2_settings_update() |
| 205 | 205 | { |
| 206 | - $nogooglefont = autoptimizeOptionWrapper::get_option( 'autoptimize_css_nogooglefont', '' ); |
|
| 207 | - $ao_extrasetting = autoptimizeOptionWrapper::get_option( 'autoptimize_extra_settings', '' ); |
|
| 208 | - if ( ( $nogooglefont ) && ( empty( $ao_extrasetting ) ) ) { |
|
| 209 | - autoptimizeOptionWrapper::update_option( 'autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options() ); |
|
| 206 | + $nogooglefont = autoptimizeOptionWrapper::get_option('autoptimize_css_nogooglefont', ''); |
|
| 207 | + $ao_extrasetting = autoptimizeOptionWrapper::get_option('autoptimize_extra_settings', ''); |
|
| 208 | + if (($nogooglefont) && (empty($ao_extrasetting))) { |
|
| 209 | + autoptimizeOptionWrapper::update_option('autoptimize_extra_settings', autoptimizeConfig::get_ao_extra_default_options()); |
|
| 210 | 210 | } |
| 211 | - delete_option( 'autoptimize_css_nogooglefont' ); |
|
| 211 | + delete_option('autoptimize_css_nogooglefont'); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -220,33 +220,33 @@ discard block |
||
| 220 | 220 | $jobs = _get_cron_array(); |
| 221 | 221 | |
| 222 | 222 | // Remove all ao_cachechecker cron jobs (for now). |
| 223 | - foreach ( $jobs as $when => $job ) { |
|
| 224 | - $name = key( $job ); |
|
| 223 | + foreach ($jobs as $when => $job) { |
|
| 224 | + $name = key($job); |
|
| 225 | 225 | |
| 226 | - if ( false !== strpos( $name, 'ao_cachechecker' ) ) { |
|
| 227 | - unset( $jobs[ $when ] ); |
|
| 226 | + if (false !== strpos($name, 'ao_cachechecker')) { |
|
| 227 | + unset($jobs[$when]); |
|
| 228 | 228 | } |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | // Save the data. |
| 232 | - _set_cron_array( $jobs ); |
|
| 232 | + _set_cron_array($jobs); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
| 236 | 236 | * Migrate imgopt options from autoptimize_extra_settings to autoptimize_imgopt_settings |
| 237 | 237 | */ |
| 238 | 238 | private function upgrade_from_2_4() { |
| 239 | - $extra_settings = autoptimizeOptionWrapper::get_option( 'autoptimize_extra_settings', '' ); |
|
| 240 | - $imgopt_settings = autoptimizeOptionWrapper::get_option( 'autoptimize_imgopt_settings', '' ); |
|
| 241 | - if ( empty( $imgopt_settings ) && ! empty( $extra_settings ) ) { |
|
| 239 | + $extra_settings = autoptimizeOptionWrapper::get_option('autoptimize_extra_settings', ''); |
|
| 240 | + $imgopt_settings = autoptimizeOptionWrapper::get_option('autoptimize_imgopt_settings', ''); |
|
| 241 | + if (empty($imgopt_settings) && !empty($extra_settings)) { |
|
| 242 | 242 | $imgopt_settings = autoptimizeConfig::get_ao_imgopt_default_options(); |
| 243 | - if ( array_key_exists( 'autoptimize_extra_checkbox_field_5', $extra_settings ) ) { |
|
| 243 | + if (array_key_exists('autoptimize_extra_checkbox_field_5', $extra_settings)) { |
|
| 244 | 244 | $imgopt_settings['autoptimize_imgopt_checkbox_field_1'] = $extra_settings['autoptimize_extra_checkbox_field_5']; |
| 245 | 245 | } |
| 246 | - if ( array_key_exists( 'autoptimize_extra_select_field_6', $extra_settings ) ) { |
|
| 246 | + if (array_key_exists('autoptimize_extra_select_field_6', $extra_settings)) { |
|
| 247 | 247 | $imgopt_settings['autoptimize_imgopt_select_field_2'] = $extra_settings['autoptimize_extra_select_field_6']; |
| 248 | 248 | } |
| 249 | - autoptimizeOptionWrapper::update_option( 'autoptimize_imgopt_settings', $imgopt_settings ); |
|
| 249 | + autoptimizeOptionWrapper::update_option('autoptimize_imgopt_settings', $imgopt_settings); |
|
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | } |
@@ -3,7 +3,7 @@ discard block |
||
| 3 | 3 | * Temporary options page for AO26, will integrate CCSS functionality in next release. |
| 4 | 4 | */ |
| 5 | 5 | |
| 6 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 6 | +if (!defined('ABSPATH')) { |
|
| 7 | 7 | exit; |
| 8 | 8 | } |
| 9 | 9 | |
@@ -17,39 +17,39 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public function __construct() |
| 19 | 19 | { |
| 20 | - $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http ); |
|
| 20 | + $this->settings_screen_do_remote_http = apply_filters('autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http); |
|
| 21 | 21 | $this->run(); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | protected function enabled() |
| 25 | 25 | { |
| 26 | - return apply_filters( 'autoptimize_filter_show_criticalcsss_tabs', true ); |
|
| 26 | + return apply_filters('autoptimize_filter_show_criticalcsss_tabs', true); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | public function run() |
| 30 | 30 | { |
| 31 | - if ( $this->enabled() ) { |
|
| 32 | - add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_critcss_tabs' ), 10, 1 ); |
|
| 31 | + if ($this->enabled()) { |
|
| 32 | + add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_critcss_tabs'), 10, 1); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
| 36 | - add_action( 'network_admin_menu', array( $this, 'add_critcss_admin_menu' ) ); |
|
| 35 | + if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
| 36 | + add_action('network_admin_menu', array($this, 'add_critcss_admin_menu')); |
|
| 37 | 37 | } else { |
| 38 | - add_action( 'admin_menu', array( $this, 'add_critcss_admin_menu' ) ); |
|
| 38 | + add_action('admin_menu', array($this, 'add_critcss_admin_menu')); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - public function add_critcss_tabs( $in ) |
|
| 42 | + public function add_critcss_tabs($in) |
|
| 43 | 43 | { |
| 44 | - $in = array_merge( $in, array( 'ao_critcss' => '⚡ ' . __( 'Critical CSS', 'autoptimize' ) ) ); |
|
| 44 | + $in = array_merge($in, array('ao_critcss' => '⚡ '.__('Critical CSS', 'autoptimize'))); |
|
| 45 | 45 | |
| 46 | 46 | return $in; |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | public function add_critcss_admin_menu() |
| 50 | 50 | { |
| 51 | - if ( $this->enabled() ) { |
|
| 52 | - add_submenu_page( null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array( $this, 'ao_criticalcsssettings_page' ) ); |
|
| 51 | + if ($this->enabled()) { |
|
| 52 | + add_submenu_page(null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array($this, 'ao_criticalcsssettings_page')); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
@@ -60,35 +60,35 @@ discard block |
||
| 60 | 60 | .ao_settings_div {background: white;border: 1px solid #ccc;padding: 1px 15px;margin: 15px 10px 10px 0;} |
| 61 | 61 | .ao_settings_div .form-table th {font-weight: normal;} |
| 62 | 62 | </style> |
| 63 | - <script>document.title = "Autoptimize: <?php _e( 'Critical CSS', 'autoptimize' ); ?> " + document.title;</script> |
|
| 63 | + <script>document.title = "Autoptimize: <?php _e('Critical CSS', 'autoptimize'); ?> " + document.title;</script> |
|
| 64 | 64 | <div class="wrap"> |
| 65 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
| 65 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
| 66 | 66 | <?php echo autoptimizeConfig::ao_admin_tabs(); ?> |
| 67 | 67 | <div class="ao_settings_div"> |
| 68 | 68 | <?php |
| 69 | 69 | $ccss_explanation = ''; |
| 70 | 70 | |
| 71 | 71 | // get the HTML with the explanation of what critical CSS is. |
| 72 | - if ( $this->settings_screen_do_remote_http ) { |
|
| 73 | - $ccss_explanation = get_transient( 'ccss_explain_ao26' ); |
|
| 74 | - if ( empty( $ccss_explanation ) ) { |
|
| 75 | - $ccss_expl_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_ccss_explain_ao26.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION ); |
|
| 76 | - if ( ! is_wp_error( $ccss_expl_resp ) ) { |
|
| 77 | - if ( '200' == wp_remote_retrieve_response_code( $ccss_expl_resp ) ) { |
|
| 78 | - $ccss_explanation = wp_kses_post( wp_remote_retrieve_body( $ccss_expl_resp ) ); |
|
| 79 | - set_transient( 'ccss_explain_ao26', $ccss_explanation, WEEK_IN_SECONDS ); |
|
| 72 | + if ($this->settings_screen_do_remote_http) { |
|
| 73 | + $ccss_explanation = get_transient('ccss_explain_ao26'); |
|
| 74 | + if (empty($ccss_explanation)) { |
|
| 75 | + $ccss_expl_resp = wp_remote_get('https://misc.optimizingmatters.com/autoptimize_ccss_explain_ao26.html?ao_ver='.AUTOPTIMIZE_PLUGIN_VERSION); |
|
| 76 | + if (!is_wp_error($ccss_expl_resp)) { |
|
| 77 | + if ('200' == wp_remote_retrieve_response_code($ccss_expl_resp)) { |
|
| 78 | + $ccss_explanation = wp_kses_post(wp_remote_retrieve_body($ccss_expl_resp)); |
|
| 79 | + set_transient('ccss_explain_ao26', $ccss_explanation, WEEK_IN_SECONDS); |
|
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | // placeholder text in case HTML is empty. |
| 86 | - if ( empty( $ccss_explanation ) ) { |
|
| 86 | + if (empty($ccss_explanation)) { |
|
| 87 | 87 | $ccss_explanation = '<h2>Fix render-blocking CSS!</h2><p>Significantly improve your first-paint times by making CSS non-render-blocking.</p><br /><a href="./plugin-install.php?s=autoptimize+criticalcss&tab=search&type=term" class="button">Install the "Autoptimize Critical CSS Power-Up"!</a>'; |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | // and echo it. |
| 91 | - echo $ccss_explanation . '<p> </p>'; |
|
| 91 | + echo $ccss_explanation.'<p> </p>'; |
|
| 92 | 92 | ?> |
| 93 | 93 | </div> |
| 94 | 94 | </div> |
@@ -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 | - autoptimizeOptionWrapper::update_option( 'autoptimize_cachesize_notice', true ); |
|
| 62 | - if ( apply_filters( 'autoptimize_filter_cachecheck_sendmail', true ) ) { |
|
| 63 | - $home_url = esc_url( home_url() ); |
|
| 64 | - $ao_mailto = apply_filters( 'autoptimize_filter_cachecheck_mailto', autoptimizeOptionWrapper::get_option( 'admin_email', '' ) ); |
|
| 65 | - |
|
| 66 | - $ao_mailsubject = __( 'Autoptimize cache size warning', 'autoptimize' ) . ' (' . $home_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: ' . $home_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 | + autoptimizeOptionWrapper::update_option('autoptimize_cachesize_notice', true); |
|
| 62 | + if (apply_filters('autoptimize_filter_cachecheck_sendmail', true)) { |
|
| 63 | + $home_url = esc_url(home_url()); |
|
| 64 | + $ao_mailto = apply_filters('autoptimize_filter_cachecheck_mailto', autoptimizeOptionWrapper::get_option('admin_email', '')); |
|
| 65 | + |
|
| 66 | + $ao_mailsubject = __('Autoptimize cache size warning', 'autoptimize').' ('.$home_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: '.$home_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) autoptimizeOptionWrapper::get_option( 'autoptimize_cachesize_notice', false ) && current_user_can( 'manage_options' ) ) { |
|
| 90 | + if ((bool) autoptimizeOptionWrapper::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 | - autoptimizeOptionWrapper::update_option( 'autoptimize_cachesize_notice', false ); |
|
| 94 | + autoptimizeOptionWrapper::update_option('autoptimize_cachesize_notice', false); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | // Notice for image proxy usage. |
| 98 | 98 | $_imgopt_notice = autoptimizeImages::instance()->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, -3 ) ) ) { |
|
| 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, -3))) { |
|
| 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><strong>' . __( 'Autoptimize', 'autoptimize' ) . '</strong>: ' . $_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><strong>'.__('Autoptimize', 'autoptimize').'</strong>: '.$_imgopt_notice['notice'].'</p></div>'; |
|
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | } |
@@ -4,7 +4,7 @@ discard block |
||
| 4 | 4 | * addons and/or affiliate services. |
| 5 | 5 | */ |
| 6 | 6 | |
| 7 | -if ( ! defined( 'ABSPATH' ) ) { |
|
| 7 | +if (!defined('ABSPATH')) { |
|
| 8 | 8 | exit; |
| 9 | 9 | } |
| 10 | 10 | |
@@ -17,68 +17,68 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public function run() |
| 19 | 19 | { |
| 20 | - if ( $this->enabled() ) { |
|
| 21 | - add_filter( 'autoptimize_filter_settingsscreen_tabs', array( $this, 'add_partner_tabs' ), 10, 1 ); |
|
| 20 | + if ($this->enabled()) { |
|
| 21 | + add_filter('autoptimize_filter_settingsscreen_tabs', array($this, 'add_partner_tabs'), 10, 1); |
|
| 22 | 22 | } |
| 23 | - if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { |
|
| 24 | - add_action( 'network_admin_menu', array( $this, 'add_admin_menu' ) ); |
|
| 23 | + if (is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network()) { |
|
| 24 | + add_action('network_admin_menu', array($this, 'add_admin_menu')); |
|
| 25 | 25 | } else { |
| 26 | - add_action( 'admin_menu', array( $this, 'add_admin_menu' ) ); |
|
| 26 | + add_action('admin_menu', array($this, 'add_admin_menu')); |
|
| 27 | 27 | } |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | protected function enabled() |
| 31 | 31 | { |
| 32 | - return apply_filters( 'autoptimize_filter_show_partner_tabs', true ); |
|
| 32 | + return apply_filters('autoptimize_filter_show_partner_tabs', true); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | - public function add_partner_tabs( $in ) |
|
| 35 | + public function add_partner_tabs($in) |
|
| 36 | 36 | { |
| 37 | - $in = array_merge( $in, array( |
|
| 38 | - 'ao_partners' => __( 'Optimize More!', 'autoptimize' ), |
|
| 39 | - ) ); |
|
| 37 | + $in = array_merge($in, array( |
|
| 38 | + 'ao_partners' => __('Optimize More!', 'autoptimize'), |
|
| 39 | + )); |
|
| 40 | 40 | |
| 41 | 41 | return $in; |
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | public function add_admin_menu() |
| 45 | 45 | { |
| 46 | - if ( $this->enabled() ) { |
|
| 47 | - add_submenu_page( null, 'AO partner', 'AO partner', 'manage_options', 'ao_partners', array( $this, 'ao_partners_page' ) ); |
|
| 46 | + if ($this->enabled()) { |
|
| 47 | + add_submenu_page(null, 'AO partner', 'AO partner', 'manage_options', 'ao_partners', array($this, 'ao_partners_page')); |
|
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | protected function get_ao_partner_feed_markup() |
| 52 | 52 | { |
| 53 | - $no_feed_text = __( 'Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for Autoptimize power-ups!', 'autoptimize' ); |
|
| 53 | + $no_feed_text = __('Have a look at <a href="http://optimizingmatters.com/">optimizingmatters.com</a> for Autoptimize power-ups!', 'autoptimize'); |
|
| 54 | 54 | $output = ''; |
| 55 | - if ( apply_filters( 'autoptimize_settingsscreen_remotehttp', true ) ) { |
|
| 56 | - $rss = fetch_feed( 'http://feeds.feedburner.com/OptimizingMattersDownloads' ); |
|
| 55 | + if (apply_filters('autoptimize_settingsscreen_remotehttp', true)) { |
|
| 56 | + $rss = fetch_feed('http://feeds.feedburner.com/OptimizingMattersDownloads'); |
|
| 57 | 57 | $maxitems = 0; |
| 58 | 58 | |
| 59 | - if ( ! is_wp_error( $rss ) ) { |
|
| 60 | - $maxitems = $rss->get_item_quantity( 20 ); |
|
| 61 | - $rss_items = $rss->get_items( 0, $maxitems ); |
|
| 59 | + if (!is_wp_error($rss)) { |
|
| 60 | + $maxitems = $rss->get_item_quantity(20); |
|
| 61 | + $rss_items = $rss->get_items(0, $maxitems); |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if ( 0 == $maxitems ) { |
|
| 64 | + if (0 == $maxitems) { |
|
| 65 | 65 | $output .= $no_feed_text; |
| 66 | 66 | } else { |
| 67 | 67 | $output .= '<ul>'; |
| 68 | - foreach ( $rss_items as $item ) { |
|
| 69 | - $item_url = esc_url( $item->get_permalink() ); |
|
| 68 | + foreach ($rss_items as $item) { |
|
| 69 | + $item_url = esc_url($item->get_permalink()); |
|
| 70 | 70 | $enclosure = $item->get_enclosure(); |
| 71 | 71 | |
| 72 | 72 | $output .= '<li class="itemDetail">'; |
| 73 | - $output .= '<h3 class="itemTitle"><a href="' . $item_url . '" target="_blank">' . esc_html( $item->get_title() ) . '</a></h3>'; |
|
| 73 | + $output .= '<h3 class="itemTitle"><a href="'.$item_url.'" target="_blank">'.esc_html($item->get_title()).'</a></h3>'; |
|
| 74 | 74 | |
| 75 | - if ( $enclosure && ( false !== strpos( $enclosure->get_type(), 'image' ) ) ) { |
|
| 76 | - $img_url = esc_url( $enclosure->get_link() ); |
|
| 77 | - $output .= '<div class="itemImage"><a href="' . $item_url . '" target="_blank"><img src="' . $img_url . '"></a></div>'; |
|
| 75 | + if ($enclosure && (false !== strpos($enclosure->get_type(), 'image'))) { |
|
| 76 | + $img_url = esc_url($enclosure->get_link()); |
|
| 77 | + $output .= '<div class="itemImage"><a href="'.$item_url.'" target="_blank"><img src="'.$img_url.'"></a></div>'; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - $output .= '<div class="itemDescription">' . wp_kses_post( $item->get_description() ) . '</div>'; |
|
| 81 | - $output .= '<div class="itemButtonRow"><div class="itemButton button-secondary"><a href="' . $item_url . '" target="_blank">' . __( 'More info', 'autoptimize' ) . '</a></div></div>'; |
|
| 80 | + $output .= '<div class="itemDescription">'.wp_kses_post($item->get_description()).'</div>'; |
|
| 81 | + $output .= '<div class="itemButtonRow"><div class="itemButton button-secondary"><a href="'.$item_url.'" target="_blank">'.__('More info', 'autoptimize').'</a></div></div>'; |
|
| 82 | 82 | $output .= '</li>'; |
| 83 | 83 | } |
| 84 | 84 | $output .= '</ul>'; |
@@ -136,11 +136,11 @@ discard block |
||
| 136 | 136 | color: #23282d; |
| 137 | 137 | } |
| 138 | 138 | </style> |
| 139 | - <script>document.title = "Autoptimize: <?php _e( 'Optimize More!', 'autoptimize' ); ?> " + document.title;</script> |
|
| 139 | + <script>document.title = "Autoptimize: <?php _e('Optimize More!', 'autoptimize'); ?> " + document.title;</script> |
|
| 140 | 140 | <div class="wrap"> |
| 141 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> |
|
| 141 | + <h1><?php _e('Autoptimize Settings', 'autoptimize'); ?></h1> |
|
| 142 | 142 | <?php echo autoptimizeConfig::ao_admin_tabs(); ?> |
| 143 | - <?php echo '<h2>' . __( "These Autoptimize power-ups and related services will improve your site's performance even more!", 'autoptimize' ) . '</h2>'; ?> |
|
| 143 | + <?php echo '<h2>'.__("These Autoptimize power-ups and related services will improve your site's performance even more!", 'autoptimize').'</h2>'; ?> |
|
| 144 | 144 | <div> |
| 145 | 145 | <?php echo $this->get_ao_partner_feed_markup(); ?> |
| 146 | 146 | </div> |
@@ -20,19 +20,19 @@ |
||
| 20 | 20 | * to files that don't exist in AO's cache. |
| 21 | 21 | */ |
| 22 | 22 | |
| 23 | -$original_request = strtok( $_SERVER['REQUEST_URI'], '?' ); |
|
| 24 | -$fallback_target = preg_replace( '/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request ); |
|
| 23 | +$original_request = strtok($_SERVER['REQUEST_URI'], '?'); |
|
| 24 | +$fallback_target = preg_replace('/(.*)_(?:[a-z0-9]{32})\.(js|css)$/', '${1}_fallback.${2}', $original_request); |
|
| 25 | 25 | $ao_cache_dir = '<!--ao-cache-dir-->'; |
| 26 | -$js_or_css = pathinfo( $original_request, PATHINFO_EXTENSION ); |
|
| 27 | -$fallback_path = $ao_cache_dir . $js_or_css . '/autoptimize_fallback.' . $js_or_css; |
|
| 26 | +$js_or_css = pathinfo($original_request, PATHINFO_EXTENSION); |
|
| 27 | +$fallback_path = $ao_cache_dir.$js_or_css.'/autoptimize_fallback.'.$js_or_css; |
|
| 28 | 28 | |
| 29 | -if ( $original_request !== $fallback_target && file_exists( $fallback_path ) ) { |
|
| 29 | +if ($original_request !== $fallback_target && file_exists($fallback_path)) { |
|
| 30 | 30 | // error_log( 'Autoptimize file ' . $original_request . ' not found, using fallback instead.' ); |
| 31 | - header( 'HTTP/1.1 301 Moved Permanently' ); |
|
| 32 | - header( 'Location: ' . $fallback_target ); |
|
| 31 | + header('HTTP/1.1 301 Moved Permanently'); |
|
| 32 | + header('Location: '.$fallback_target); |
|
| 33 | 33 | } else { |
| 34 | 34 | // error_log( 'Autoptimize file ' . $original_request . ' not found, sending 410 gone response.' ); |
| 35 | - header( 'HTTP/1.1 410 Gone' ); |
|
| 35 | + header('HTTP/1.1 410 Gone'); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | exit(); |
@@ -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.6.0' ); |
|
| 23 | +define('AUTOPTIMIZE_PLUGIN_VERSION', '2.6.0'); |
|
| 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.6', '<' ) ) { |
|
| 30 | +if (version_compare(PHP_VERSION, '5.6', '<')) { |
|
| 31 | 31 | function autoptimize_incompatible_admin_notice() { |
| 32 | - 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>'; |
|
| 33 | - if ( isset( $_GET['activate'] ) ) { |
|
| 34 | - unset( $_GET['activate'] ); |
|
| 32 | + 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>'; |
|
| 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; |