PluginProbe
Autoptimize / 3.0.3
Autoptimize v3.0.3
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 +281 -138 2.7.03.0.3 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 + $metaBox = 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).
@@ -95,9 +100,9 @@
95 100
96 101 public function show_config()
97 102 {
98 103 $conf = self::instance();
99 -?>
104 + ?>
100 105 <style>
101 106 /* title and button */
102 107 #ao_title_and_button:after {content:''; display:block; clear:both;}
103 108
@@ -113,8 +118,10 @@
113 118 }
114 119
115 120 input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:normal;}
116 121 #autoptimize_main .cb_label {display: block; padding-left: 25px; text-indent: -25px;}
122 +#autoptimize_main .form-table th {padding-top: 15px; padding-bottom: 15px;}
123 +#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 124
118 125 /* rss block */
119 126 #futtta_feed ul{list-style:outside;}
120 127 #futtta_feed {font-size:medium; margin:0px 20px;}
@@ -187,9 +194,9 @@
187 194 </p></div>
188 195 <?php } ?>
189 196
190 197 <div id="autoptimize_main">
191 - <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
198 + <h1 id="ao_title"><?php apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? _e( 'Autoptimize Pro Settings', 'autoptimize' ) : _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
192 199 <?php echo $this->ao_admin_tabs(); ?>
193 200
194 201 <form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
195 202 <?php settings_fields( 'autoptimize' ); ?>
@@ -218,25 +225,40 @@
218 225 <h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
219 226 <table class="form-table">
220 227 <tr valign="top">
221 228 <th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th>
222 -<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
229 +<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo $conf->get( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
223 230 </tr>
224 -<tr valign="top" class="js_sub">
231 +<tr valign="top" class="js_sub js_aggregate_master">
225 232 <th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
226 233 <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" ' : ''; ?>/>
227 -<?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>
234 +<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking?', 'autoptimize' ); ?></label></td>
228 235 </tr>
229 -<tr valign="top" class="js_sub js_aggregate">
230 -<th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
231 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
232 -<?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>
236 +<tr valign="top" class="js_sub js_aggregate hidden">
237 +<th scope="row">&emsp;<?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
238 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo $conf->get( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
239 +<?php _e( 'Let Autoptimize also extract JS from the HTML (discouraged as it can make Autoptimize\'s cache size grow quickly)', 'autoptimize' ); ?></label></td>
233 240 </tr>
234 -<tr valign="top" class="js_sub js_aggregate">
235 -<th scope="row"><?php _e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
236 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
237 -<?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td>
241 +<tr valign="top" class="js_sub js_aggregate hidden">
242 +<th scope="row">&emsp;<?php _e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
243 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo $conf->get( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
244 +<?php _e( 'Load JavaScript early (discouraged as it makes the JS render blocking)', 'autoptimize' ); ?></label></td>
238 245 </tr>
246 +<tr valign="top" class="js_sub js_aggregate hidden">
247 +<th scope="row">&emsp;<?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
248 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo $conf->get( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
249 +<?php _e( 'If your aggregated scripts break because of a JS-error, you might want to try this, but generally discouraged.', 'autoptimize' ); ?></label></td>
250 +</tr>
251 +<tr valign="top" class="js_sub js_not_aggregate_master">
252 +<th scope="row"><?php _e( 'Do not aggregate but defer?', 'autoptimize' ); ?></th>
253 +<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" ' : ''; ?>/>
254 +<?php _e( 'Individual JS-files will be minified and deferred, making them non-render-blocking.', 'autoptimize' ); ?></label></td>
255 +</tr>
256 +<tr valign="top" id="js_defer_inline" class="js_sub js_not_aggregate hidden">
257 +<th scope="row">&emsp;<?php _e( 'Also defer inline JS?', 'autoptimize' ); ?></th>
258 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_defer_inline" <?php echo $conf->get( 'autoptimize_js_defer_inline' ) ? 'checked="checked" ' : ''; ?>/>
259 +<?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>
260 +</tr>
239 261 <?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
240 262 <tr valign="top" class="js_sub js_aggregate">
241 263 <th scope="row">
242 264 <?php
@@ -243,24 +265,23 @@
243 265 _e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
244 266 echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
245 267 ?>
246 268 </th>
247 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
269 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo $conf->get( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
248 270 <?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>
249 271 </tr>
250 272 <?php } ?>
251 273 <tr valign="top" class="js_sub">
252 274 <th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th>
253 -<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 />
275 +<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', '' ) ); ?>"/><br />
254 276 <?php
255 -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' );
277 +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' );
256 278 ?>
257 279 </label></td>
258 280 </tr>
259 -<tr valign="top" class="js_sub js_aggregate">
260 -<th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
261 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
262 -<?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td>
281 +<tr valign="top">
282 +<th scope="row"><?php _e( 'Remove Unused JavaScript?', 'autoptimize' ); ?></th>
283 +<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>
263 284 </tr>
264 285 </table>
265 286 </li>
266 287
@@ -268,9 +289,9 @@
268 289 <h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2>
269 290 <table class="form-table">
270 291 <tr valign="top">
271 292 <th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th>
272 -<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
293 +<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo $conf->get( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
273 294 </tr>
274 295 <tr class="css_sub" valign="top">
275 296 <th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
276 297 <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" ' : ''; ?>/>
@@ -277,14 +298,14 @@
277 298 <?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>
278 299 </tr>
279 300 <tr valign="top" class="css_sub css_aggregate">
280 301 <th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th>
281 -<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" ' : ''; ?>/>
302 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo $conf->get( 'autoptimize_css_include_inline', '1' ) ? 'checked="checked" ' : ''; ?>/>
282 303 <?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
283 304 </tr>
284 305 <tr class="css_sub css_aggregate" valign="top">
285 306 <th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th>
286 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
307 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo $conf->get( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
287 308 <?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
288 309 </tr>
289 310 <?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
290 311 <tr valign="top" class="css_sub css_aggregate">
@@ -293,41 +314,50 @@
293 314 _e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
294 315 echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
295 316 ?>
296 317 </th>
297 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
318 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo $conf->get( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
298 319 <?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td>
299 320 </tr>
300 321 <?php } ?>
301 322 <tr valign="top" class="css_sub">
302 -<th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th>
303 -<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" ' : ''; ?>/>
323 +<th scope="row"><?php _e( 'Eliminate render-blocking CSS?', 'autoptimize' ); ?></th>
324 +<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" ' : ''; ?>/>
304 325 <?php
305 -_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' );
326 +_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' );
306 327 echo ' ';
307 328 $critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' );
308 329 // translators: links "autoptimize critical CSS" tab.
309 -echo sprintf( __( 'This can be fully automated for different types of pages on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' );
330 +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>' );
310 331 ?>
311 332 </label></td>
312 333 </tr>
313 334 <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
314 335 <th scope="row"></th>
315 -<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>
336 +<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>
316 337 </tr>
317 338 <tr valign="top" class="css_sub css_aggregate">
318 339 <th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th>
319 -<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" ' : ''; ?>/>
340 +<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" ' : ''; ?>/>
320 341 <?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>
321 342 </tr>
322 343 <tr valign="top" class="css_sub">
323 344 <th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th>
324 -<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 />
345 +<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr( $conf->get( 'autoptimize_css_exclude', '' ) ); ?>"/><br />
325 346 <?php
326 347 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' );
327 348 ?>
328 349 </label></td>
329 350 </tr>
351 +<?php if ( false === autoptimizeUtils::is_plugin_active( 'unusedcss/unusedcss.php' ) ) { ?>
352 +<tr valign="top">
353 +<th scope="row"><?php _e( 'Remove Unused CSS?', 'autoptimize' ); ?></th>
354 +<?php
355 +$_rapidload_link = 'https://misc.optimizingmatters.com/partners/?from=csssettings&partner=rapidload';
356 +?>
357 +<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>
358 +</tr>
359 +<?php } ?>
330 360 </table>
331 361 </li>
332 362
333 363 <li class="itemDetail">
@@ -334,13 +364,13 @@
334 364 <h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2>
335 365 <table class="form-table">
336 366 <tr valign="top">
337 367 <th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th>
338 -<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
368 +<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo $conf->get( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
339 369 </tr>
340 370 <tr class="html_sub" valign="top">
341 371 <th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th>
342 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
372 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo $conf->get( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
343 373 <?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td>
344 374 </tr>
345 375 </table>
346 376 </li>
@@ -349,10 +379,23 @@
349 379 <h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2>
350 380 <table class="form-table">
351 381 <tr valign="top">
352 382 <th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th>
353 -<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 />
354 -<?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>
383 +<?php
384 +if ( true === autoptimizeImages::imgopt_active() && true === apply_filters( 'autoptimize_filter_cdn_set_by_imgopt', false ) ) {
385 + // cdn set by imgopt, not to be changealbe in the settings.
386 + $cdn_editable = 'disabled';
387 + $cdn_placeholder = 'placeholder="' . __( 'The CDN has automatically been set to make use of the image optimization CDN.', 'autoptimize' ) . ' "';
388 + $cdn_description = '';
389 +} else {
390 + $cdn_editable = '';
391 + $cdn_placeholder = 'placeholder="' . __( 'example: //cdn.yoursite.com/', 'autoptimize' ) . ' "';
392 + $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' );
393 +}
394 +?>
395 +<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 />
396 +<?php echo $cdn_description; ?>
397 +</label></td>
355 398 </tr>
356 399 </table>
357 400 </li>
358 401
@@ -378,9 +421,9 @@
378 421 if ( $ao_cache_size > 0 ) {
379 422 $details = ', ~' . $ao_cache_size . ' total';
380 423 }
381 424 // translators: Kilobytes + timestamp shown.
382 - 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] ) );
425 + 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] ) );
383 426 }
384 427 ?>
385 428 </td>
386 429 </tr>
@@ -391,9 +434,9 @@
391 434 <h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2>
392 435 <table class="form-table">
393 436 <tr valign="top" >
394 437 <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th>
395 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_nogzip', '1' ) ? 'checked="checked" ' : ''; ?>/>
438 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo $conf->get( 'autoptimize_cache_nogzip') ? 'checked="checked" ' : ''; ?>/>
396 439 <?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>
397 440 </tr>
398 441 <?php
399 442 $_min_excl_class = '';
@@ -402,19 +445,19 @@
402 445 }
403 446 ?>
404 447 <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>">
405 448 <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th>
406 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_minify_excluded', '1' ) ? 'checked="checked" ' : ''; ?>/>
449 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo $conf->get( 'autoptimize_minify_excluded' ) ? 'checked="checked" ' : ''; ?>/>
407 450 <?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>
408 451 </tr>
409 452 <tr valign="top">
410 - <th scope="row"><?php _e( 'Experimental: enable 404 fallbacks.', 'autoptimize' ); ?></th>
411 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '' ) ? 'checked="checked" ' : ''; ?>/>
412 - <?php _e( 'Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. This experimental feature tries 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>
453 + <th scope="row"><?php _e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th>
454 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo $conf->get( 'autoptimize_cache_fallback' ) ? 'checked="checked" ' : ''; ?>/>
455 + <?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>
413 456 </tr>
414 457 <tr valign="top">
415 458 <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th>
416 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/>
459 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo $conf->get( 'autoptimize_optimize_logged' ) ? 'checked="checked" ' : ''; ?>/>
417 460 <?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>
418 461 </tr>
419 462 <?php
420 463 if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) {
@@ -420,13 +463,22 @@
420 463 if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) {
421 464 ?>
422 465 <tr valign="top" >
423 466 <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th>
424 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/>
467 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo $conf->get( 'autoptimize_optimize_checkout' ) ? 'checked="checked" ' : ''; ?>/>
425 468 <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
426 469 </td>
427 470 </tr>
428 471 <?php } ?>
472 + <?php
473 + if ( true === apply_filters( 'autoptimize_filter_enable_meta_ao_settings', true ) ) {
474 + ?>
475 + <tr valign="top">
476 + <th scope="row"><?php _e( 'Enable configuration per post/ page?', 'autoptimize' ); ?></th>
477 + <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" ' : ''; ?>/>
478 + <?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>
479 + </tr>
480 + <?php } ?>
429 481 </table>
430 482 </li>
431 483
432 484 </ul>
@@ -437,9 +489,10 @@
437 489 </p>
438 490
439 491 </form>
440 492 </div>
441 -<div id="autoptimize_admin_feed" class="hidden">
493 +<div id="autoptimize_admin_feed">
494 + <?php if ( apply_filters( 'autoptimize_filter_show_partner_tabs', true ) ) { ?>
442 495 <div class="autoptimize_banner hidden">
443 496 <ul>
444 497 <?php
445 498 if ( $this->settings_screen_do_remote_http ) {
@@ -459,50 +512,29 @@
459 512 <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li>
460 513 <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>
461 514 </ul>
462 515 </div>
516 + <?php } ?>
463 517 <div style="margin-left:10px;margin-top:-5px;">
464 518 <h2>
465 - <?php _e( 'futtta about', 'autoptimize' ); ?>
466 - <select id="feed_dropdown" >
467 - <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option>
468 - <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option>
469 - <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option>
470 - </select>
519 + <?php _e( 'Autoptimize news', 'autoptimize' ); ?>
471 520 </h2>
472 521 <div id="futtta_feed">
473 522 <div id="autoptimizefeed">
474 523 <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
475 524 </div>
476 - <div id="wordpressfeed">
477 - <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?>
478 - </div>
479 - <div id="webtechfeed">
480 - <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?>
481 - </div>
482 525 </div>
483 526 </div>
484 - <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>
527 + <?php if ( apply_filters( 'autoptimize_filter_show_partner_tabs', true ) ) { ?>
528 + <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>
529 + <?php } ?>
485 530 </div>
486 -
487 531 <script type="text/javascript">
488 - var feed = new Array;
489 - feed[1]="autoptimizefeed";
490 - feed[2]="wordpressfeed";
491 - feed[3]="webtechfeed";
492 - cookiename="autoptimize_feed";
493 -
494 532 jQuery(document).ready(function() {
495 533 check_ini_state();
496 534
497 - jQuery('#autoptimize_admin_feed').fadeTo("slow",1).show();
498 535 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();
499 536
500 - jQuery( "#feed_dropdown" ).change(function() {
501 - jQuery("#futtta_feed").fadeTo(0,0);
502 - jQuery("#futtta_feed").fadeTo("slow",1);
503 - });
504 -
505 537 jQuery( "#autoptimize_html" ).change(function() {
506 538 if (this.checked) {
507 539 jQuery(".html_sub:visible").fadeTo("fast",1);
508 540 } else {
@@ -518,18 +550,39 @@
518 550 }
519 551 });
520 552
521 553 jQuery( "#autoptimize_js_aggregate" ).change(function() {
522 - if (this.checked && jQuery("#autoptimize_js").attr('checked')) {
523 - jQuery(".js_aggregate:visible").fadeTo("fast",1);
524 - jQuery( "#min_excl_row" ).show();
554 + if (this.checked && jQuery("#autoptimize_js").prop('checked')) {
555 + jQuery( "#autoptimize_js_defer_not_aggregate" ).prop( 'checked', false ); // uncheck "defer not aggregate"
556 + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // ungrey self
557 + jQuery( ".js_aggregate" ).show( 'slow' ); // show sub-items
558 + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'slow', .33 ); // grey out "not aggregate"
559 + jQuery( ".js_not_aggregate" ).hide( 'slow' ); // hide not aggregate sub-items
560 + jQuery( "#min_excl_row" ).show(); // make sure "minify excluded" is visible
561 + check_exclusions( "js", "on" );
525 562 } else {
526 - jQuery(".js_aggregate:visible").fadeTo("fast",.33);
527 - if ( jQuery( "#autoptimize_css_aggregate" ).prop('checked') == false ) {
563 + jQuery( ".js_aggregate" ).hide( 'slow' ); // hide sub-itmes
564 + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // un-grey-out "not aggregate"
565 + if ( jQuery( "#autoptimize_css_aggregate" ).prop( 'checked' ) == false ) { // hide "minify excluded"
528 566 jQuery( "#min_excl_row" ).hide();
529 567 }
568 + check_exclusions( "js", "off" );
530 569 }
531 570 });
571 +
572 + jQuery( "#autoptimize_js_defer_not_aggregate" ).change(function() {
573 + if (this.checked && jQuery("#autoptimize_js").prop('checked')) {
574 + jQuery( "#autoptimize_js_aggregate" ).prop( 'checked', false ); // uncheck "aggregate JS"
575 + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // ungrey self
576 + jQuery( ".js_not_aggregate" ).show( 'slow'); // show sub-items
577 + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'slow', .33 ); // grey out "aggregate"
578 + jQuery( ".js_aggregate" ).hide( 'slow' ); // hide aggregate sub-items
579 + check_exclusions( "js", "off" );
580 + } else {
581 + jQuery( ".js_not_aggregate" ).hide( 'slow' ); // hide sub-items
582 + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // un-grey-out "aggregate"
583 + }
584 + });
532 585
533 586 jQuery( "#autoptimize_css" ).change(function() {
534 587 if (this.checked) {
535 588 jQuery(".css_sub:visible").fadeTo("fast",1);
@@ -538,16 +591,18 @@
538 591 }
539 592 });
540 593
541 594 jQuery( "#autoptimize_css_aggregate" ).change(function() {
542 - if (this.checked && jQuery("#autoptimize_css").attr('checked')) {
595 + if (this.checked && jQuery("#autoptimize_css").prop('checked')) {
543 596 jQuery(".css_aggregate:visible").fadeTo("fast",1);
544 597 jQuery( "#min_excl_row" ).show();
598 + check_exclusions( "css", "on" );
545 599 } else {
546 600 jQuery(".css_aggregate:visible").fadeTo("fast",.33);
547 601 if ( jQuery( "#autoptimize_js_aggregate" ).prop('checked') == false ) {
548 602 jQuery( "#min_excl_row" ).hide();
549 603 }
604 + check_exclusions( "css", "off" );
550 605 }
551 606 });
552 607
553 608 jQuery( "#autoptimize_css_inline" ).change(function() {
@@ -572,13 +627,8 @@
572 627 } else {
573 628 jQuery("li.itemDetail:not(.multiSite)").fadeTo("fast",1);
574 629 }
575 630 });
576 -
577 - jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) });
578 - feedid=jQuery.cookie(cookiename);
579 - if(typeof(feedid) !== "string") feedid=1;
580 - show_feed(feedid);
581 631 })
582 632
583 633 // validate cdn_url.
584 634 var cdn_url=document.getElementById("cdn_url");
@@ -592,36 +642,56 @@
592 642 }});
593 643 }
594 644
595 645 function check_ini_state() {
596 - if (!jQuery("#autoptimize_css_defer").attr('checked')) {
646 + if (!jQuery("#autoptimize_css_defer").prop('checked')) {
597 647 jQuery("#autoptimize_css_defer_inline").hide();
598 648 }
599 - if (!jQuery("#autoptimize_html").attr('checked')) {
649 + if (!jQuery("#autoptimize_html").prop('checked')) {
600 650 jQuery(".html_sub:visible").fadeTo('fast',.33);
601 651 }
602 - if (!jQuery("#autoptimize_css").attr('checked')) {
652 + if (!jQuery("#autoptimize_css").prop('checked')) {
603 653 jQuery(".css_sub:visible").fadeTo('fast',.33);
604 654 }
605 - if (!jQuery("#autoptimize_css_aggregate").attr('checked')) {
655 + if (!jQuery("#autoptimize_css_aggregate").prop('checked')) {
606 656 jQuery(".css_aggregate:visible").fadeTo('fast',.33);
607 657 }
608 - if (!jQuery("#autoptimize_js").attr('checked')) {
609 - jQuery(".js_sub:visible").fadeTo('fast',.33);
658 + if (jQuery("#autoptimize_js_aggregate").prop('checked')) {
659 + jQuery( ".js_aggregate" ).show( 'fast' );
660 + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'fast', .33 );
610 661 }
611 - if (!jQuery("#autoptimize_js_aggregate").attr('checked')) {
612 - jQuery(".js_aggregate:visible").fadeTo('fast',.33);
662 + if (jQuery("#autoptimize_js_defer_not_aggregate").prop('checked')) {
663 + jQuery( ".js_not_aggregate" ).show( 'fast' );
664 + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'fast', .33 );
613 665 }
614 - if (jQuery("#autoptimize_enable_site_config").attr('checked')) {
666 + if (jQuery("#autoptimize_enable_site_config").prop('checked')) {
615 667 jQuery("li.itemDetail:not(.multiSite)").fadeTo('fast',.33);
616 668 }
669 + if (!jQuery("#autoptimize_js").prop('checked')) {
670 + jQuery(".js_sub:visible").fadeTo('fast',.33);
671 + }
617 672 }
673 +
674 + function check_exclusions( what, state ) {
675 + exclusion_node = 'input[name="autoptimize_' + what + '_exclude"]';
676 + current_exclusion = jQuery( exclusion_node ).val();
618 677
619 - function show_feed(id) {
620 - jQuery('#futtta_feed').children().hide();
621 - jQuery('#'+feed[id]).show();
622 - jQuery("#feed_dropdown").val(id);
623 - jQuery.cookie(cookiename,id,{ expires: 365 });
678 + if ( what == "js" ) {
679 + default_exclusion = ", wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.min.js";
680 + } else if ( what == "css") {
681 + default_exclusion = ", admin-bar.min.css, dashicons.min.css, wp-content/cache/, wp-content/uploads/";
682 + }
683 +
684 + default_in_current = current_exclusion.indexOf(default_exclusion);
685 +
686 + if ( state == "on" && default_in_current == -1 ) {
687 + jQuery( exclusion_node ).val( current_exclusion + default_exclusion );
688 + } else if ( state = "off" && current_exclusion == default_exclusion ) {
689 + jQuery( exclusion_node ).val( "" );
690 + } else if ( state = "off" && default_in_current != -1 ) {
691 + new_exclusion = current_exclusion.substring( 0, default_in_current) + current_exclusion.substring( default_in_current + default_exclusion.length, current_exclusion.length );
692 + jQuery( exclusion_node ).val( new_exclusion );
693 + }
624 694 }
625 695 </script>
626 696 </div>
627 697
@@ -629,17 +699,18 @@
629 699 }
630 700
631 701 public function addmenu()
632 702 {
703 + $_my_name = apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? __( 'Autoptimize Pro', 'autoptimize' ) : __( 'Autoptimize', 'autoptimize' );
633 704 if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
634 705 // multisite, network admin, ao network activated: add normal settings page at network level.
635 - $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
706 + $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
636 707 } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
637 708 // 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.
638 - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
709 + $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
639 710 } else {
640 711 // 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.
641 - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
712 + $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
642 713 }
643 714
644 715 add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
645 716 add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
@@ -646,9 +717,8 @@
646 717 }
647 718
648 719 public function autoptimize_admin_scripts()
649 720 {
650 - wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true );
651 721 wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
652 722 }
653 723
654 724 public function autoptimize_admin_styles()
@@ -662,8 +732,10 @@
662 732 register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
663 733 register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
664 734 register_setting( 'autoptimize', 'autoptimize_js' );
665 735 register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
736 + register_setting( 'autoptimize', 'autoptimize_js_defer_not_aggregate' );
737 + register_setting( 'autoptimize', 'autoptimize_js_defer_inline' );
666 738 register_setting( 'autoptimize', 'autoptimize_js_exclude' );
667 739 register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
668 740 register_setting( 'autoptimize', 'autoptimize_js_justhead' );
669 741 register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
@@ -683,8 +755,9 @@
683 755 register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
684 756 register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
685 757 register_setting( 'autoptimize', 'autoptimize_minify_excluded' );
686 758 register_setting( 'autoptimize', 'autoptimize_cache_fallback' );
759 + register_setting( 'autoptimize', 'autoptimize_enable_meta_ao_settings' );
687 760 }
688 761
689 762 public function setmeta( $links, $file = null )
690 763 {
@@ -718,33 +791,36 @@
718 791 */
719 792 public static function get_defaults()
720 793 {
721 794 static $config = array(
722 - 'autoptimize_html' => 0,
723 - 'autoptimize_html_keepcomments' => 0,
724 - 'autoptimize_enable_site_config' => 1,
725 - 'autoptimize_js' => 0,
726 - 'autoptimize_js_aggregate' => 1,
727 - 'autoptimize_js_exclude' => 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js',
728 - 'autoptimize_js_trycatch' => 0,
729 - 'autoptimize_js_justhead' => 0,
730 - 'autoptimize_js_include_inline' => 0,
731 - 'autoptimize_js_forcehead' => 0,
732 - 'autoptimize_css' => 0,
733 - 'autoptimize_css_aggregate' => 1,
734 - 'autoptimize_css_exclude' => 'admin-bar.min.css, dashicons.min.css, wp-content/cache/, wp-content/uploads/',
735 - 'autoptimize_css_justhead' => 0,
736 - 'autoptimize_css_include_inline' => 1,
737 - 'autoptimize_css_defer' => 0,
738 - 'autoptimize_css_defer_inline' => '',
739 - 'autoptimize_css_inline' => 0,
740 - 'autoptimize_css_datauris' => 0,
741 - 'autoptimize_cdn_url' => '',
742 - 'autoptimize_cache_nogzip' => 1,
743 - 'autoptimize_optimize_logged' => 1,
744 - 'autoptimize_optimize_checkout' => 0,
745 - 'autoptimize_minify_excluded' => 1,
746 - 'autoptimize_cache_fallback' => '',
795 + 'autoptimize_html' => 0,
796 + 'autoptimize_html_keepcomments' => 0,
797 + 'autoptimize_enable_site_config' => 1,
798 + 'autoptimize_js' => 0,
799 + 'autoptimize_js_aggregate' => 0,
800 + 'autoptimize_js_defer_not_aggregate' => 1,
801 + 'autoptimize_js_defer_inline' => 1,
802 + 'autoptimize_js_exclude' => '', // 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.min.js',
803 + 'autoptimize_js_trycatch' => 0,
804 + 'autoptimize_js_justhead' => 0,
805 + 'autoptimize_js_include_inline' => 0,
806 + 'autoptimize_js_forcehead' => 0,
807 + 'autoptimize_css' => 0,
808 + 'autoptimize_css_aggregate' => 0,
809 + 'autoptimize_css_exclude' => '', // admin-bar.min.css, dashicons.min.css, wp-content/cache/, wp-content/uploads/',
810 + 'autoptimize_css_justhead' => 0,
811 + 'autoptimize_css_include_inline' => 0,
812 + 'autoptimize_css_defer' => 0,
813 + 'autoptimize_css_defer_inline' => '',
814 + 'autoptimize_css_inline' => 0,
815 + 'autoptimize_css_datauris' => 0,
816 + 'autoptimize_cdn_url' => '',
817 + 'autoptimize_cache_nogzip' => 1,
818 + 'autoptimize_optimize_logged' => 1,
819 + 'autoptimize_optimize_checkout' => 0,
820 + 'autoptimize_minify_excluded' => 1,
821 + 'autoptimize_cache_fallback' => 1,
822 + 'autoptimize_enable_meta_ao_settings' => 1,
747 823 );
748 824
749 825 return $config;
750 826 }
@@ -762,8 +838,9 @@
762 838 'autoptimize_extra_radio_field_4' => '1',
763 839 'autoptimize_extra_text_field_2' => '',
764 840 'autoptimize_extra_text_field_3' => '',
765 841 'autoptimize_extra_text_field_7' => '',
842 + 'autoptimize_extra_checkbox_field_8' => '0',
766 843 );
767 844
768 845 return $defaults;
769 846 }
@@ -780,31 +857,24 @@
780 857 'autoptimize_imgopt_select_field_2' => '2', // quality glossy.
781 858 'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
782 859 'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
783 860 'autoptimize_imgopt_text_field_5' => '', // lazy load exclusions empty.
861 + 'autoptimize_imgopt_text_field_6' => '', // optimization exclusions empty.
862 + 'autoptimize_imgopt_number_field_7' => '2', // lazy load from nth image (0 = lazyload all).
784 863 );
785 864 return $defaults;
786 865 }
787 866
788 867 /**
789 - * Returns preload polyfill JS.
868 + * Returns preload JS onload handler.
790 869 *
791 - * @return string
792 - */
793 - public static function get_ao_css_preload_polyfill()
794 - {
795 - $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>' );
796 - return $preload_poly;
797 - }
798 -
799 - /**
800 - * Returns preload JS onload handler.
870 + * @param string $media media attribute value the JS to use.
801 871 *
802 872 * @return string
803 873 */
804 - public static function get_ao_css_preload_onload()
874 + public static function get_ao_css_preload_onload( $media = 'all' )
805 875 {
806 - $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.rel='stylesheet'" );
876 + $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" );
807 877 return $preload_onload;
808 878 }
809 879
810 880 public function get( $key )
@@ -919,11 +989,84 @@
919 989 *
920 990 * @return bool
921 991 */
922 992 public static function should_show_menu_tabs() {
923 - if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
993 + if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) || false === autoptimizeOptionWrapper::is_ao_active_for_network() ) {
924 994 return true;
925 995 } else {
926 996 return false;
927 997 }
998 + }
999 +
1000 + /**
1001 + * Returns the post meta AO settings for reuse in different optimizers.
1002 + *
1003 + * @return bool
1004 + */
1005 + public static function get_post_meta_ao_settings( $optim ) {
1006 + if ( ! autoptimizeConfig::is_ao_meta_settings_active() ) {
1007 + // Per page/post settings not active, so always return true (as in; can be optimized).
1008 + if ( in_array( $optim, array( 'ao_post_preload' ) ) ) {
1009 + // but make sure to return false for text input.
1010 + return false;
1011 + }
1012 + return true;
1013 + }
1014 +
1015 + static $_meta_value = null;
1016 + if ( null === $_meta_value ) {
1017 + global $wp_query;
1018 + if ( isset( $wp_query ) && ( is_page() || is_single() ) ) {
1019 + $_meta_value = get_post_meta( get_the_ID(), 'ao_post_optimize', true );
1020 + } else if ( isset( $wp_query ) ) {
1021 + $_meta_value = false;
1022 + }
1023 + }
1024 +
1025 + // If autoptimize_post_optimize !== 'on' (except for ao_post_preload, which can have other values) then always return false as all is off.
1026 + // fixme: need unit tests to ensure below logic is sane!
1027 + if ( empty( $_meta_value ) || ! is_array( $_meta_value ) ) {
1028 + // no metabox values so all optimizations are a go.
1029 + if ( in_array( $optim, array( 'ao_post_preload' ) ) ) {
1030 + // but make sure to return false for text input.
1031 + return false;
1032 + }
1033 + return true;
1034 + } else if ( array_key_exists( 'ao_post_optimize', $_meta_value ) && 'on' !== $_meta_value['ao_post_optimize'] ) {
1035 + // ao entirely off for this page.
1036 + return false;
1037 + } else if ( array_key_exists( $optim, $_meta_value ) && empty( $_meta_value[$optim] ) ) {
1038 + // sub-optimization off for this page.
1039 + return false;
1040 + } else if ( array_key_exists( $optim, $_meta_value ) && 'on' === $_meta_value[$optim] ) {
1041 + // sub-optimization is explictly on.
1042 + return true;
1043 + } else if ( array_key_exists( $optim, $_meta_value ) && in_array( $optim, array( 'ao_post_preload' ) ) && ! empty( $_meta_value[$optim] ) ) {
1044 + // a non-bool metabox optimization (currently only preload field), return value instead of bool.
1045 + return $_meta_value[$optim];
1046 + } else if ( in_array( $optim, array( 'ao_post_preload' ) ) && ( ! array_key_exists( $optim, $_meta_value ) || empty( $_meta_value[$optim] ) ) ) {
1047 + // a non-bool metabox optimization not found or empty, so returning false.
1048 + return false;
1049 + } else {
1050 + // when in doubt "go" for optimization, but this should never happen?
1051 + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
1052 + error_log( 'AO metabox logic fallback; well, how did I get here? Maybe this helps: looking for ' . $optim . ' in ' . json_encode( $_meta_value ) );
1053 + }
1054 + return true;
1055 + }
1056 + }
1057 +
1058 + /**
1059 + * Are the post meta AO settings active (default: no)?
1060 + *
1061 + * @return bool
1062 + */
1063 + public static function is_ao_meta_settings_active() {
1064 + static $_meta_settings_active = null;
1065 +
1066 + if ( null === $_meta_settings_active ) {
1067 + $_meta_settings_active = apply_filters( 'autoptimize_filter_enable_meta_ao_settings', autoptimizeOptionWrapper::get_option( 'autoptimize_enable_meta_ao_settings', '1' ) );
1068 + }
1069 +
1070 + return $_meta_settings_active;
928 1071 }
929 1072 }