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 +314 -145 2.6.23.1.4 View file →
@@ -42,8 +42,9 @@
42 42 }
43 43
44 44 add_action( 'admin_menu', array( $this, 'addmenu' ) );
45 45 add_action( 'admin_init', array( $this, 'registersettings' ) );
46 + add_action( 'admin_init', array( 'PAnD', 'init' ) );
46 47
47 48 // Set meta info.
48 49 if ( function_exists( 'plugin_row_meta' ) ) {
49 50 // 2.8 and higher.
@@ -60,8 +61,12 @@
60 61 autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 );
61 62 }
62 63
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 + }
64 69 }
65 70
66 71 // Adds the Autoptimize Toolbar to the Admin bar.
67 72 // (we load outside the is_admin check so it's also displayed on the frontend toolbar).
@@ -94,10 +99,12 @@
94 99 }
95 100
96 101 public function show_config()
97 102 {
103 + // phpcs:disable Generic.WhiteSpace.ScopeIndent.IncorrectExact
104 + // phpcs:disable Generic.WhiteSpace.ScopeIndent.Incorrect
98 105 $conf = self::instance();
99 -?>
106 + ?>
100 107 <style>
101 108 /* title and button */
102 109 #ao_title_and_button:after {content:''; display:block; clear:both;}
103 110
@@ -113,8 +120,10 @@
113 120 }
114 121
115 122 input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:normal;}
116 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;}
117 126
118 127 /* rss block */
119 128 #futtta_feed ul{list-style:outside;}
120 129 #futtta_feed {font-size:medium; margin:0px 20px;}
@@ -179,16 +188,17 @@
179 188 </style>
180 189
181 190 <div class="wrap">
182 191
183 -<?php if ( defined( 'AUTOPTIMIZE_LEGACY_MINIFIERS' ) ) { ?>
184 - <div class="notice-error notice"><p>
185 - <?php _e( "You are using the (no longer supported) AUTOPTIMIZE_LEGACY_MINIFIERS constant. Ensure your site is working properly and remove the constant, it doesn't do anything any more.", 'autoptimize' ); ?>
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' ); ?>
186 196 </p></div>
187 197 <?php } ?>
188 198
189 199 <div id="autoptimize_main">
190 - <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
200 + <h1 id="ao_title"><?php apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? _e( 'Autoptimize Pro Settings', 'autoptimize' ) : _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
191 201 <?php echo $this->ao_admin_tabs(); ?>
192 202
193 203 <form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
194 204 <?php settings_fields( 'autoptimize' ); ?>
@@ -210,9 +220,9 @@
210 220 </table>
211 221 </li>
212 222 <?php } else { ?>
213 223 <input type="hidden" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" value="on" />
214 -<?php } ?>
224 +<?php } ?>
215 225
216 226 <li class="itemDetail">
217 227 <h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
218 228 <table class="form-table">
@@ -217,25 +227,40 @@
217 227 <h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
218 228 <table class="form-table">
219 229 <tr valign="top">
220 230 <th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th>
221 -<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
231 +<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo $conf->get( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
222 232 </tr>
223 -<tr valign="top" class="js_sub">
233 +<tr valign="top" class="js_sub js_aggregate_master">
224 234 <th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
225 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" ' : ''; ?>/>
226 -<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking? If this option is off, the individual JS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td>
236 +<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking?', 'autoptimize' ); ?></label></td>
227 237 </tr>
228 -<tr valign="top" class="js_sub js_aggregate">
229 -<th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
230 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
231 -<?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>
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>
232 242 </tr>
233 -<tr valign="top" class="js_sub js_aggregate">
234 -<th scope="row"><?php _e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
235 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
236 -<?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td>
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>
237 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>
238 263 <?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
239 264 <tr valign="top" class="js_sub js_aggregate">
240 265 <th scope="row">
241 266 <?php
@@ -242,24 +267,23 @@
242 267 _e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
243 268 echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
244 269 ?>
245 270 </th>
246 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
271 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo $conf->get( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
247 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>
248 273 </tr>
249 274 <?php } ?>
250 275 <tr valign="top" class="js_sub">
251 276 <th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th>
252 -<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js' ); ?>"/><br />
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 />
253 278 <?php
254 -echo __( '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 by Autoptimize.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' );
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' );
255 280 ?>
256 281 </label></td>
257 282 </tr>
258 -<tr valign="top" class="js_sub js_aggregate">
259 -<th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
260 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
261 -<?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td>
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>
262 286 </tr>
263 287 </table>
264 288 </li>
265 289
@@ -267,9 +291,9 @@
267 291 <h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2>
268 292 <table class="form-table">
269 293 <tr valign="top">
270 294 <th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th>
271 -<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
295 +<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo $conf->get( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
272 296 </tr>
273 297 <tr class="css_sub" valign="top">
274 298 <th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
275 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" ' : ''; ?>/>
@@ -276,14 +300,14 @@
276 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>
277 301 </tr>
278 302 <tr valign="top" class="css_sub css_aggregate">
279 303 <th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th>
280 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_include_inline', '1' ) ? 'checked="checked" ' : ''; ?>/>
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" ' : ''; ?>/>
281 305 <?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
282 306 </tr>
283 307 <tr class="css_sub css_aggregate" valign="top">
284 308 <th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th>
285 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
309 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo $conf->get( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
286 310 <?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
287 311 </tr>
288 312 <?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
289 313 <tr valign="top" class="css_sub css_aggregate">
@@ -292,43 +316,50 @@
292 316 _e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
293 317 echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
294 318 ?>
295 319 </th>
296 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
320 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo $conf->get( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
297 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>
298 322 </tr>
299 323 <?php } ?>
300 324 <tr valign="top" class="css_sub">
301 -<th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th>
302 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' ) ? 'checked="checked" ' : ''; ?>/>
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" ' : ''; ?>/>
303 327 <?php
304 -_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> for more info.', 'autoptimize' );
305 -if ( ! autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) {
306 - echo ' ';
307 - $critcss_install_url = network_admin_url() . 'plugin-install.php?s=autoptimize+criticalcss&tab=search&type=term';
308 - // translators: links to plugin install screen with "autoptimize critical CSS" search.
309 - echo sprintf( __( 'This can be fully automated for different types of pages with the %s.', 'autoptimize' ), '<a href="' . $critcss_install_url . '">Autoptimize CriticalCSS Power-Up</a>' );
310 -}
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>' );
311 333 ?>
312 334 </label></td>
313 335 </tr>
314 336 <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
315 337 <th scope="row"></th>
316 -<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 autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' ); ?></textarea></label></td>
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>
317 339 </tr>
318 340 <tr valign="top" class="css_sub css_aggregate">
319 341 <th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th>
320 -<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_inline' ) ? 'checked="checked" ' : ''; ?>/>
321 -<?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>
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>
322 344 </tr>
323 345 <tr valign="top" class="css_sub">
324 346 <th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th>
325 -<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css' ); ?>"/><br />
347 +<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr( $conf->get( 'autoptimize_css_exclude', '' ) ); ?>"/><br />
326 348 <?php
327 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' );
328 350 ?>
329 351 </label></td>
330 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 } ?>
331 362 </table>
332 363 </li>
333 364
334 365 <li class="itemDetail">
@@ -335,13 +366,18 @@
335 366 <h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2>
336 367 <table class="form-table">
337 368 <tr valign="top">
338 369 <th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th>
339 -<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
370 +<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo $conf->get( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
340 371 </tr>
341 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>
376 +</tr>
377 +<tr class="html_sub" valign="top">
342 378 <th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th>
343 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
379 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo $conf->get( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
344 380 <?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td>
345 381 </tr>
346 382 </table>
347 383 </li>
@@ -350,10 +386,23 @@
350 386 <h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2>
351 387 <table class="form-table">
352 388 <tr valign="top">
353 389 <th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th>
354 -<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( autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ), array( 'http', 'https' ) ); ?>" /><br />
355 -<?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>
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>
356 405 </tr>
357 406 </table>
358 407 </li>
359 408
@@ -379,9 +428,9 @@
379 428 if ( $ao_cache_size > 0 ) {
380 429 $details = ', ~' . $ao_cache_size . ' total';
381 430 }
382 431 // translators: Kilobytes + timestamp shown.
383 - printf( __( '%1$s files, totalling %2$s Kbytes (calculated at %3$s)', 'autoptimize' ), $ao_stat_arr[0], $ao_cache_size, date( 'H:i e', $ao_stat_arr[2] ) );
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
384 433 }
385 434 ?>
386 435 </td>
387 436 </tr>
@@ -390,11 +439,11 @@
390 439
391 440 <li class="itemDetail">
392 441 <h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2>
393 442 <table class="form-table">
394 - <tr valign="top" >
443 + <tr valign="top">
395 444 <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th>
396 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip', '1' ) ? 'checked="checked" ' : ''; ?>/>
445 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo $conf->get( 'autoptimize_cache_nogzip' ) ? 'checked="checked" ' : ''; ?>/>
397 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>
398 447 </tr>
399 448 <?php
400 449 $_min_excl_class = '';
@@ -403,14 +452,19 @@
403 452 }
404 453 ?>
405 454 <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>">
406 455 <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th>
407 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_minify_excluded', '1' ) ? 'checked="checked" ' : ''; ?>/>
456 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo $conf->get( 'autoptimize_minify_excluded' ) ? 'checked="checked" ' : ''; ?>/>
408 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>
409 458 </tr>
410 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">
411 465 <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th>
412 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/>
466 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo $conf->get( 'autoptimize_optimize_logged' ) ? 'checked="checked" ' : ''; ?>/>
413 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>
414 468 </tr>
415 469 <?php
416 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' ) ) {
@@ -416,13 +470,29 @@
416 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' ) ) {
417 471 ?>
418 472 <tr valign="top" >
419 473 <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th>
420 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/>
474 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo $conf->get( 'autoptimize_optimize_checkout' ) ? 'checked="checked" ' : ''; ?>/>
421 475 <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
422 476 </td>
423 477 </tr>
424 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 } ?>
425 495 </table>
426 496 </li>
427 497
428 498 </ul>
@@ -433,9 +503,10 @@
433 503 </p>
434 504
435 505 </form>
436 506 </div>
437 -<div id="autoptimize_admin_feed" class="hidden">
507 +<div id="autoptimize_admin_feed">
508 + <?php if ( apply_filters( 'autoptimize_filter_show_partner_tabs', true ) ) { ?>
438 509 <div class="autoptimize_banner hidden">
439 510 <ul>
440 511 <?php
441 512 if ( $this->settings_screen_do_remote_http ) {
@@ -455,50 +526,29 @@
455 526 <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li>
456 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>
457 528 </ul>
458 529 </div>
530 + <?php } ?>
459 531 <div style="margin-left:10px;margin-top:-5px;">
460 532 <h2>
461 - <?php _e( 'futtta about', 'autoptimize' ); ?>
462 - <select id="feed_dropdown" >
463 - <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option>
464 - <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option>
465 - <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option>
466 - </select>
533 + <?php _e( 'Autoptimize news', 'autoptimize' ); ?>
467 534 </h2>
468 535 <div id="futtta_feed">
469 536 <div id="autoptimizefeed">
470 537 <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
471 538 </div>
472 - <div id="wordpressfeed">
473 - <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?>
474 - </div>
475 - <div id="webtechfeed">
476 - <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?>
477 - </div>
478 539 </div>
479 540 </div>
480 - <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 } ?>
481 544 </div>
482 -
483 545 <script type="text/javascript">
484 - var feed = new Array;
485 - feed[1]="autoptimizefeed";
486 - feed[2]="wordpressfeed";
487 - feed[3]="webtechfeed";
488 - cookiename="autoptimize_feed";
489 -
490 546 jQuery(document).ready(function() {
491 547 check_ini_state();
492 548
493 - jQuery('#autoptimize_admin_feed').fadeTo("slow",1).show();
494 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();
495 550
496 - jQuery( "#feed_dropdown" ).change(function() {
497 - jQuery("#futtta_feed").fadeTo(0,0);
498 - jQuery("#futtta_feed").fadeTo("slow",1);
499 - });
500 -
501 551 jQuery( "#autoptimize_html" ).change(function() {
502 552 if (this.checked) {
503 553 jQuery(".html_sub:visible").fadeTo("fast",1);
504 554 } else {
@@ -514,19 +564,40 @@
514 564 }
515 565 });
516 566
517 567 jQuery( "#autoptimize_js_aggregate" ).change(function() {
518 - if (this.checked && jQuery("#autoptimize_js").attr('checked')) {
519 - jQuery(".js_aggregate:visible").fadeTo("fast",1);
520 - jQuery( "#min_excl_row" ).show();
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" );
521 576 } else {
522 - jQuery(".js_aggregate:visible").fadeTo("fast",.33);
523 - if ( jQuery( "#autoptimize_css_aggregate" ).prop('checked') == false ) {
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"
524 580 jQuery( "#min_excl_row" ).hide();
525 581 }
582 + check_exclusions( "js", "off" );
526 583 }
527 584 });
528 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 +
529 600 jQuery( "#autoptimize_css" ).change(function() {
530 601 if (this.checked) {
531 602 jQuery(".css_sub:visible").fadeTo("fast",1);
532 603 } else {
@@ -534,16 +605,18 @@
534 605 }
535 606 });
536 607
537 608 jQuery( "#autoptimize_css_aggregate" ).change(function() {
538 - if (this.checked && jQuery("#autoptimize_css").attr('checked')) {
609 + if (this.checked && jQuery("#autoptimize_css").prop('checked')) {
539 610 jQuery(".css_aggregate:visible").fadeTo("fast",1);
540 611 jQuery( "#min_excl_row" ).show();
612 + check_exclusions( "css", "on" );
541 613 } else {
542 614 jQuery(".css_aggregate:visible").fadeTo("fast",.33);
543 615 if ( jQuery( "#autoptimize_js_aggregate" ).prop('checked') == false ) {
544 616 jQuery( "#min_excl_row" ).hide();
545 617 }
618 + check_exclusions( "css", "off" );
546 619 }
547 620 });
548 621
549 622 jQuery( "#autoptimize_css_inline" ).change(function() {
@@ -568,13 +641,8 @@
568 641 } else {
569 642 jQuery("li.itemDetail:not(.multiSite)").fadeTo("fast",1);
570 643 }
571 644 });
572 -
573 - jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) });
574 - feedid=jQuery.cookie(cookiename);
575 - if(typeof(feedid) !== "string") feedid=1;
576 - show_feed(feedid);
577 645 })
578 646
579 647 // validate cdn_url.
580 648 var cdn_url=document.getElementById("cdn_url");
@@ -588,36 +656,56 @@
588 656 }});
589 657 }
590 658
591 659 function check_ini_state() {
592 - if (!jQuery("#autoptimize_css_defer").attr('checked')) {
660 + if (!jQuery("#autoptimize_css_defer").prop('checked')) {
593 661 jQuery("#autoptimize_css_defer_inline").hide();
594 662 }
595 - if (!jQuery("#autoptimize_html").attr('checked')) {
663 + if (!jQuery("#autoptimize_html").prop('checked')) {
596 664 jQuery(".html_sub:visible").fadeTo('fast',.33);
597 665 }
598 - if (!jQuery("#autoptimize_css").attr('checked')) {
666 + if (!jQuery("#autoptimize_css").prop('checked')) {
599 667 jQuery(".css_sub:visible").fadeTo('fast',.33);
600 668 }
601 - if (!jQuery("#autoptimize_css_aggregate").attr('checked')) {
669 + if (!jQuery("#autoptimize_css_aggregate").prop('checked')) {
602 670 jQuery(".css_aggregate:visible").fadeTo('fast',.33);
603 671 }
604 - if (!jQuery("#autoptimize_js").attr('checked')) {
605 - jQuery(".js_sub:visible").fadeTo('fast',.33);
672 + if (jQuery("#autoptimize_js_aggregate").prop('checked')) {
673 + jQuery( ".js_aggregate" ).show( 'fast' );
674 + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'fast', .33 );
606 675 }
607 - if (!jQuery("#autoptimize_js_aggregate").attr('checked')) {
608 - jQuery(".js_aggregate:visible").fadeTo('fast',.33);
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 );
609 679 }
610 - if (jQuery("#autoptimize_enable_site_config").attr('checked')) {
680 + if (jQuery("#autoptimize_enable_site_config").prop('checked')) {
611 681 jQuery("li.itemDetail:not(.multiSite)").fadeTo('fast',.33);
612 682 }
683 + if (!jQuery("#autoptimize_js").prop('checked')) {
684 + jQuery(".js_sub:visible").fadeTo('fast',.33);
685 + }
613 686 }
614 687
615 - function show_feed(id) {
616 - jQuery('#futtta_feed').children().hide();
617 - jQuery('#'+feed[id]).show();
618 - jQuery("#feed_dropdown").val(id);
619 - 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 + }
620 708 }
621 709 </script>
622 710 </div>
623 711
@@ -625,17 +713,18 @@
625 713 }
626 714
627 715 public function addmenu()
628 716 {
717 + $_my_name = apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? __( 'Autoptimize Pro', 'autoptimize' ) : __( 'Autoptimize', 'autoptimize' );
629 718 if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
630 719 // multisite, network admin, ao network activated: add normal settings page at network level.
631 - $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
720 + $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
632 721 } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
633 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.
634 - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
723 + $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
635 724 } else {
636 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.
637 - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
726 + $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
638 727 }
639 728
640 729 add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
641 730 add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
@@ -642,9 +731,8 @@
642 731 }
643 732
644 733 public function autoptimize_admin_scripts()
645 734 {
646 - wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true );
647 735 wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
648 736 }
649 737
650 738 public function autoptimize_admin_styles()
@@ -655,11 +743,14 @@
655 743
656 744 public function registersettings() {
657 745 register_setting( 'autoptimize', 'autoptimize_html' );
658 746 register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
747 + register_setting( 'autoptimize', 'autoptimize_html_minify_inline' );
659 748 register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
660 749 register_setting( 'autoptimize', 'autoptimize_js' );
661 750 register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
751 + register_setting( 'autoptimize', 'autoptimize_js_defer_not_aggregate' );
752 + register_setting( 'autoptimize', 'autoptimize_js_defer_inline' );
662 753 register_setting( 'autoptimize', 'autoptimize_js_exclude' );
663 754 register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
664 755 register_setting( 'autoptimize', 'autoptimize_js_justhead' );
665 756 register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
@@ -678,8 +769,11 @@
678 769 register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
679 770 register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
680 771 register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
681 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' );
682 776 }
683 777
684 778 public function setmeta( $links, $file = null )
685 779 {
@@ -713,32 +807,38 @@
713 807 */
714 808 public static function get_defaults()
715 809 {
716 810 static $config = array(
717 - 'autoptimize_html' => 0,
718 - 'autoptimize_html_keepcomments' => 0,
719 - 'autoptimize_enable_site_config' => 1,
720 - 'autoptimize_js' => 0,
721 - 'autoptimize_js_aggregate' => 1,
722 - 'autoptimize_js_exclude' => 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js',
723 - 'autoptimize_js_trycatch' => 0,
724 - 'autoptimize_js_justhead' => 0,
725 - 'autoptimize_js_include_inline' => 0,
726 - 'autoptimize_js_forcehead' => 0,
727 - 'autoptimize_css' => 0,
728 - 'autoptimize_css_aggregate' => 1,
729 - 'autoptimize_css_exclude' => 'admin-bar.min.css, dashicons.min.css, wp-content/cache/, wp-content/uploads/',
730 - 'autoptimize_css_justhead' => 0,
731 - 'autoptimize_css_include_inline' => 1,
732 - 'autoptimize_css_defer' => 0,
733 - 'autoptimize_css_defer_inline' => '',
734 - 'autoptimize_css_inline' => 0,
735 - 'autoptimize_css_datauris' => 0,
736 - 'autoptimize_cdn_url' => '',
737 - 'autoptimize_cache_nogzip' => 1,
738 - 'autoptimize_optimize_logged' => 1,
739 - 'autoptimize_optimize_checkout' => 0,
740 - 'autoptimize_minify_excluded' => 1,
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,
741 841 );
742 842
743 843 return $config;
744 844 }
@@ -756,8 +856,9 @@
756 856 'autoptimize_extra_radio_field_4' => '1',
757 857 'autoptimize_extra_text_field_2' => '',
758 858 'autoptimize_extra_text_field_3' => '',
759 859 'autoptimize_extra_text_field_7' => '',
860 + 'autoptimize_extra_checkbox_field_8' => '0',
760 861 );
761 862
762 863 return $defaults;
763 864 }
@@ -774,31 +875,24 @@
774 875 'autoptimize_imgopt_select_field_2' => '2', // quality glossy.
775 876 'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
776 877 'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
777 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).
778 881 );
779 882 return $defaults;
780 883 }
781 884
782 885 /**
783 - * Returns preload polyfill JS.
886 + * Returns preload JS onload handler.
784 887 *
785 - * @return string
786 - */
787 - public static function get_ao_css_preload_polyfill()
788 - {
789 - $preload_poly = apply_filters( 'autoptimize_css_preload_polyfill', '<script data-cfasync=\'false\'>!function(t){"use strict";t.loadCSS||(t.loadCSS=function(){});var e=loadCSS.relpreload={};if(e.support=function(){var e;try{e=t.document.createElement("link").relList.supports("preload")}catch(t){e=!1}return function(){return e}}(),e.bindMediaToggle=function(t){function e(){t.media=a}var a=t.media||"all";t.addEventListener?t.addEventListener("load",e):t.attachEvent&&t.attachEvent("onload",e),setTimeout(function(){t.rel="stylesheet",t.media="only x"}),setTimeout(e,3e3)},e.poly=function(){if(!e.support())for(var a=t.document.getElementsByTagName("link"),n=0;n<a.length;n++){var o=a[n];"preload"!==o.rel||"style"!==o.getAttribute("as")||o.getAttribute("data-loadcss")||(o.setAttribute("data-loadcss",!0),e.bindMediaToggle(o))}},!e.support()){e.poly();var a=t.setInterval(e.poly,500);t.addEventListener?t.addEventListener("load",function(){e.poly(),t.clearInterval(a)}):t.attachEvent&&t.attachEvent("onload",function(){e.poly(),t.clearInterval(a)})}"undefined"!=typeof exports?exports.loadCSS=loadCSS:t.loadCSS=loadCSS}("undefined"!=typeof global?global:this);</script>' );
790 - return $preload_poly;
791 - }
792 -
793 - /**
794 - * Returns preload JS onload handler.
888 + * @param string $media media attribute value the JS to use.
795 889 *
796 890 * @return string
797 891 */
798 - public static function get_ao_css_preload_onload()
892 + public static function get_ao_css_preload_onload( $media = 'all' )
799 893 {
800 - $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.rel='stylesheet'" );
894 + $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" );
801 895 return $preload_onload;
802 896 }
803 897
804 898 public function get( $key )
@@ -913,11 +1007,86 @@
913 1007 *
914 1008 * @return bool
915 1009 */
916 1010 public static function should_show_menu_tabs() {
917 - if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
1011 + if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) || false === autoptimizeOptionWrapper::is_ao_active_for_network() ) {
918 1012 return true;
919 1013 } else {
920 1014 return false;
921 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;
922 1091 }
923 1092 }