PluginProbe
Autoptimize / 3.1.4
Autoptimize v3.1.4
2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 All 107 releases
← All changes | classes/autoptimizeConfig.php +791 -411 2.3.03.1.4 View file →
@@ -1,84 +1,114 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2 +/**
3 + * Main configuration logic.
4 + */
3 5
4 -class autoptimizeConfig {
6 +if ( ! defined( 'ABSPATH' ) ) {
7 + exit;
8 +}
9 +
10 +class autoptimizeConfig
11 +{
12 + /**
13 + * Options.
14 + *
15 + * @var array
16 + */
5 17 private $config = null;
18 +
19 + /**
20 + * Singleton instance.
21 + *
22 + * @var self|null
23 + */
6 24 static private $instance = null;
7 25
8 - //Singleton: private construct
9 - private function __construct() {
10 - if( is_admin() ) {
11 - //Add the admin page and settings
12 - add_action('admin_menu',array($this,'addmenu'));
13 - add_action('admin_init',array($this,'registersettings'));
26 + /**
27 + * Options.
28 + *
29 + * @var bool
30 + */
31 + private $settings_screen_do_remote_http = true;
14 32
15 - //Set meta info
16 - if(function_exists('plugin_row_meta')) {
17 - //2.8+
18 - add_filter('plugin_row_meta',array($this,'setmeta'),10,2);
19 - } elseif(function_exists('post_class')) {
20 - //2.7
21 - $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
22 - add_filter('plugin_action_links_'.$plugin,array($this,'setmeta'));
33 + /**
34 + * Singleton.
35 + */
36 + private function __construct()
37 + {
38 + if ( is_admin() ) {
39 + // Add the admin page and settings.
40 + if ( autoptimizeOptionWrapper::is_ao_active_for_network() ) {
41 + add_action( 'network_admin_menu', array( $this, 'addmenu' ) );
23 42 }
24 43
25 - //Clean cache?
26 - if(get_option('autoptimize_cache_clean')) {
44 + add_action( 'admin_menu', array( $this, 'addmenu' ) );
45 + add_action( 'admin_init', array( $this, 'registersettings' ) );
46 + add_action( 'admin_init', array( 'PAnD', 'init' ) );
47 +
48 + // Set meta info.
49 + if ( function_exists( 'plugin_row_meta' ) ) {
50 + // 2.8 and higher.
51 + add_filter( 'plugin_row_meta', array( $this, 'setmeta' ), 10, 2 );
52 + } elseif ( function_exists( 'post_class' ) ) {
53 + // 2.7 and lower.
54 + $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
55 + add_filter( 'plugin_action_links_' . $plugin, array( $this, 'setmeta' ) );
56 + }
57 +
58 + // Clean cache?
59 + if ( autoptimizeOptionWrapper::get_option( 'autoptimize_cache_clean' ) ) {
27 60 autoptimizeCache::clearall();
28 - update_option('autoptimize_cache_clean',0);
61 + autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 );
29 62 }
63 +
64 + $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
65 +
66 + if ( $this->is_ao_meta_settings_active() ) {
67 + $meta_box = new autoptimizeMetabox();
68 + }
30 69 }
31 70
32 - //Add the Autoptimize Toolbar to the Admin bar
33 - //(we loaded outside the verification of is_admin to also be displayed on the frontend toolbar)
71 + // Adds the Autoptimize Toolbar to the Admin bar.
72 + // (we load outside the is_admin check so it's also displayed on the frontend toolbar).
34 73 $toolbar = new autoptimizeToolbar();
35 74 }
36 -
37 - static public function instance() {
38 - //Only one instance
39 - if (self::$instance == null) {
75 +
76 + /**
77 + * Instantiates aoconfig.
78 + *
79 + * @return autoptimizeConfig
80 + */
81 + static public function instance()
82 + {
83 + // Only one instance.
84 + if ( null === self::$instance ) {
40 85 self::$instance = new autoptimizeConfig();
41 86 }
42 -
87 +
43 88 return self::$instance;
44 - }
45 -
46 - public function show() {
47 -?>
89 + }
90 +
91 + public function show_network_message() {
92 + ?>
93 + <div class="wrap">
94 + <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
95 + <?php echo $this->ao_admin_tabs(); ?>
96 + <p style="font-size:120%;"><?php echo apply_filters( 'autoptimize_filter_settingsscreen_multisite_network_message', __( 'Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize' ) ); ?></p>
97 + </div>
98 + <?php
99 + }
100 +
101 + public function show_config()
102 + {
103 + // phpcs:disable Generic.WhiteSpace.ScopeIndent.IncorrectExact
104 + // phpcs:disable Generic.WhiteSpace.ScopeIndent.Incorrect
105 + $conf = self::instance();
106 + ?>
48 107 <style>
49 108 /* title and button */
50 109 #ao_title_and_button:after {content:''; display:block; clear:both;}
51 -#ao_adv_button{float:right;}
52 -#ao_hide_adv:before, #ao_show_adv:before {
53 - display: inline-block;
54 - float: left;
55 - height: 20px;
56 - width: 35px;
57 - background: none;
58 - color: #b4b9be;
59 - font: normal 20px/26px dashicons;
60 - letter-spacing: -4px;
61 - text-align: left;
62 - speak: none;
63 - -webkit-font-smoothing: antialiased;
64 - -moz-osx-font-smoothing: grayscale;
65 -}
66 -#ao_hide_adv:before {
67 - content: "\f108 \f142";
68 -}
69 -#ao_show_adv:before {
70 - content: "\f108 \f140";
71 -}
72 110
73 -/* animate "show adv" button */
74 -#ao_show_adv { animation: watchmenow 3s linear 5s 10; }
75 -#ao_show_adv:hover { animation: none; }
76 -@keyframes watchmenow {
77 - 0% { box-shadow: unset; }
78 - 100% { box-shadow: 0px 0px 20px yellow; }
79 -}
80 -
81 111 /* form */
82 112 .itemDetail {
83 113 background: #fff;
84 114 border: 1px solid #ccc;
@@ -87,14 +117,17 @@
87 117 }
88 118 .itemTitle {
89 119 margin-top: 0;
90 120 }
91 -input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:100;}
121 +
122 +input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:normal;}
92 123 #autoptimize_main .cb_label {display: block; padding-left: 25px; text-indent: -25px;}
124 +#autoptimize_main .form-table th {padding-top: 15px; padding-bottom: 15px;}
125 +#autoptimize_main .js_aggregate td, #autoptimize_main .js_aggregate th, #autoptimize_main .js_not_aggregate td, #autoptimize_main .js_not_aggregate th{padding-top:0px;}
93 126
94 127 /* rss block */
95 128 #futtta_feed ul{list-style:outside;}
96 -#futtta_feed {font-size:medium; margin:0px 20px;}
129 +#futtta_feed {font-size:medium; margin:0px 20px;}
97 130
98 131 /* banner + unslider */
99 132 .autoptimize_banner {
100 133 margin: 0 38px;
@@ -137,8 +170,9 @@
137 170 }
138 171 .unslider-arrow.next::before {
139 172 content: "\f345";
140 173 }
174 +
141 175 /* responsive stuff: hide admin-feed on smaller screens */
142 176 @media (min-width: 961px) {
143 177 #autoptimize_main {float:left;width:69%;}
144 178 #autoptimize_admin_feed{float:right;width:30%;display:block !important;}
@@ -147,11 +181,8 @@
147 181 #autoptimize_main {width:100%;}
148 182 #autoptimize_admin_feed {width:0%;display:none !important;}
149 183 }
150 184 @media (max-width: 782px) {
151 - #ao_hide_adv span, #ao_show_adv span {display: none;}
152 - #ao_hide_adv,#ao_show_adv {height: 34px;padding: 4px 12px 8px 8px;}
153 - #ao_hide_adv:before,#ao_show_adv:before {font-size: 25px;}
154 185 #autoptimize_main input[type="checkbox"] {margin-left: 10px;}
155 186 #autoptimize_main .cb_label {display: block; padding-left: 45px; text-indent: -45px;}
156 187 }
157 188 </style>
@@ -157,311 +188,367 @@
157 188 </style>
158 189
159 190 <div class="wrap">
160 191
161 -<?php if (version_compare(PHP_VERSION, '5.3.0') < 0) { ?>
162 -<div class="notice-error notice"><?php echo '<p>' . sprintf( __('<strong>You are using a very old version of PHP</strong> (5.2.x or older) which has <a href=%s>serious security and performance issues</a>. Support for PHP 5.5 and below will be removed in one of the next AO released, please ask your hoster to provide you with an upgrade path to 7.x.','autoptimize'), '"http://blog.futtta.be/2016/03/15/why-would-you-still-be-on-php-5-2/" target="_blank"') . '</p>'; ?></div>
192 +<!-- Temporary nudge to disable aoccss power-up. -->
193 +<?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?>
194 + <div class="notice-info notice"><p>
195 + <?php _e( 'Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize' ); ?>
196 + </p></div>
163 197 <?php } ?>
164 198
165 199 <div id="autoptimize_main">
166 -<div id="ao_title_and_button">
167 - <h1 id="ao_title"><?php _e('Autoptimize Settings','autoptimize'); ?>
168 - <span id="ao_adv_button">
169 - <?php
170 - if (get_option('autoptimize_show_adv','0')=='1') {
171 - ?>
172 - <a href="javascript:void(0);" id="ao_show_adv" class="button" style="display:none;"><span><?php _e("Show advanced settings","autoptimize") ?></span></a>
173 - <a href="javascript:void(0);" id="ao_hide_adv" class="button"><span><?php _e("Hide advanced settings","autoptimize") ?></span></a>
174 - <style>tr.ao_adv{display:table-row;} li.ao_adv{display:list-item;}</style>
175 - <?php
176 - $hiddenClass="";
177 - } else {
178 - ?>
179 - <a href="javascript:void(0);" id="ao_show_adv" class="button"><span><?php _e("Show advanced settings","autoptimize") ?></span></a>
180 - <a href="javascript:void(0);" id="ao_hide_adv" class="button" style="display:none;"><span><?php _e("Hide advanced settings","autoptimize") ?></span></a>
181 - <?php
182 - $hiddenClass="hidden ";
183 - }
184 - ?>
185 - </span>
186 - </h1>
187 -</div>
200 + <h1 id="ao_title"><?php apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? _e( 'Autoptimize Pro Settings', 'autoptimize' ) : _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
201 + <?php echo $this->ao_admin_tabs(); ?>
188 202
189 -<?php echo $this->ao_admin_tabs(); ?>
203 +<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
204 +<?php settings_fields( 'autoptimize' ); ?>
190 205
191 -<form method="post" action="options.php">
192 -<?php settings_fields('autoptimize'); ?>
206 +<ul>
193 207
194 -<ul>
208 +<?php
209 +// Only show enable site configuration in network site option.
210 +if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
211 +?>
212 + <li class="itemDetail multiSite">
213 + <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2>
214 + <table class="form-table">
215 + <tr valign="top">
216 + <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th>
217 + <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ? 'checked="checked" ' : ''; ?>/>
218 + <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td>
219 + </tr>
220 + </table>
221 + </li>
222 +<?php } else { ?>
223 + <input type="hidden" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" value="on" />
224 +<?php } ?>
195 225
196 226 <li class="itemDetail">
197 -<h2 class="itemTitle"><?php _e('HTML Options','autoptimize'); ?></h2>
227 +<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
198 228 <table class="form-table">
199 229 <tr valign="top">
200 -<th scope="row"><?php _e('Optimize HTML Code?','autoptimize'); ?></th>
201 -<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo get_option('autoptimize_html')?'checked="checked" ':''; ?>/></td>
230 +<th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th>
231 +<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo $conf->get( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
202 232 </tr>
203 -<tr class="<?php echo $hiddenClass;?>html_sub ao_adv" valign="top">
204 -<th scope="row"><?php _e('Keep HTML comments?','autoptimize'); ?></th>
205 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo get_option('autoptimize_html_keepcomments')?'checked="checked" ':''; ?>/>
206 -<?php _e('Enable this if you want HTML comments to remain in the page.','autoptimize'); ?></label></td>
233 +<tr valign="top" class="js_sub js_aggregate_master">
234 +<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
235 +<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get( 'autoptimize_js_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
236 +<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking?', 'autoptimize' ); ?></label></td>
207 237 </tr>
238 +<tr valign="top" class="js_sub js_aggregate hidden">
239 +<th scope="row">&emsp;<?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
240 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo $conf->get( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
241 +<?php _e( 'Let Autoptimize also extract JS from the HTML (discouraged as it can make Autoptimize\'s cache size grow quickly)', 'autoptimize' ); ?></label></td>
242 +</tr>
243 +<tr valign="top" class="js_sub js_aggregate hidden">
244 +<th scope="row">&emsp;<?php _e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
245 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo $conf->get( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
246 +<?php _e( 'Load JavaScript early (discouraged as it makes the JS render blocking)', 'autoptimize' ); ?></label></td>
247 +</tr>
248 +<tr valign="top" class="js_sub js_aggregate hidden">
249 +<th scope="row">&emsp;<?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
250 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo $conf->get( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
251 +<?php _e( 'If your aggregated scripts break because of a JS-error, you might want to try this, but generally discouraged.', 'autoptimize' ); ?></label></td>
252 +</tr>
253 +<tr valign="top" class="js_sub js_not_aggregate_master">
254 +<th scope="row"><?php _e( 'Do not aggregate but defer?', 'autoptimize' ); ?></th>
255 +<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_defer_not_aggregate" name="autoptimize_js_defer_not_aggregate" <?php echo $conf->get( 'autoptimize_js_defer_not_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
256 +<?php _e( 'Individual JS-files will be minified and deferred, making them non-render-blocking.', 'autoptimize' ); ?></label></td>
257 +</tr>
258 +<tr valign="top" id="js_defer_inline" class="js_sub js_not_aggregate hidden">
259 +<th scope="row">&emsp;<?php _e( 'Also defer inline JS?', 'autoptimize' ); ?></th>
260 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_defer_inline" <?php echo $conf->get( 'autoptimize_js_defer_inline' ) ? 'checked="checked" ' : ''; ?>/>
261 +<?php _e( 'Also defer inline JS. Generally this will allow all JS to be deferred, so you should remove default exclusions, test and only exclude specific items if still needed.', 'autoptimize' ); ?></label></td>
262 +</tr>
263 +<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
264 +<tr valign="top" class="js_sub js_aggregate">
265 +<th scope="row">
266 +<?php
267 + _e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
268 + echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
269 +?>
270 +</th>
271 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo $conf->get( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
272 +<?php _e( 'Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize' ); ?></label></td>
273 +</tr>
274 +<?php } ?>
275 +<tr valign="top" class="js_sub">
276 +<th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th>
277 +<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', '' ) ); ?>"/><br />
278 +<?php
279 +echo __( 'A comma-separated list of scripts you do not want optimized, for example \'whatever.js, my_var\' (without the quotes).', 'autoptimize' ) . ' ' . __( 'Important: when "aggregate JS-files" is on, excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' );
280 +?>
281 +</label></td>
282 +</tr>
283 +<tr valign="top">
284 +<th scope="row"><?php _e( 'Remove Unused JavaScript?', 'autoptimize' ); ?></th>
285 +<td><?php _e( 'Autoptimize combines your theme & plugins\' JavaScript, but does not know what is used and what not. If Google Pagespeed Insights detects unused JavaScript, consider using a plugin like "Plugin Organizer" or similar to manage what JavaScript is added where.', 'autoptimize' ); ?></td>
286 +</tr>
208 287 </table>
209 288 </li>
210 289
211 290 <li class="itemDetail">
212 -<h2 class="itemTitle"><?php _e('JavaScript Options','autoptimize'); ?></h2>
213 -<table class="form-table">
291 +<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2>
292 +<table class="form-table">
214 293 <tr valign="top">
215 -<th scope="row"><?php _e('Optimize JavaScript Code?','autoptimize'); ?></th>
216 -<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo get_option('autoptimize_js')?'checked="checked" ':''; ?>/></td>
294 +<th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th>
295 +<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo $conf->get( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
217 296 </tr>
218 -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv">
219 -<th scope="row"><?php _e('Force JavaScript in &lt;head&gt;?','autoptimize'); ?></th>
220 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo get_option('autoptimize_js_forcehead')?'checked="checked" ':''; ?>/>
221 -<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.','autoptimize'); ?></label></td>
297 +<tr class="css_sub" valign="top">
298 +<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
299 +<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get( 'autoptimize_css_aggregate' ) ? 'checked="checked" ' : ''; ?>/>
300 +<?php _e( 'Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
222 301 </tr>
223 -<?php if (get_option('autoptimize_js_justhead')) { ?>
224 -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv">
225 -<th scope="row"><?php _e('Look for scripts only in &lt;head&gt;?','autoptimize'); echo ' <i>'. __('(deprecated)','autoptimize') . '</i>'; ?></th>
226 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo get_option('autoptimize_js_justhead')?'checked="checked" ':''; ?>/>
227 -<?php _e('Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.','autoptimize'); ?></label></td>
302 +<tr valign="top" class="css_sub css_aggregate">
303 +<th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th>
304 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo $conf->get( 'autoptimize_css_include_inline', '1' ) ? 'checked="checked" ' : ''; ?>/>
305 +<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
228 306 </tr>
307 +<tr class="css_sub css_aggregate" valign="top">
308 +<th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th>
309 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo $conf->get( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
310 +<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
311 +</tr>
312 +<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
313 +<tr valign="top" class="css_sub css_aggregate">
314 +<th scope="row">
315 +<?php
316 +_e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
317 +echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
318 +?>
319 +</th>
320 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo $conf->get( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
321 +<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td>
322 +</tr>
229 323 <?php } ?>
230 -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv">
231 -<th scope="row"><?php _e('Also aggregate inline JS?','autoptimize'); ?></th>
232 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo get_option('autoptimize_js_include_inline')?'checked="checked" ':''; ?>/>
233 -<?php _e('Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.','autoptimize'); ?></label></td>
324 +<tr valign="top" class="css_sub">
325 +<th scope="row"><?php _e( 'Eliminate render-blocking CSS?', 'autoptimize' ); ?></th>
326 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo $conf->get( 'autoptimize_css_defer' ) ? 'checked="checked" ' : ''; ?>/>
327 +<?php
328 +_e( 'Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize' );
329 +echo ' ';
330 +$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' );
331 +// translators: links "autoptimize critical CSS" tab.
332 +echo sprintf( __( 'You can manually create rules for different types of pages or have this done fully automated on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' );
333 +?>
334 +</label></td>
234 335 </tr>
235 -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv">
236 -<th scope="row"><?php _e('Exclude scripts from Autoptimize:','autoptimize'); ?></th>
237 -<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo get_option('autoptimize_js_exclude',"seal.js, js/jquery/jquery.js"); ?>"/><br />
238 -<?php _e('A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated and minimized by Autoptimize.','autoptimize'); ?></label></td>
336 +<tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
337 +<th scope="row"></th>
338 +<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize' ); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeStyles::sanitize_css( autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' ) ); ?></textarea></label></td>
239 339 </tr>
240 -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv">
241 -<th scope="row"><?php _e('Add try-catch wrapping?','autoptimize'); ?></th>
242 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo get_option('autoptimize_js_trycatch')?'checked="checked" ':''; ?>/>
243 -<?php _e('If your scripts break because of a JS-error, you might want to try this.','autoptimize'); ?></label></td>
340 +<tr valign="top" class="css_sub css_aggregate">
341 +<th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th>
342 +<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo $conf->get( 'autoptimize_css_inline' ) ? 'checked="checked" ' : ''; ?>/>
343 +<?php _e( 'Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize' ); ?></label></td>
244 344 </tr>
345 +<tr valign="top" class="css_sub">
346 +<th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th>
347 +<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr( $conf->get( 'autoptimize_css_exclude', '' ) ); ?>"/><br />
348 +<?php
349 +echo __( 'A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' );
350 +?>
351 +</label></td>
352 +</tr>
353 +<?php if ( false === autoptimizeUtils::is_plugin_active( 'unusedcss/unusedcss.php' ) ) { ?>
354 +<tr valign="top">
355 +<th scope="row"><?php _e( 'Remove Unused CSS?', 'autoptimize' ); ?></th>
356 +<?php
357 +$_rapidload_link = 'https://misc.optimizingmatters.com/partners/?from=csssettings&partner=rapidload';
358 +?>
359 +<td><?php echo sprintf( __( 'If Google Pagespeed Insights detects unused CSS, consider using %s to <strong>reduce your site\'s CSS size to up to 90&#37;</strong>, resulting in a slimmer, faster site!', 'autoptimize' ), '<a href="' . $_rapidload_link . '" target="_blank">the premium Rapidload service</a>' ); ?></td>
360 +</tr>
361 +<?php } ?>
245 362 </table>
246 363 </li>
247 364
248 365 <li class="itemDetail">
249 -<h2 class="itemTitle"><?php _e('CSS Options','autoptimize'); ?></h2>
250 -<table class="form-table">
366 +<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2>
367 +<table class="form-table">
251 368 <tr valign="top">
252 -<th scope="row"><?php _e('Optimize CSS Code?','autoptimize'); ?></th>
253 -<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo get_option('autoptimize_css')?'checked="checked" ':''; ?>/></td>
369 +<th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th>
370 +<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo $conf->get( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
254 371 </tr>
255 -<tr class="<?php echo $hiddenClass;?>css_sub ao_adv" valign="top">
256 -<th scope="row"><?php _e('Generate data: URIs for images?','autoptimize'); ?></th>
257 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo get_option('autoptimize_css_datauris')?'checked="checked" ':''; ?>/>
258 -<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.','autoptimize'); ?></label></td>
372 +<tr class="html_sub" valign="top">
373 +<th scope="row"><?php _e( 'Also minify inline JS/ CSS?', 'autoptimize' ); ?></th>
374 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_minify_inline" <?php echo $conf->get( 'autoptimize_html_minify_inline' ) ? 'checked="checked" ' : ''; ?>/>
375 +<?php _e( 'Enable this if you want inline JS or CSS to be minified as well.', 'autoptimize' ); ?></label></td>
259 376 </tr>
260 -<?php if (get_option('autoptimize_css_justhead')) { ?>
261 -<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv">
262 -<th scope="row"><?php _e('Look for styles only in &lt;head&gt;?','autoptimize'); echo ' <i>'. __('(deprecated)','autoptimize') . '</i>'; ?></th>
263 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo get_option('autoptimize_css_justhead')?'checked="checked" ':''; ?>/>
264 -<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.','autoptimize'); ?></label></td>
377 +<tr class="html_sub" valign="top">
378 +<th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th>
379 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo $conf->get( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
380 +<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td>
265 381 </tr>
266 -<?php } ?>
267 -<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv">
268 -<th scope="row"><?php _e('Also aggregate inline CSS?','autoptimize'); ?></th>
269 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo get_option('autoptimize_css_include_inline','1')?'checked="checked" ':''; ?>/>
270 -<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.','autoptimize'); ?></label></td>
271 -</tr>
272 -<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv">
273 -<th scope="row"><?php _e('Inline and Defer CSS?','autoptimize'); ?></th>
274 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo get_option('autoptimize_css_defer')?'checked="checked" ':''; ?>/>
275 -<?php _e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="http://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> before activating this option!','autoptimize'); ?></label></td>
276 -</tr>
277 -<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv" id="autoptimize_css_defer_inline">
278 -<th scope="row"></th>
279 -<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e('Paste the above the fold CSS here.','autoptimize'); ?>" name="autoptimize_css_defer_inline"><?php echo get_option('autoptimize_css_defer_inline'); ?></textarea></label></td>
280 -</tr>
281 -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv css_sub">
282 -<th scope="row"><?php _e('Inline all CSS?','autoptimize'); ?></th>
283 -<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo get_option('autoptimize_css_inline')?'checked="checked" ':''; ?>/>
284 -<?php _e('Inlining all CSS can improve performance for sites with a low pageviews/ visitor-rate, but may slow down performance otherwise.','autoptimize'); ?></label></td>
285 -</tr>
286 -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv css_sub">
287 -<th scope="row"><?php _e('Exclude CSS from Autoptimize:','autoptimize'); ?></th>
288 -<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo get_option('autoptimize_css_exclude','admin-bar.min.css, dashicons.min.css'); ?>"/><br />
289 -<?php _e('A comma-separated list of CSS you want to exclude from being optimized.','autoptimize'); ?></label></td>
290 -</tr>
291 382 </table>
292 383 </li>
293 384
294 385 <li class="itemDetail">
295 -<h2 class="itemTitle"><?php _e('CDN Options','autoptimize'); ?></h2>
296 -<table class="form-table">
386 +<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2>
387 +<table class="form-table">
297 388 <tr valign="top">
298 -<th scope="row"><?php _e('CDN Base URL','autoptimize'); ?></th>
299 -<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url(get_option('autoptimize_cdn_url',''),array("http","https")); ?>" /><br />
300 -<?php _e('Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative (e.g. <code>//cdn.example.com/</code>). This is not needed for Cloudflare.','autoptimize'); ?></label></td>
389 +<th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th>
390 +<?php
391 +if ( true === autoptimizeImages::imgopt_active() && true === apply_filters( 'autoptimize_filter_cdn_set_by_imgopt', false ) ) {
392 + // cdn set by imgopt, not to be changealbe in the settings.
393 + $cdn_editable = 'disabled';
394 + $cdn_placeholder = 'placeholder="' . __( 'The CDN has automatically been set to make use of the image optimization CDN.', 'autoptimize' ) . ' "';
395 + $cdn_description = '';
396 +} else {
397 + $cdn_editable = '';
398 + $cdn_placeholder = 'placeholder="' . __( 'example: //cdn.yoursite.com/', 'autoptimize' ) . ' "';
399 + $cdn_description = __( 'Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative. This is not needed for Cloudflare.', 'autoptimize' );
400 +}
401 +?>
402 +<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" <?php echo $cdn_placeholder . $cdn_editable; ?> value="<?php echo esc_url( autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ), array( 'http', 'https' ) ); ?>" /><br />
403 +<?php echo $cdn_description; ?>
404 +</label></td>
301 405 </tr>
302 406 </table>
303 407 </li>
304 408
305 -<li class="<?php echo $hiddenClass;?>itemDetail ao_adv">
306 -<h2 class="itemTitle"><?php _e('Cache Info','autoptimize'); ?></h2>
307 -<table class="form-table" >
308 -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
309 -<th scope="row"><?php _e('Cache folder','autoptimize'); ?></th>
310 -<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td>
409 +<li class="itemDetail">
410 +<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2>
411 +<table class="form-table" >
412 +<tr valign="top" >
413 +<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th>
414 +<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td>
311 415 </tr>
312 -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
313 -<th scope="row"><?php _e('Can we write?','autoptimize'); ?></th>
314 -<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes','autoptimize') : __('No','autoptimize')); ?></td>
416 +<tr valign="top" >
417 +<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th>
418 +<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td>
315 419 </tr>
316 -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
317 -<th scope="row"><?php _e('Cached styles and scripts','autoptimize'); ?></th>
318 -<td><?php
319 - $AOstatArr=autoptimizeCache::stats();
320 - $AOcacheSize=round($AOstatArr[1]/1024);
321 - printf( __( '%1$s files, totalling %2$s Kbytes (calculated at %3$s)', 'autoptimize'), $AOstatArr[0], $AOcacheSize, date("H:i e", $AOstatArr[2]) );
322 -?></td>
420 +<tr valign="top" >
421 +<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th>
422 +<td>
423 + <?php
424 + $ao_stat_arr = autoptimizeCache::stats();
425 + if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) {
426 + $ao_cache_size = size_format( $ao_stat_arr[1], 2 );
427 + $details = '';
428 + if ( $ao_cache_size > 0 ) {
429 + $details = ', ~' . $ao_cache_size . ' total';
430 + }
431 + // translators: Kilobytes + timestamp shown.
432 + printf( __( '%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize' ), $ao_stat_arr[0], $ao_cache_size, date( 'H:i e', $ao_stat_arr[2] ) ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
433 + }
434 + ?>
435 +</td>
323 436 </tr>
324 437 </table>
325 438 </li>
326 439
327 -<li class="<?php echo $hiddenClass;?>itemDetail ao_adv">
328 -<h2 class="itemTitle"><?php _e('Misc Options','autoptimize'); ?></h2>
329 -<table class="form-table">
330 - <tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
331 - <th scope="row"><?php _e('Save aggregated script/css as static files?','autoptimize'); ?></th>
332 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo get_option('autoptimize_cache_nogzip','1')?'checked="checked" ':''; ?>/>
333 - <?php _e('By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.','autoptimize'); ?></label>
334 - </td>
335 - </tr>
336 - <tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
337 - <th scope="row"><?php _e('Also optimize for logged in users?','autoptimize'); ?></th>
338 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo get_option('autoptimize_optimize_logged','1')?'checked="checked" ':''; ?>/>
339 - <?php _e('By default Autoptimize is also active for logged on users, uncheck not to optimize when logged in e.g. to use a pagebuilder.','autoptimize'); ?></label>
340 - </td>
341 - </tr>
342 - <?php
343 - if ( function_exists("is_checkout") || function_exists("is_cart") || function_exists("edd_is_checkout") || function_exists("wpsc_is_cart") || function_exists("wpsc_is_checkout") ) {
344 - ?>
345 - <tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
346 - <th scope="row"><?php _e('Also optimize shop cart/ checkout?','autoptimize'); ?></th>
347 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo get_option('autoptimize_optimize_checkout','1')?'checked="checked" ':''; ?>/>
348 - <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.','autoptimize'); ?></label>
349 - </td>
350 - </tr>
351 - <?php
352 - }
353 - ?>
440 +<li class="itemDetail">
441 +<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2>
442 +<table class="form-table">
443 + <tr valign="top">
444 + <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th>
445 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo $conf->get( 'autoptimize_cache_nogzip' ) ? 'checked="checked" ' : ''; ?>/>
446 + <?php _e( 'By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize' ); ?></label></td>
447 + </tr>
448 + <?php
449 + $_min_excl_class = '';
450 + if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) {
451 + $_min_excl_class = 'hidden';
452 + }
453 + ?>
454 + <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>">
455 + <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th>
456 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo $conf->get( 'autoptimize_minify_excluded' ) ? 'checked="checked" ' : ''; ?>/>
457 + <?php _e( 'When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize' ); ?></label></td>
458 + </tr>
459 + <tr valign="top">
460 + <th scope="row"><?php _e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th>
461 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo $conf->get( 'autoptimize_cache_fallback' ) ? 'checked="checked" ' : ''; ?>/>
462 + <?php _e( 'Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. With this option on, Autoptimize will try to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize' ); ?></label></td>
463 + </tr>
464 + <tr valign="top">
465 + <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th>
466 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo $conf->get( 'autoptimize_optimize_logged' ) ? 'checked="checked" ' : ''; ?>/>
467 + <?php _e( 'By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize' ); ?></label></td>
468 + </tr>
469 + <?php
470 + if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) {
471 + ?>
472 + <tr valign="top" >
473 + <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th>
474 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo $conf->get( 'autoptimize_optimize_checkout' ) ? 'checked="checked" ' : ''; ?>/>
475 + <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
476 + </td>
477 + </tr>
478 + <?php } ?>
479 + <?php
480 + if ( true === apply_filters( 'autoptimize_filter_enable_meta_ao_settings', true ) ) {
481 + ?>
482 + <tr valign="top">
483 + <th scope="row"><?php _e( 'Enable configuration per post/ page?', 'autoptimize' ); ?></th>
484 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_enable_meta_ao_settings" <?php echo $conf->get( 'autoptimize_enable_meta_ao_settings' ) ? 'checked="checked" ' : ''; ?>/>
485 + <?php _e( 'Add a "metabox" to the post/ page edit screen allowing different optimizations to be turned off on a per post/ page level?', 'autoptimize' ); ?></label></td>
486 + </tr>
487 + <?php } ?>
488 + <?php if ( false !== (bool) autoptimizeOptionWrapper::get_option( 'autoptimize_installed_before_compatibility', false ) ) { ?>
489 + <tr valign="top">
490 + <th scope="row"><?php _e( 'Disable extra compatibilty logic?', 'autoptimize' ); ?></th>
491 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_installed_before_compatibility" checked="checked" />
492 + <?php _e( 'In Autoptimize 3.0 extra compatibiity logic was added (e.g. for Gutenberg blocks, Revolution Slider, jQuery-heavy plugins, ...), but if you had Autoptimize installed already before the update to 3.0, this compatibility code was disabled. <strong>Untick this option to permanently enable the compatibility logic</strong>.', 'autoptimize' ); ?></label></td>
493 + </tr>
494 + <?php } ?>
354 495 </table>
355 496 </li>
356 497
357 498 </ul>
358 499
359 -<input type="hidden" id="autoptimize_show_adv" name="autoptimize_show_adv" value="<?php echo get_option('autoptimize_show_adv','0'); ?>">
360 -
361 500 <p class="submit">
362 -<input type="submit" class="button-secondary" value="<?php _e('Save Changes','autoptimize') ?>" />
363 -<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache','autoptimize') ?>" />
501 +<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
502 +<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" />
364 503 </p>
365 504
366 505 </form>
367 506 </div>
368 -<div id="autoptimize_admin_feed" class="hidden">
507 +<div id="autoptimize_admin_feed">
508 + <?php if ( apply_filters( 'autoptimize_filter_show_partner_tabs', true ) ) { ?>
369 509 <div class="autoptimize_banner hidden">
370 - <ul>
371 - <?php
372 - if (apply_filters('autoptimize_settingsscreen_remotehttp',true)) {
373 - $AO_banner=get_transient("autoptimize_banner");
374 - if (empty($AO_banner)) {
375 - $banner_resp = wp_remote_get("http://misc.optimizingmatters.com/autoptimize_news.html");
376 - if (!is_wp_error($banner_resp)) {
377 - if (wp_remote_retrieve_response_code($banner_resp)=="200") {
378 - $AO_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp));
379 - set_transient("autoptimize_banner",$AO_banner,DAY_IN_SECONDS);
380 - }
510 + <ul>
511 + <?php
512 + if ( $this->settings_screen_do_remote_http ) {
513 + $ao_banner = get_transient( 'autoptimize_banner' );
514 + if ( empty( $ao_banner ) ) {
515 + $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
516 + if ( ! is_wp_error( $banner_resp ) ) {
517 + if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) {
518 + $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
519 + set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS );
381 520 }
382 521 }
383 - echo $AO_banner;
384 522 }
385 - ?>
386 - <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.","autoptimize"); ?></li>
387 - <li><?php _e("Happy with Autoptimize?","autoptimize"); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e("Try my other plugins!","autoptimize"); ?></a></li>
388 - </ul>
523 + echo $ao_banner;
524 + }
525 + ?>
526 + <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li>
527 + <li><?php _e( 'Happy with Autoptimize?', 'autoptimize' ); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e( 'Try my other plugins!', 'autoptimize' ); ?></a></li>
528 + </ul>
389 529 </div>
530 + <?php } ?>
390 531 <div style="margin-left:10px;margin-top:-5px;">
391 532 <h2>
392 - <?php _e("futtta about","autoptimize") ?>
393 - <select id="feed_dropdown" >
394 - <option value="1"><?php _e("Autoptimize","autoptimize") ?></option>
395 - <option value="2"><?php _e("WordPress","autoptimize") ?></option>
396 - <option value="3"><?php _e("Web Technology","autoptimize") ?></option>
397 - </select>
533 + <?php _e( 'Autoptimize news', 'autoptimize' ); ?>
398 534 </h2>
399 535 <div id="futtta_feed">
400 536 <div id="autoptimizefeed">
401 - <?php $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_autoptimize"); ?>
537 + <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
402 538 </div>
403 - <div id="wordpressfeed">
404 - <?php $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_wordpress"); ?>
405 - </div>
406 - <div id="webtechfeed">
407 - <?php $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_webtech"); ?>
408 - </div>
409 539 </div>
410 540 </div>
411 - <div style="float:right;margin:50px 15px;"><a href="http://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url().'/'.plugin_basename(dirname(__FILE__)).'/external/do_not_donate_smallest.png'; ?>" title="<?php _e("Do not donate for this plugin!","autoptimize"); ?>"></a></div>
541 + <?php if ( apply_filters( 'autoptimize_filter_show_partner_tabs', true ) ) { ?>
542 + <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url() . '/' . plugin_basename( dirname( __FILE__ ) ) . '/external/do_not_donate_smallest.png'; ?>" title="<?php _e( 'Do not donate for this plugin!', 'autoptimize' ); ?>"></a></div>
543 + <?php } ?>
412 544 </div>
413 -
414 545 <script type="text/javascript">
415 - var feed = new Array;
416 - feed[1]="autoptimizefeed";
417 - feed[2]="wordpressfeed";
418 - feed[3]="webtechfeed";
419 - cookiename="autoptimize_feed";
420 -
421 546 jQuery(document).ready(function() {
422 547 check_ini_state();
423 - jQuery('#autoptimize_admin_feed').fadeTo("slow",1).show();
548 +
424 549 jQuery('.autoptimize_banner').unslider({autoplay:true, delay:3500, infinite: false, arrows:{prev:'<a class="unslider-arrow prev"></a>', next:'<a class="unslider-arrow next"></a>'}}).fadeTo("slow",1).show();
425 550
426 - jQuery( "#feed_dropdown" ).change(function() {
427 - jQuery("#futtta_feed").fadeTo(0,0);
428 - jQuery("#futtta_feed").fadeTo("slow",1);
429 - });
430 -
431 - jQuery( "#ao_show_adv" ).click(function() {
432 - jQuery( "#ao_show_adv" ).hide();
433 - jQuery( "#ao_hide_adv" ).show();
434 - jQuery( ".ao_adv" ).removeClass("hidden");
435 - jQuery( ".ao_adv" ).show("slow");
436 - if (jQuery("#autoptimize_css").attr('checked')) {
437 - jQuery(".css_sub:visible").fadeTo("fast",1);
438 - if (!jQuery("#autoptimize_css_defer").attr('checked')) {
439 - jQuery("#autoptimize_css_defer_inline").hide();
440 - }
441 - }
442 - if (jQuery("#autoptimize_js").attr('checked')) {
443 - jQuery(".js_sub:visible").fadeTo("fast",1);
444 - }
445 - check_ini_state()
446 - jQuery( "input#autoptimize_show_adv" ).val("1");
447 - });
448 -
449 - jQuery( "#ao_hide_adv" ).click(function() {
450 - jQuery( "#ao_hide_adv" ).hide();
451 - jQuery( "#ao_show_adv" ).show();
452 - jQuery( ".ao_adv" ).hide("slow");
453 - jQuery( ".ao_adv" ).addClass("hidden");
454 - if (!jQuery("#autoptimize_css").attr('checked')) {
455 - jQuery(".css_sub:visible").fadeTo("fast",.33);
456 - }
457 - if (!jQuery("#autoptimize_js").attr('checked')) {
458 - jQuery(".js_sub:visible").fadeTo("fast",.33);
459 - }
460 - check_ini_state()
461 - jQuery( "input#autoptimize_show_adv" ).val("0");
462 - });
463 -
464 551 jQuery( "#autoptimize_html" ).change(function() {
465 552 if (this.checked) {
466 553 jQuery(".html_sub:visible").fadeTo("fast",1);
467 554 } else {
@@ -476,8 +563,41 @@
476 563 jQuery(".js_sub:visible").fadeTo("fast",.33);
477 564 }
478 565 });
479 566
567 + jQuery( "#autoptimize_js_aggregate" ).change(function() {
568 + if (this.checked && jQuery("#autoptimize_js").prop('checked')) {
569 + jQuery( "#autoptimize_js_defer_not_aggregate" ).prop( 'checked', false ); // uncheck "defer not aggregate"
570 + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // ungrey self
571 + jQuery( ".js_aggregate" ).show( 'slow' ); // show sub-items
572 + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'slow', .33 ); // grey out "not aggregate"
573 + jQuery( ".js_not_aggregate" ).hide( 'slow' ); // hide not aggregate sub-items
574 + jQuery( "#min_excl_row" ).show(); // make sure "minify excluded" is visible
575 + check_exclusions( "js", "on" );
576 + } else {
577 + jQuery( ".js_aggregate" ).hide( 'slow' ); // hide sub-itmes
578 + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // un-grey-out "not aggregate"
579 + if ( jQuery( "#autoptimize_css_aggregate" ).prop( 'checked' ) == false ) { // hide "minify excluded"
580 + jQuery( "#min_excl_row" ).hide();
581 + }
582 + check_exclusions( "js", "off" );
583 + }
584 + });
585 +
586 + jQuery( "#autoptimize_js_defer_not_aggregate" ).change(function() {
587 + if (this.checked && jQuery("#autoptimize_js").prop('checked')) {
588 + jQuery( "#autoptimize_js_aggregate" ).prop( 'checked', false ); // uncheck "aggregate JS"
589 + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // ungrey self
590 + jQuery( ".js_not_aggregate" ).show( 'slow'); // show sub-items
591 + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'slow', .33 ); // grey out "aggregate"
592 + jQuery( ".js_aggregate" ).hide( 'slow' ); // hide aggregate sub-items
593 + check_exclusions( "js", "off" );
594 + } else {
595 + jQuery( ".js_not_aggregate" ).hide( 'slow' ); // hide sub-items
596 + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // un-grey-out "aggregate"
597 + }
598 + });
599 +
480 600 jQuery( "#autoptimize_css" ).change(function() {
481 601 if (this.checked) {
482 602 jQuery(".css_sub:visible").fadeTo("fast",1);
483 603 } else {
@@ -484,8 +604,22 @@
484 604 jQuery(".css_sub:visible").fadeTo("fast",.33);
485 605 }
486 606 });
487 607
608 + jQuery( "#autoptimize_css_aggregate" ).change(function() {
609 + if (this.checked && jQuery("#autoptimize_css").prop('checked')) {
610 + jQuery(".css_aggregate:visible").fadeTo("fast",1);
611 + jQuery( "#min_excl_row" ).show();
612 + check_exclusions( "css", "on" );
613 + } else {
614 + jQuery(".css_aggregate:visible").fadeTo("fast",.33);
615 + if ( jQuery( "#autoptimize_js_aggregate" ).prop('checked') == false ) {
616 + jQuery( "#min_excl_row" ).hide();
617 + }
618 + check_exclusions( "css", "off" );
619 + }
620 + });
621 +
488 622 jQuery( "#autoptimize_css_inline" ).change(function() {
489 623 if (this.checked) {
490 624 jQuery("#autoptimize_css_defer").prop("checked",false);
491 625 jQuery("#autoptimize_css_defer_inline").hide("slow");
@@ -500,15 +634,18 @@
500 634 jQuery("#autoptimize_css_defer_inline").hide("slow");
501 635 }
502 636 });
503 637
504 - jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) });
505 - feedid=jQuery.cookie(cookiename);
506 - if(typeof(feedid) !== "string") feedid=1;
507 - show_feed(feedid);
638 + jQuery( "#autoptimize_enable_site_config" ).change(function() {
639 + if (this.checked) {
640 + jQuery("li.itemDetail:not(.multiSite)").fadeTo("fast",.33);
641 + } else {
642 + jQuery("li.itemDetail:not(.multiSite)").fadeTo("fast",1);
643 + }
644 + });
508 645 })
509 646
510 - // validate cdn_url
647 + // validate cdn_url.
511 648 var cdn_url=document.getElementById("cdn_url");
512 649 cdn_url_baseCSS=cdn_url.style.cssText;
513 650 if ("validity" in cdn_url) {
514 651 jQuery("#cdn_url").focusout(function (event) {
@@ -519,27 +656,56 @@
519 656 }});
520 657 }
521 658
522 659 function check_ini_state() {
523 - if (!jQuery("#autoptimize_css_defer").attr('checked')) {
660 + if (!jQuery("#autoptimize_css_defer").prop('checked')) {
524 661 jQuery("#autoptimize_css_defer_inline").hide();
525 662 }
526 - if (!jQuery("#autoptimize_html").attr('checked')) {
663 + if (!jQuery("#autoptimize_html").prop('checked')) {
527 664 jQuery(".html_sub:visible").fadeTo('fast',.33);
528 665 }
529 - if (!jQuery("#autoptimize_css").attr('checked')) {
666 + if (!jQuery("#autoptimize_css").prop('checked')) {
530 667 jQuery(".css_sub:visible").fadeTo('fast',.33);
531 668 }
532 - if (!jQuery("#autoptimize_js").attr('checked')) {
669 + if (!jQuery("#autoptimize_css_aggregate").prop('checked')) {
670 + jQuery(".css_aggregate:visible").fadeTo('fast',.33);
671 + }
672 + if (jQuery("#autoptimize_js_aggregate").prop('checked')) {
673 + jQuery( ".js_aggregate" ).show( 'fast' );
674 + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'fast', .33 );
675 + }
676 + if (jQuery("#autoptimize_js_defer_not_aggregate").prop('checked')) {
677 + jQuery( ".js_not_aggregate" ).show( 'fast' );
678 + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'fast', .33 );
679 + }
680 + if (jQuery("#autoptimize_enable_site_config").prop('checked')) {
681 + jQuery("li.itemDetail:not(.multiSite)").fadeTo('fast',.33);
682 + }
683 + if (!jQuery("#autoptimize_js").prop('checked')) {
533 684 jQuery(".js_sub:visible").fadeTo('fast',.33);
534 685 }
535 686 }
536 687
537 - function show_feed(id) {
538 - jQuery('#futtta_feed').children().hide();
539 - jQuery('#'+feed[id]).show();
540 - jQuery("#feed_dropdown").val(id);
541 - jQuery.cookie(cookiename,id,{ expires: 365 });
688 + function check_exclusions( what, state ) {
689 + exclusion_node = 'input[name="autoptimize_' + what + '_exclude"]';
690 + current_exclusion = jQuery( exclusion_node ).val();
691 +
692 + if ( what == "js" ) {
693 + default_exclusion = ", wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.min.js";
694 + } else if ( what == "css") {
695 + default_exclusion = ", admin-bar.min.css, dashicons.min.css, wp-content/cache/, wp-content/uploads/";
696 + }
697 +
698 + default_in_current = current_exclusion.indexOf(default_exclusion);
699 +
700 + if ( state == "on" && default_in_current == -1 ) {
701 + jQuery( exclusion_node ).val( current_exclusion + default_exclusion );
702 + } else if ( state = "off" && current_exclusion == default_exclusion ) {
703 + jQuery( exclusion_node ).val( "" );
704 + } else if ( state = "off" && default_in_current != -1 ) {
705 + new_exclusion = current_exclusion.substring( 0, default_in_current) + current_exclusion.substring( default_in_current + default_exclusion.length, current_exclusion.length );
706 + jQuery( exclusion_node ).val( new_exclusion );
707 + }
542 708 }
543 709 </script>
544 710 </div>
545 711
@@ -545,66 +711,90 @@
545 711
546 712 <?php
547 713 }
548 714
549 - public function addmenu() {
550 - $hook=add_options_page(__('Autoptimize Options','autoptimize'),'Autoptimize','manage_options','autoptimize',array($this,'show'));
551 - add_action( 'admin_print_scripts-'.$hook,array($this,'autoptimize_admin_scripts'));
552 - add_action( 'admin_print_styles-'.$hook,array($this,'autoptimize_admin_styles'));
715 + public function addmenu()
716 + {
717 + $_my_name = apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? __( 'Autoptimize Pro', 'autoptimize' ) : __( 'Autoptimize', 'autoptimize' );
718 + if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
719 + // multisite, network admin, ao network activated: add normal settings page at network level.
720 + $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
721 + } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
722 + // multisite, ao network activated, not network admin so site specific settings, but "autoptimize_enable_site_config" is off: show "sorry, ask network admin" message iso options.
723 + $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
724 + } else {
725 + // default: show normal options page if not multisite, if multisite but not network activated, if multisite and network activated and "autoptimize_enable_site_config" is on.
726 + $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
727 + }
728 +
729 + add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
730 + add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
553 731 }
554 732
555 - public function autoptimize_admin_scripts() {
556 - wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'),null,true);
557 - wp_enqueue_script('unslider', plugins_url('/external/js/unslider-min.js', __FILE__), array('jquery'),null,true);
733 + public function autoptimize_admin_scripts()
734 + {
735 + wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
558 736 }
559 737
560 - public function autoptimize_admin_styles() {
561 - wp_enqueue_style('unslider', plugins_url('/external/js/unslider.css', __FILE__));
562 - wp_enqueue_style('unslider-dots', plugins_url('/external/js/unslider-dots.css', __FILE__));
738 + public function autoptimize_admin_styles()
739 + {
740 + wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) );
741 + wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) );
563 742 }
564 743
565 744 public function registersettings() {
566 - register_setting('autoptimize','autoptimize_html');
567 - register_setting('autoptimize','autoptimize_html_keepcomments');
568 - register_setting('autoptimize','autoptimize_js');
569 - register_setting('autoptimize','autoptimize_js_exclude');
570 - register_setting('autoptimize','autoptimize_js_trycatch');
571 - register_setting('autoptimize','autoptimize_js_justhead');
572 - register_setting('autoptimize','autoptimize_js_forcehead');
573 - register_setting('autoptimize','autoptimize_js_include_inline');
574 - register_setting('autoptimize','autoptimize_css');
575 - register_setting('autoptimize','autoptimize_css_exclude');
576 - register_setting('autoptimize','autoptimize_css_justhead');
577 - register_setting('autoptimize','autoptimize_css_datauris');
578 - register_setting('autoptimize','autoptimize_css_defer');
579 - register_setting('autoptimize','autoptimize_css_defer_inline');
580 - register_setting('autoptimize','autoptimize_css_inline');
581 - register_setting('autoptimize','autoptimize_css_include_inline');
582 - register_setting('autoptimize','autoptimize_cdn_url');
583 - register_setting('autoptimize','autoptimize_cache_clean');
584 - register_setting('autoptimize','autoptimize_cache_nogzip');
585 - register_setting('autoptimize','autoptimize_show_adv');
586 - register_setting('autoptimize','autoptimize_optimize_logged');
587 - register_setting('autoptimize','autoptimize_optimize_checkout');
745 + register_setting( 'autoptimize', 'autoptimize_html' );
746 + register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
747 + register_setting( 'autoptimize', 'autoptimize_html_minify_inline' );
748 + register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
749 + register_setting( 'autoptimize', 'autoptimize_js' );
750 + register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
751 + register_setting( 'autoptimize', 'autoptimize_js_defer_not_aggregate' );
752 + register_setting( 'autoptimize', 'autoptimize_js_defer_inline' );
753 + register_setting( 'autoptimize', 'autoptimize_js_exclude' );
754 + register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
755 + register_setting( 'autoptimize', 'autoptimize_js_justhead' );
756 + register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
757 + register_setting( 'autoptimize', 'autoptimize_js_include_inline' );
758 + register_setting( 'autoptimize', 'autoptimize_css' );
759 + register_setting( 'autoptimize', 'autoptimize_css_aggregate' );
760 + register_setting( 'autoptimize', 'autoptimize_css_exclude' );
761 + register_setting( 'autoptimize', 'autoptimize_css_justhead' );
762 + register_setting( 'autoptimize', 'autoptimize_css_datauris' );
763 + register_setting( 'autoptimize', 'autoptimize_css_defer' );
764 + register_setting( 'autoptimize', 'autoptimize_css_defer_inline' );
765 + register_setting( 'autoptimize', 'autoptimize_css_inline' );
766 + register_setting( 'autoptimize', 'autoptimize_css_include_inline' );
767 + register_setting( 'autoptimize', 'autoptimize_cdn_url' );
768 + register_setting( 'autoptimize', 'autoptimize_cache_clean' );
769 + register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
770 + register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
771 + register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
772 + register_setting( 'autoptimize', 'autoptimize_minify_excluded' );
773 + register_setting( 'autoptimize', 'autoptimize_cache_fallback' );
774 + register_setting( 'autoptimize', 'autoptimize_enable_meta_ao_settings' );
775 + register_setting( 'autoptimize', 'autoptimize_installed_before_compatibility' );
588 776 }
589 777
590 - public function setmeta($links,$file=null) {
591 - //Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/
592 - //Do it only once - saves time
778 + public function setmeta( $links, $file = null )
779 + {
780 + // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/.
781 + // Do it only once - saves time.
593 782 static $plugin;
594 - if(empty($plugin))
595 - $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
596 -
597 - if($file===null) {
598 - //2.7
599 - $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'));
600 - array_unshift($links,$settings_link);
783 + if ( empty( $plugin ) ) {
784 + $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
785 + }
786 +
787 + if ( null === $file ) {
788 + // 2.7 and lower.
789 + $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) );
790 + array_unshift( $links, $settings_link );
601 791 } else {
602 - //2.8
603 - //If it's us, add the link
604 - if($file === $plugin) {
605 - $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>',__('Settings')));
606 - $links = array_merge($links,$newlink);
792 + // 2.8 and higher.
793 + // If it's us, add the link.
794 + if ( $file === $plugin ) {
795 + $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) );
796 + $links = array_merge( $links, $newlink );
607 797 }
608 798 }
609 799
610 800 return $links;
@@ -609,71 +799,148 @@
609 799
610 800 return $links;
611 801 }
612 802
613 - public function get($key) {
614 - if(!is_array($this->config)) {
615 - //Default config
616 - $config = array('autoptimize_html' => 0,
617 - 'autoptimize_html_keepcomments' => 0,
618 - 'autoptimize_js' => 0,
619 - 'autoptimize_js_exclude' => "seal.js, js/jquery/jquery.js",
620 - 'autoptimize_js_trycatch' => 0,
621 - 'autoptimize_js_justhead' => 0,
622 - 'autoptimize_js_include_inline' => 0,
623 - 'autoptimize_js_forcehead' => 0,
624 - 'autoptimize_css' => 0,
625 - 'autoptimize_css_exclude' => "admin-bar.min.css, dashicons.min.css",
626 - 'autoptimize_css_justhead' => 0,
627 - 'autoptimize_css_include_inline' => 1,
628 - 'autoptimize_css_defer' => 0,
629 - 'autoptimize_css_defer_inline' => "",
630 - 'autoptimize_css_inline' => 0,
631 - 'autoptimize_css_datauris' => 0,
632 - 'autoptimize_cdn_url' => "",
633 - 'autoptimize_cache_nogzip' => 1,
634 - 'autoptimize_show_adv' => 0,
635 - 'autoptimize_optimize_logged' => 1,
636 - 'autoptimize_optimize_checkout' => 1
637 - );
803 + /**
804 + * Provides the default options.
805 + *
806 + * @return array
807 + */
808 + public static function get_defaults()
809 + {
810 + static $config = array(
811 + 'autoptimize_html' => 0,
812 + 'autoptimize_html_keepcomments' => 0,
813 + 'autoptimize_html_minify_inline' => 0,
814 + 'autoptimize_enable_site_config' => 1,
815 + 'autoptimize_js' => 0,
816 + 'autoptimize_js_aggregate' => 0,
817 + 'autoptimize_js_defer_not_aggregate' => 1,
818 + 'autoptimize_js_defer_inline' => 1,
819 + 'autoptimize_js_exclude' => '',
820 + 'autoptimize_js_trycatch' => 0,
821 + 'autoptimize_js_justhead' => 0,
822 + 'autoptimize_js_include_inline' => 0,
823 + 'autoptimize_js_forcehead' => 0,
824 + 'autoptimize_css' => 0,
825 + 'autoptimize_css_aggregate' => 0,
826 + 'autoptimize_css_exclude' => '',
827 + 'autoptimize_css_justhead' => 0,
828 + 'autoptimize_css_include_inline' => 0,
829 + 'autoptimize_css_defer' => 0,
830 + 'autoptimize_css_defer_inline' => '',
831 + 'autoptimize_css_inline' => 0,
832 + 'autoptimize_css_datauris' => 0,
833 + 'autoptimize_cdn_url' => '',
834 + 'autoptimize_cache_nogzip' => 1,
835 + 'autoptimize_optimize_logged' => 1,
836 + 'autoptimize_optimize_checkout' => 0,
837 + 'autoptimize_minify_excluded' => 1,
838 + 'autoptimize_cache_fallback' => 1,
839 + 'autoptimize_enable_meta_ao_settings' => 1,
840 + 'autoptimize_installed_before_compatibility' => 0,
841 + );
638 842
639 - //Override with user settings
640 - foreach(array_keys($config) as $name) {
641 - $conf = get_option($name);
642 - if($conf!==false) {
643 - //It was set before!
644 - $config[$name] = $conf;
843 + return $config;
844 + }
845 +
846 + /**
847 + * Returns default option values for autoptimizeExtra.
848 + *
849 + * @return array
850 + */
851 + public static function get_ao_extra_default_options()
852 + {
853 + $defaults = array(
854 + 'autoptimize_extra_checkbox_field_1' => '0',
855 + 'autoptimize_extra_checkbox_field_0' => '0',
856 + 'autoptimize_extra_radio_field_4' => '1',
857 + 'autoptimize_extra_text_field_2' => '',
858 + 'autoptimize_extra_text_field_3' => '',
859 + 'autoptimize_extra_text_field_7' => '',
860 + 'autoptimize_extra_checkbox_field_8' => '0',
861 + );
862 +
863 + return $defaults;
864 + }
865 +
866 + /**
867 + * Returns default option values for autoptimizeExtra.
868 + *
869 + * @return array
870 + */
871 + public static function get_ao_imgopt_default_options()
872 + {
873 + $defaults = array(
874 + 'autoptimize_imgopt_checkbox_field_1' => '0', // imgopt off.
875 + 'autoptimize_imgopt_select_field_2' => '2', // quality glossy.
876 + 'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
877 + 'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
878 + 'autoptimize_imgopt_text_field_5' => '', // lazy load exclusions empty.
879 + 'autoptimize_imgopt_text_field_6' => '', // optimization exclusions empty.
880 + 'autoptimize_imgopt_number_field_7' => '2', // lazy load from nth image (0 = lazyload all).
881 + );
882 + return $defaults;
883 + }
884 +
885 + /**
886 + * Returns preload JS onload handler.
887 + *
888 + * @param string $media media attribute value the JS to use.
889 + *
890 + * @return string
891 + */
892 + public static function get_ao_css_preload_onload( $media = 'all' )
893 + {
894 + $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" );
895 + return $preload_onload;
896 + }
897 +
898 + public function get( $key )
899 + {
900 + if ( ! is_array( $this->config ) ) {
901 + // Default config.
902 + $config = self::get_defaults();
903 +
904 + // Override with user settings.
905 + foreach ( array_keys( $config ) as $name ) {
906 + $conf = autoptimizeOptionWrapper::get_option( $name );
907 + if ( false !== $conf ) {
908 + // It was set before!
909 + $config[ $name ] = $conf;
645 910 }
646 911 }
647 912
648 - //Save for next question
913 + // Save for next call.
649 914 $this->config = apply_filters( 'autoptimize_filter_get_config', $config );
650 915 }
651 916
652 - if(isset($this->config[$key]))
653 - return $this->config[$key];
917 + if ( isset( $this->config[ $key ] ) ) {
918 + return $this->config[ $key ];
919 + }
654 920
655 921 return false;
656 922 }
657 923
658 - private function getFutttaFeeds($url) {
659 - if (apply_filters('autoptimize_settingsscreen_remotehttp',true)) {
660 - $rss = fetch_feed( $url );
924 + private function get_futtta_feeds( $url ) {
925 + if ( $this->settings_screen_do_remote_http ) {
926 + $rss = fetch_feed( $url );
661 927 $maxitems = 0;
662 928
663 929 if ( ! is_wp_error( $rss ) ) {
664 - $maxitems = $rss->get_item_quantity( 7 );
930 + $maxitems = $rss->get_item_quantity( 7 );
665 931 $rss_items = $rss->get_items( 0, $maxitems );
666 932 }
667 933 ?>
668 934 <ul>
669 - <?php if ( $maxitems == 0 ) : ?>
935 + <?php if ( 0 == $maxitems ) : ?>
670 936 <li><?php _e( 'No items', 'autoptimize' ); ?></li>
671 937 <?php else : ?>
672 938 <?php foreach ( $rss_items as $item ) : ?>
673 939 <li>
674 940 <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
675 - title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date('j F Y | g:i a') ); ?>">
941 + <?php // translators: the variable contains a date. ?>
942 + title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>">
676 943 <?php echo esc_html( $item->get_title() ); ?>
677 944 </a>
678 945 </li>
679 946 <?php endforeach; ?>
@@ -678,35 +945,148 @@
678 945 </li>
679 946 <?php endforeach; ?>
680 947 <?php endif; ?>
681 948 </ul>
682 - <?php
949 + <?php
683 950 }
684 951 }
685 952
686 - // based on http://wordpress.stackexchange.com/a/58826
687 - static function ao_admin_tabs(){
688 - $tabs = apply_filters('autoptimize_filter_settingsscreen_tabs',array('autoptimize' => __('Main','autoptimize')));
689 - $tabContent="";
690 - if (count($tabs)>1) {
691 - if(isset($_GET['page'])){
692 - $currentId = $_GET['page'];
953 + static function ao_admin_tabs()
954 + {
955 + // based on http://wordpress.stackexchange.com/a/58826 .
956 + $tabs = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS &amp; HTML', 'autoptimize' ) ) );
957 + $tab_content = '';
958 + $tabs_count = count( $tabs );
959 + if ( $tabs_count > 1 ) {
960 + if ( isset( $_GET['page'] ) ) {
961 + $current_id = $_GET['page'];
693 962 } else {
694 - $currentId = "autoptimize";
963 + $current_id = 'autoptimize';
695 964 }
696 - $tabContent .= "<h2 class=\"nav-tab-wrapper\">";
697 - foreach($tabs as $tabId => $tabName){
698 - if($currentId == $tabId){
699 - $class = " nav-tab-active";
700 - } else{
701 - $class = "";
965 + $tab_content .= '<h2 class="nav-tab-wrapper">';
966 + foreach ( $tabs as $tab_id => $tab_name ) {
967 + if ( $current_id == $tab_id ) {
968 + $class = ' nav-tab-active';
969 + } else {
970 + $class = '';
702 971 }
703 - $tabContent .= '<a class="nav-tab'.$class.'" href="?page='.$tabId.'">'.$tabName.'</a>';
972 + $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>';
704 973 }
705 - $tabContent .= "</h2>";
974 + $tab_content .= '</h2>';
706 975 } else {
707 - $tabContent = "<hr/>";
976 + $tab_content = '<hr/>';
708 977 }
709 978
710 - return $tabContent;
979 + return $tab_content;
980 + }
981 +
982 + /**
983 + * Returns true if in admin (and not in admin-ajax.php!)
984 + *
985 + * @return bool
986 + */
987 + public static function is_admin_and_not_ajax()
988 + {
989 + return ( is_admin() && ! self::doing_ajax() );
990 + }
991 +
992 + /**
993 + * Returns true if doing ajax.
994 + *
995 + * @return bool
996 + */
997 + protected static function doing_ajax()
998 + {
999 + if ( function_exists( 'wp_doing_ajax' ) ) {
1000 + return wp_doing_ajax();
1001 + }
1002 + return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
1003 + }
1004 +
1005 + /**
1006 + * Returns true menu or tab is to be shown.
1007 + *
1008 + * @return bool
1009 + */
1010 + public static function should_show_menu_tabs() {
1011 + if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) || false === autoptimizeOptionWrapper::is_ao_active_for_network() ) {
1012 + return true;
1013 + } else {
1014 + return false;
1015 + }
1016 + }
1017 +
1018 + /**
1019 + * Returns the post meta AO settings for reuse in different optimizers.
1020 + *
1021 + * @param string $optim What optimization we need meta setting for.
1022 + *
1023 + * @return bool
1024 + */
1025 + public static function get_post_meta_ao_settings( $optim ) {
1026 + if ( ! autoptimizeConfig::is_ao_meta_settings_active() ) {
1027 + // Per page/post settings not active, so always return true (as in; can be optimized).
1028 + if ( in_array( $optim, array( 'ao_post_preload' ) ) ) {
1029 + // but make sure to return false for text input.
1030 + return false;
1031 + }
1032 + return true;
1033 + }
1034 +
1035 + static $_meta_value = null;
1036 + if ( null === $_meta_value ) {
1037 + global $wp_query;
1038 + if ( isset( $wp_query ) && ( is_page() || is_single() ) ) {
1039 + $_meta_value = get_post_meta( get_the_ID(), 'ao_post_optimize', true );
1040 + } else if ( isset( $wp_query ) ) {
1041 + $_meta_value = false;
1042 + }
1043 + }
1044 +
1045 + // If autoptimize_post_optimize !== 'on' (except for ao_post_preload, which can have other values) then always return false as all is off.
1046 + // fixme: need unit tests to ensure below logic is sane!
1047 + if ( empty( $_meta_value ) || ! is_array( $_meta_value ) ) {
1048 + // no metabox values so all optimizations are a go.
1049 + if ( in_array( $optim, array( 'ao_post_preload' ) ) ) {
1050 + // but make sure to return false for text input.
1051 + return false;
1052 + }
1053 + return true;
1054 + } else if ( array_key_exists( 'ao_post_optimize', $_meta_value ) && 'on' !== $_meta_value['ao_post_optimize'] ) {
1055 + // ao entirely off for this page.
1056 + return false;
1057 + } else if ( array_key_exists( $optim, $_meta_value ) && empty( $_meta_value[ $optim ] ) ) {
1058 + // sub-optimization off for this page.
1059 + return false;
1060 + } else if ( array_key_exists( $optim, $_meta_value ) && 'on' === $_meta_value[ $optim ] ) {
1061 + // sub-optimization is explictly on.
1062 + return true;
1063 + } else if ( array_key_exists( $optim, $_meta_value ) && in_array( $optim, array( 'ao_post_preload' ) ) && ! empty( $_meta_value[ $optim ] ) ) {
1064 + // a non-bool metabox optimization (currently only preload field), return value instead of bool.
1065 + return $_meta_value[ $optim ];
1066 + } else if ( in_array( $optim, array( 'ao_post_preload' ) ) && ( ! array_key_exists( $optim, $_meta_value ) || empty( $_meta_value[ $optim ] ) ) ) {
1067 + // a non-bool metabox optimization not found or empty, so returning false.
1068 + return false;
1069 + } else {
1070 + // when in doubt "go" for optimization, but this should never happen?
1071 + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
1072 + error_log( 'AO metabox logic fallback; well, how did I get here? Maybe this helps: looking for ' . $optim . ' in ' . json_encode( $_meta_value ) );
1073 + }
1074 + return true;
1075 + }
1076 + }
1077 +
1078 + /**
1079 + * Are the post meta AO settings active (default: no)?
1080 + *
1081 + * @return bool
1082 + */
1083 + public static function is_ao_meta_settings_active() {
1084 + static $_meta_settings_active = null;
1085 +
1086 + if ( null === $_meta_settings_active ) {
1087 + $_meta_settings_active = apply_filters( 'autoptimize_filter_enable_meta_ao_settings', autoptimizeOptionWrapper::get_option( 'autoptimize_enable_meta_ao_settings', '1' ) );
1088 + }
1089 +
1090 + return $_meta_settings_active;
711 1091 }
712 1092 }