PluginProbe
Autoptimize / trunk
Autoptimize vtrunk
3.1.16 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 All 108 releases
← All changes | classes/autoptimizeConfig.php +407 -211 2.6.0 → trunk View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 - * Main configurtion logic.
3 + * Main configuration logic.
4 4 */
5 5
6 6 if ( ! defined( 'ABSPATH' ) ) {
7 7 exit;
@@ -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).
@@ -85,11 +90,11 @@
85 90
86 91 public function show_network_message() {
87 92 ?>
88 93 <div class="wrap">
89 - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
94 + <h1><?php esc_html_e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
90 95 <?php echo $this->ao_admin_tabs(); ?>
91 - <p style="font-size:120%;"><?php _e( 'Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize' ); ?></p>
96 + <p style="font-size:120%;"><?php echo apply_filters( 'autoptimize_filter_settingsscreen_multisite_network_message', esc_html__( 'Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize' ) ); ?></p>
92 97 </div>
93 98 <?php
94 99 }
95 100
@@ -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
@@ -111,10 +118,13 @@
111 118 .itemTitle {
112 119 margin-top: 0;
113 120 }
114 121
115 -input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:normal;}
122 +.form-table th{font-weight:normal;}
123 +#autoptimize_main form input:invalid {box-shadow: 0 0 1px 1px red;}
116 124 #autoptimize_main .cb_label {display: block; padding-left: 25px; text-indent: -25px;}
125 +#autoptimize_main .form-table th {padding-top: 15px; padding-bottom: 15px;}
126 +#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 127
118 128 /* rss block */
119 129 #futtta_feed ul{list-style:outside;}
120 130 #futtta_feed {font-size:medium; margin:0px 20px;}
@@ -179,16 +189,10 @@
179 189 </style>
180 190
181 191 <div class="wrap">
182 192
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' ); ?>
186 - </p></div>
187 -<?php } ?>
188 -
189 193 <div id="autoptimize_main">
190 - <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
194 + <h1 id="ao_title"><?php apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? esc_html_e( 'Autoptimize Pro Settings', 'autoptimize' ) : esc_html_e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
191 195 <?php echo $this->ao_admin_tabs(); ?>
192 196
193 197 <form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
194 198 <?php settings_fields( 'autoptimize' ); ?>
@@ -199,178 +203,231 @@
199 203 // Only show enable site configuration in network site option.
200 204 if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
201 205 ?>
202 206 <li class="itemDetail multiSite">
203 - <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2>
207 + <h2 class="itemTitle"><?php esc_html_e( 'Multisite Options', 'autoptimize' ); ?></h2>
204 208 <table class="form-table">
205 209 <tr valign="top">
206 - <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th>
210 + <th scope="row"><?php esc_html_e( 'Enable site configuration?', 'autoptimize' ); ?></th>
207 211 <td><label class="cb_label"><input type="checkbox" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ? 'checked="checked" ' : ''; ?>/>
208 - <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td>
212 + <?php esc_html_e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td>
209 213 </tr>
210 214 </table>
211 215 </li>
212 216 <?php } else { ?>
213 217 <input type="hidden" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" value="on" />
214 -<?php } ?>
218 +<?php } ?>
215 219
216 220 <li class="itemDetail">
217 -<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
221 +<h2 class="itemTitle"><?php esc_html_e( 'JavaScript Options', 'autoptimize' ); ?></h2>
218 222 <table class="form-table">
219 223 <tr valign="top">
220 -<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>
224 +<th scope="row"><?php esc_html_e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th>
225 +<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo $conf->get( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
222 226 </tr>
223 -<tr valign="top" class="js_sub">
224 -<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
227 +<tr valign="top" class="js_sub js_aggregate_master">
228 +<th scope="row"><?php esc_html_e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
225 229 <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>
230 +<?php esc_html_e( 'Aggregate all linked JS-files to have them loaded non-render blocking?', 'autoptimize' ); ?></label></td>
227 231 </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>
232 +<tr valign="top" class="js_sub js_aggregate hidden">
233 +<th scope="row">&emsp;<?php esc_html_e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
234 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo $conf->get( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
235 +<?php esc_html_e( 'Let Autoptimize also extract JS from the HTML (discouraged as it can make Autoptimize\'s cache size grow quickly)', 'autoptimize' ); ?></label></td>
232 236 </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>
237 +<tr valign="top" class="js_sub js_aggregate hidden">
238 +<th scope="row">&emsp;<?php esc_html_e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
239 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo $conf->get( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
240 +<?php esc_html_e( 'Load JavaScript early (discouraged as it makes the JS render blocking)', 'autoptimize' ); ?></label></td>
237 241 </tr>
242 +<tr valign="top" class="js_sub js_aggregate hidden">
243 +<th scope="row">&emsp;<?php esc_html_e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
244 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo $conf->get( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
245 +<?php esc_html_e( 'If your aggregated scripts break because of a JS-error, you might want to try this, but generally discouraged.', 'autoptimize' ); ?></label></td>
246 +</tr>
247 +<tr valign="top" class="js_sub js_not_aggregate_master">
248 +<th scope="row"><?php esc_html_e( 'Do not aggregate but defer?', 'autoptimize' ); ?></th>
249 +<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" ' : ''; ?>/>
250 +<?php esc_html_e( 'Individual JS-files will be minified and deferred, making them non-render-blocking.', 'autoptimize' ); ?></label></td>
251 +</tr>
252 +<tr valign="top" id="js_defer_inline" class="js_sub js_not_aggregate hidden">
253 +<th scope="row">&emsp;<?php esc_html_e( 'Also defer inline JS?', 'autoptimize' ); ?></th>
254 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_defer_inline" <?php echo $conf->get( 'autoptimize_js_defer_inline' ) ? 'checked="checked" ' : ''; ?>/>
255 +<?php esc_html_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>
256 +</tr>
238 257 <?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
239 258 <tr valign="top" class="js_sub js_aggregate">
240 259 <th scope="row">
241 260 <?php
242 - _e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
243 - echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
261 + esc_html_e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
262 + echo ' <i>' . esc_html__( '(deprecated)', 'autoptimize' ) . '</i>';
244 263 ?>
245 264 </th>
246 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
247 -<?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>
265 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo $conf->get( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
266 +<?php esc_html_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 267 </tr>
249 268 <?php } ?>
250 269 <tr valign="top" class="js_sub">
251 -<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 />
270 +<th scope="row"><?php esc_html_e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th>
271 +<td><label><input type="text" pattern="[^\*]*" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', '' ) ); ?>"/><br />
253 272 <?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' );
273 +echo esc_html__( 'A comma-separated list of scripts you do not want optimized, for example \'whatever.js, my_var\' (without the quotes).', 'autoptimize' ) . ' ' . esc_html__( '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 274 ?>
256 275 </label></td>
257 276 </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>
277 +<tr valign="top">
278 +<th scope="row"><?php esc_html_e( 'Remove Unused JavaScript?', 'autoptimize' ); ?></th>
279 +<td><?php esc_html_e( 'Autoptimize combines your theme & plugins\' JavaScript, but does not know what is used and what is 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 280 </tr>
263 281 </table>
264 282 </li>
265 283
266 284 <li class="itemDetail">
267 -<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2>
285 +<h2 class="itemTitle"><?php esc_html_e( 'CSS Options', 'autoptimize' ); ?></h2>
268 286 <table class="form-table">
269 287 <tr valign="top">
270 -<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>
288 +<th scope="row"><?php esc_html_e( 'Optimize CSS Code?', 'autoptimize' ); ?></th>
289 +<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo $conf->get( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
272 290 </tr>
273 291 <tr class="css_sub" valign="top">
274 -<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
292 +<th scope="row"><?php esc_html_e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
275 293 <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 -<?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>
294 +<?php esc_html_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 295 </tr>
278 296 <tr valign="top" class="css_sub css_aggregate">
279 -<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" ' : ''; ?>/>
281 -<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
297 +<th scope="row"><?php esc_html_e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th>
298 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo $conf->get( 'autoptimize_css_include_inline', '1' ) ? 'checked="checked" ' : ''; ?>/>
299 +<?php esc_html_e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
282 300 </tr>
283 301 <tr class="css_sub css_aggregate" valign="top">
284 -<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" ' : ''; ?>/>
286 -<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
302 +<th scope="row"><?php esc_html_e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th>
303 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo $conf->get( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
304 +<?php esc_html_e( 'Enable this to include small background images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
287 305 </tr>
288 306 <?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
289 307 <tr valign="top" class="css_sub css_aggregate">
290 308 <th scope="row">
291 309 <?php
292 -_e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
293 -echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
310 +esc_html_e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
311 +echo ' <i>' . esc_html__( '(deprecated)', 'autoptimize' ) . '</i>';
294 312 ?>
295 313 </th>
296 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
297 -<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td>
314 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo $conf->get( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
315 +<?php esc_html_e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td>
298 316 </tr>
299 317 <?php } ?>
300 318 <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" ' : ''; ?>/>
319 +<th scope="row"><?php esc_html_e( 'Eliminate render-blocking CSS?', 'autoptimize' ); ?></th>
320 +<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 321 <?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 -}
322 +_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' );
323 +echo ' ';
324 +$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' );
325 +// translators: links "autoptimize critical CSS" tab.
326 +echo sprintf( esc_html__( '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 327 ?>
312 328 </label></td>
313 329 </tr>
314 330 <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
315 331 <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>
332 +<td><label><textarea rows="10" cols="10" style="width:100%;" spellcheck="false" placeholder="<?php esc_html_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 333 </tr>
318 334 <tr valign="top" class="css_sub css_aggregate">
319 -<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>
335 +<th scope="row"><?php esc_html_e( 'Inline all CSS?', 'autoptimize' ); ?></th>
336 +<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" ' : ''; ?>/>
337 +<?php esc_html_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 anymore, breaking thumbnails when sharing.', 'autoptimize' ); ?></label></td>
322 338 </tr>
323 339 <tr valign="top" class="css_sub">
324 -<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 />
340 +<th scope="row"><?php esc_html_e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th>
341 +<td><label><input type="text" pattern="[^\*]*" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr( $conf->get( 'autoptimize_css_exclude', '' ) ); ?>"/><br />
326 342 <?php
327 -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' );
343 +echo esc_html__( 'A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize' ) . ' ' . esc_html__( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' );
328 344 ?>
329 345 </label></td>
330 346 </tr>
347 +<?php
348 + $_availabilities = autoptimizeOptionWrapper::get_option( 'autoptimize_service_availablity' );
349 + if ( empty( $_availabilities ) || ! is_array( $_availabilities ) || ! array_key_exists( 'rapidload', $_availabilities ) || ! array_key_exists( 'status', $_availabilities['rapidload'] ) ) {
350 + $rapidload_true = true;
351 + } else if ( $_availabilities['rapidload']['status'] === 'up' ) {
352 + $rapidload_true = true;
353 + } else if ( $_availabilities['rapidload']['status'] !== 'up' ) {
354 + $rapidload_true = false;
355 + } else {
356 + $rapidload_true = false;
357 + }
358 +?>
359 +<?php if ( $rapidload_true && false === autoptimizeUtils::is_plugin_active( 'unusedcss/unusedcss.php' ) ) { ?>
360 +<tr valign="top">
361 +<th scope="row"><?php esc_html_e( 'Remove Unused CSS?', 'autoptimize' ); ?></th>
362 +<?php
363 +$_rapidload_link = 'https://misc.optimizingmatters.com/partners/?from=csssettings&partner=rapidload';
364 +?>
365 +<td><?php
366 +// translators: a link to rapidload + strong tags
367 +echo sprintf( esc_html__( 'If Google Pagespeed Insights detects unused CSS, consider using %1$sthe premium Rapidload service%2$s to %3$sreduce your site\'s CSS size to up to 90&#37;%4$s, resulting in a slimmer, faster site!', 'autoptimize' ), '<a href="' . $_rapidload_link . '" target="_blank">', '</a>', '<strong>', '</strong>' ); ?></td>
368 +</tr>
369 +<?php } ?>
331 370 </table>
332 371 </li>
333 372
334 373 <li class="itemDetail">
335 -<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2>
374 +<h2 class="itemTitle"><?php esc_html_e( 'HTML Options', 'autoptimize' ); ?></h2>
336 375 <table class="form-table">
337 376 <tr valign="top">
338 -<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>
377 +<th scope="row"><?php esc_html_e( 'Optimize HTML Code?', 'autoptimize' ); ?></th>
378 +<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo $conf->get( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td>
340 379 </tr>
341 380 <tr class="html_sub" valign="top">
342 -<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" ' : ''; ?>/>
344 -<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td>
381 +<th scope="row"><?php esc_html_e( 'Also minify inline JS/ CSS?', 'autoptimize' ); ?></th>
382 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_minify_inline" <?php echo $conf->get( 'autoptimize_html_minify_inline' ) ? 'checked="checked" ' : ''; ?>/>
383 +<?php esc_html_e( 'Enable this if you want inline JS or CSS to be minified as well.', 'autoptimize' ); ?></label></td>
345 384 </tr>
385 +<tr class="html_sub" valign="top">
386 +<th scope="row"><?php esc_html_e( 'Keep HTML comments?', 'autoptimize' ); ?></th>
387 +<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo $conf->get( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/>
388 +<?php esc_html_e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td>
389 +</tr>
346 390 </table>
347 391 </li>
348 392
349 393 <li class="itemDetail">
350 -<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2>
394 +<h2 class="itemTitle"><?php esc_html_e( 'CDN Options', 'autoptimize' ); ?></h2>
351 395 <table class="form-table">
352 396 <tr valign="top">
353 -<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>
397 +<th scope="row"><?php esc_html_e( 'CDN Base URL', 'autoptimize' ); ?></th>
398 +<?php
399 +if ( true === autoptimizeImages::imgopt_active() && true === apply_filters( 'autoptimize_filter_cdn_set_by_imgopt', false ) ) {
400 + // cdn set by imgopt, not to be changealbe in the settings.
401 + $cdn_editable = 'disabled';
402 + $cdn_placeholder = 'placeholder="' . esc_html__( 'The CDN has automatically been set to make use of the image optimization CDN.', 'autoptimize' ) . ' "';
403 + $cdn_description = '';
404 +} else {
405 + $cdn_editable = '';
406 + $cdn_placeholder = 'placeholder="' . esc_html__( 'example: //cdn.yoursite.com/', 'autoptimize' ) . ' "';
407 + $cdn_description = esc_html__( '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' );
408 +}
409 +?>
410 +<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 />
411 +<?php echo $cdn_description; ?>
412 +</label></td>
356 413 </tr>
357 414 </table>
358 415 </li>
359 416
360 417 <li class="itemDetail">
361 -<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2>
418 +<h2 class="itemTitle"><?php esc_html_e( 'Cache Info', 'autoptimize' ); ?></h2>
362 419 <table class="form-table" >
363 420 <tr valign="top" >
364 -<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th>
421 +<th scope="row"><?php esc_html_e( 'Cache folder', 'autoptimize' ); ?></th>
365 422 <td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td>
366 423 </tr>
367 424 <tr valign="top" >
368 -<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th>
369 -<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td>
425 +<th scope="row"><?php esc_html_e( 'Can we write?', 'autoptimize' ); ?></th>
426 +<td><?php echo ( autoptimizeCache::cacheavail() ? esc_html__( 'Yes', 'autoptimize' ) : esc_html__( 'No', 'autoptimize' ) ); ?></td>
370 427 </tr>
371 428 <tr valign="top" >
372 -<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th>
429 +<th scope="row"><?php esc_html_e( 'Cached styles and scripts', 'autoptimize' ); ?></th>
373 430 <td>
374 431 <?php
375 432 $ao_stat_arr = autoptimizeCache::stats();
376 433 if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) {
@@ -379,9 +436,9 @@
379 436 if ( $ao_cache_size > 0 ) {
380 437 $details = ', ~' . $ao_cache_size . ' total';
381 438 }
382 439 // 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] ) );
440 + printf( esc_html__( '%1$s files, totaling %2$s (calculated at %3$s)', 'autoptimize' ), $ao_stat_arr[0], $ao_cache_size, wp_date( 'H:i', $ao_stat_arr[2] ) ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date
384 441 }
385 442 ?>
386 443 </td>
387 444 </tr>
@@ -388,14 +445,14 @@
388 445 </table>
389 446 </li>
390 447
391 448 <li class="itemDetail">
392 -<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2>
449 +<h2 class="itemTitle"><?php esc_html_e( 'Misc Options', 'autoptimize' ); ?></h2>
393 450 <table class="form-table">
394 - <tr valign="top" >
395 - <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" ' : ''; ?>/>
397 - <?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>
451 + <tr valign="top">
452 + <th scope="row"><?php esc_html_e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th>
453 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo $conf->get( 'autoptimize_cache_nogzip' ) ? 'checked="checked" ' : ''; ?>/>
454 + <?php esc_html_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 455 </tr>
399 456 <?php
400 457 $_min_excl_class = '';
401 458 if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) {
@@ -402,27 +459,50 @@
402 459 $_min_excl_class = 'hidden';
403 460 }
404 461 ?>
405 462 <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>">
406 - <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" ' : ''; ?>/>
408 - <?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>
463 + <th scope="row"><?php esc_html_e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th>
464 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo $conf->get( 'autoptimize_minify_excluded' ) ? 'checked="checked" ' : ''; ?>/>
465 + <?php esc_html_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 466 </tr>
410 467 <tr valign="top">
411 - <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" ' : ''; ?>/>
413 - <?php _e( 'By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize' ); ?></label></td>
468 + <th scope="row"><?php esc_html_e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th>
469 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo $conf->get( 'autoptimize_cache_fallback' ) ? 'checked="checked" ' : ''; ?>/>
470 + <?php
471 + // translators; just 2 opening and closing <code> tags.
472 + printf( esc_html__( '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 %1$swp-content/autoptimize_404_handler.php%2$s is set to handle 404\'s in %1$swp-content/cache/autoptimize%2$s.', 'autoptimize' ), '<code>', '</code>' );
473 + ?>
474 + </label></td>
414 475 </tr>
476 + <tr valign="top">
477 + <th scope="row"><?php esc_html_e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th>
478 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo $conf->get( 'autoptimize_optimize_logged' ) ? 'checked="checked" ' : ''; ?>/>
479 + <?php esc_html_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 page builder.', 'autoptimize' ); ?></label></td>
480 + </tr>
415 481 <?php
416 482 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 483 ?>
418 484 <tr valign="top" >
419 - <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" ' : ''; ?>/>
421 - <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
485 + <th scope="row"><?php esc_html_e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th>
486 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo $conf->get( 'autoptimize_optimize_checkout' ) ? 'checked="checked" ' : ''; ?>/>
487 + <?php esc_html_e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
422 488 </td>
423 489 </tr>
424 490 <?php } ?>
491 + <?php
492 + if ( true === apply_filters( 'autoptimize_filter_enable_meta_ao_settings', true ) ) {
493 + ?>
494 + <tr valign="top">
495 + <th scope="row"><?php esc_html_e( 'Enable configuration per post/ page?', 'autoptimize' ); ?></th>
496 + <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" ' : ''; ?>/>
497 + <?php esc_html_e( 'Add a "meta box" to the post/ page edit screen allowing different optimizations to be turned off on a per post/ page level?', 'autoptimize' ); ?></label></td>
498 + </tr>
499 + <?php } ?>
500 + <tr valign="top">
501 + <th scope="row"><?php esc_html_e( 'Disable extra compatibility logic?', 'autoptimize' ); ?></th>
502 + <td><label class="cb_label"><input type="checkbox" name="autoptimize_installed_before_compatibility" <?php echo $conf->get( 'autoptimize_installed_before_compatibility' ) ? 'checked="checked" ' : ''; ?>/>
503 + <?php esc_html_e( 'Autoptimize applies extra "compatibility logic" to prevent issues with JS optimization (for e.g. Gutenberg blocks, Revolution Slider, jQuery-heavy plugins, ...) but may sometimes be a bit too careful. If you have render-blocking JS issues, you can try disabling this logic here. Make sure to test your site thoroughly though!', 'autoptimize' ); ?></label></td>
504 + </tr>
425 505 </table>
426 506 </li>
427 507
428 508 </ul>
@@ -427,15 +507,16 @@
427 507
428 508 </ul>
429 509
430 510 <p class="submit">
431 -<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
432 -<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" />
511 +<input type="submit" class="button-secondary" value="<?php esc_html_e( 'Save Changes', 'autoptimize' ); ?>" />
512 +<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php esc_html_e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" />
433 513 </p>
434 514
435 515 </form>
436 516 </div>
437 -<div id="autoptimize_admin_feed" class="hidden">
517 +<div id="autoptimize_admin_feed">
518 + <?php if ( apply_filters( 'autoptimize_filter_show_partner_tabs', true ) ) { ?>
438 519 <div class="autoptimize_banner hidden">
439 520 <ul>
440 521 <?php
441 522 if ( $this->settings_screen_do_remote_http ) {
@@ -451,54 +532,38 @@
451 532 }
452 533 echo $ao_banner;
453 534 }
454 535 ?>
455 - <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li>
456 - <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>
536 + <li>
537 + <?php
538 + // translators: link to the AO FAQ.
539 + printf( esc_html__( 'Need help? %1$sCheck out the FAQ here%2$s.', 'autoptimize' ), '<a href=\'https://wordpress.org/plugins/autoptimize/faq/\'>', '</a>' );
540 + ?>
541 + </li>
542 + <li><?php esc_html_e( 'Happy with Autoptimize?', 'autoptimize' ); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php esc_html_e( 'Try my other plugins!', 'autoptimize' ); ?></a></li>
457 543 </ul>
458 544 </div>
545 + <?php } ?>
459 546 <div style="margin-left:10px;margin-top:-5px;">
460 547 <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>
548 + <?php esc_html_e( 'Autoptimize news', 'autoptimize' ); ?>
467 549 </h2>
468 550 <div id="futtta_feed">
469 551 <div id="autoptimizefeed">
470 552 <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
471 553 </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 554 </div>
479 555 </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>
556 + <?php if ( apply_filters( 'autoptimize_filter_show_partner_tabs', true ) ) { ?>
557 + <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 esc_html_e( 'Do not donate for this plugin!', 'autoptimize' ); ?>"></a></div>
558 + <?php } ?>
481 559 </div>
482 -
483 560 <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 561 jQuery(document).ready(function() {
491 562 check_ini_state();
492 563
493 - jQuery('#autoptimize_admin_feed').fadeTo("slow",1).show();
494 564 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 565
496 - jQuery( "#feed_dropdown" ).change(function() {
497 - jQuery("#futtta_feed").fadeTo(0,0);
498 - jQuery("#futtta_feed").fadeTo("slow",1);
499 - });
500 -
501 566 jQuery( "#autoptimize_html" ).change(function() {
502 567 if (this.checked) {
503 568 jQuery(".html_sub:visible").fadeTo("fast",1);
504 569 } else {
@@ -514,19 +579,40 @@
514 579 }
515 580 });
516 581
517 582 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();
583 + if (this.checked && jQuery("#autoptimize_js").prop('checked')) {
584 + jQuery( "#autoptimize_js_defer_not_aggregate" ).prop( 'checked', false ); // uncheck "defer not aggregate"
585 + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // ungrey self
586 + jQuery( ".js_aggregate" ).show( 'slow' ); // show sub-items
587 + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'slow', .33 ); // grey out "not aggregate"
588 + jQuery( ".js_not_aggregate" ).hide( 'slow' ); // hide not aggregate sub-items
589 + jQuery( "#min_excl_row" ).show(); // make sure "minify excluded" is visible
590 + check_exclusions( "js", "on" );
521 591 } else {
522 - jQuery(".js_aggregate:visible").fadeTo("fast",.33);
523 - if ( jQuery( "#autoptimize_css_aggregate" ).prop('checked') == false ) {
592 + jQuery( ".js_aggregate" ).hide( 'slow' ); // hide sub-itmes
593 + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // un-grey-out "not aggregate"
594 + if ( jQuery( "#autoptimize_css_aggregate" ).prop( 'checked' ) == false ) { // hide "minify excluded"
524 595 jQuery( "#min_excl_row" ).hide();
525 596 }
597 + check_exclusions( "js", "off" );
526 598 }
527 599 });
528 600
601 + jQuery( "#autoptimize_js_defer_not_aggregate" ).change(function() {
602 + if (this.checked && jQuery("#autoptimize_js").prop('checked')) {
603 + jQuery( "#autoptimize_js_aggregate" ).prop( 'checked', false ); // uncheck "aggregate JS"
604 + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // ungrey self
605 + jQuery( ".js_not_aggregate" ).show( 'slow'); // show sub-items
606 + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'slow', .33 ); // grey out "aggregate"
607 + jQuery( ".js_aggregate" ).hide( 'slow' ); // hide aggregate sub-items
608 + check_exclusions( "js", "off" );
609 + } else {
610 + jQuery( ".js_not_aggregate" ).hide( 'slow' ); // hide sub-items
611 + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // un-grey-out "aggregate"
612 + }
613 + });
614 +
529 615 jQuery( "#autoptimize_css" ).change(function() {
530 616 if (this.checked) {
531 617 jQuery(".css_sub:visible").fadeTo("fast",1);
532 618 } else {
@@ -534,16 +620,18 @@
534 620 }
535 621 });
536 622
537 623 jQuery( "#autoptimize_css_aggregate" ).change(function() {
538 - if (this.checked && jQuery("#autoptimize_css").attr('checked')) {
624 + if (this.checked && jQuery("#autoptimize_css").prop('checked')) {
539 625 jQuery(".css_aggregate:visible").fadeTo("fast",1);
540 626 jQuery( "#min_excl_row" ).show();
627 + check_exclusions( "css", "on" );
541 628 } else {
542 629 jQuery(".css_aggregate:visible").fadeTo("fast",.33);
543 630 if ( jQuery( "#autoptimize_js_aggregate" ).prop('checked') == false ) {
544 631 jQuery( "#min_excl_row" ).hide();
545 632 }
633 + check_exclusions( "css", "off" );
546 634 }
547 635 });
548 636
549 637 jQuery( "#autoptimize_css_inline" ).change(function() {
@@ -568,13 +656,8 @@
568 656 } else {
569 657 jQuery("li.itemDetail:not(.multiSite)").fadeTo("fast",1);
570 658 }
571 659 });
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 660 })
578 661
579 662 // validate cdn_url.
580 663 var cdn_url=document.getElementById("cdn_url");
@@ -588,36 +671,56 @@
588 671 }});
589 672 }
590 673
591 674 function check_ini_state() {
592 - if (!jQuery("#autoptimize_css_defer").attr('checked')) {
675 + if (!jQuery("#autoptimize_css_defer").prop('checked')) {
593 676 jQuery("#autoptimize_css_defer_inline").hide();
594 677 }
595 - if (!jQuery("#autoptimize_html").attr('checked')) {
678 + if (!jQuery("#autoptimize_html").prop('checked')) {
596 679 jQuery(".html_sub:visible").fadeTo('fast',.33);
597 680 }
598 - if (!jQuery("#autoptimize_css").attr('checked')) {
681 + if (!jQuery("#autoptimize_css").prop('checked')) {
599 682 jQuery(".css_sub:visible").fadeTo('fast',.33);
600 683 }
601 - if (!jQuery("#autoptimize_css_aggregate").attr('checked')) {
684 + if (!jQuery("#autoptimize_css_aggregate").prop('checked')) {
602 685 jQuery(".css_aggregate:visible").fadeTo('fast',.33);
603 686 }
604 - if (!jQuery("#autoptimize_js").attr('checked')) {
605 - jQuery(".js_sub:visible").fadeTo('fast',.33);
687 + if (jQuery("#autoptimize_js_aggregate").prop('checked')) {
688 + jQuery( ".js_aggregate" ).show( 'fast' );
689 + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'fast', .33 );
606 690 }
607 - if (!jQuery("#autoptimize_js_aggregate").attr('checked')) {
608 - jQuery(".js_aggregate:visible").fadeTo('fast',.33);
691 + if (jQuery("#autoptimize_js_defer_not_aggregate").prop('checked')) {
692 + jQuery( ".js_not_aggregate" ).show( 'fast' );
693 + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'fast', .33 );
609 694 }
610 - if (jQuery("#autoptimize_enable_site_config").attr('checked')) {
695 + if (jQuery("#autoptimize_enable_site_config").prop('checked')) {
611 696 jQuery("li.itemDetail:not(.multiSite)").fadeTo('fast',.33);
612 697 }
698 + if (!jQuery("#autoptimize_js").prop('checked')) {
699 + jQuery(".js_sub:visible").fadeTo('fast',.33);
700 + }
613 701 }
614 702
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 });
703 + function check_exclusions( what, state ) {
704 + exclusion_node = 'input[name="autoptimize_' + what + '_exclude"]';
705 + current_exclusion = jQuery( exclusion_node ).val();
706 +
707 + if ( what == "js" ) {
708 + default_exclusion = ", wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.min.js";
709 + } else if ( what == "css") {
710 + default_exclusion = ", admin-bar.min.css, dashicons.min.css, wp-content/cache/, wp-content/uploads/";
711 + }
712 +
713 + default_in_current = current_exclusion.indexOf(default_exclusion);
714 +
715 + if ( state == "on" && default_in_current == -1 ) {
716 + jQuery( exclusion_node ).val( current_exclusion + default_exclusion );
717 + } else if ( state = "off" && current_exclusion == default_exclusion ) {
718 + jQuery( exclusion_node ).val( "" );
719 + } else if ( state = "off" && default_in_current != -1 ) {
720 + new_exclusion = current_exclusion.substring( 0, default_in_current) + current_exclusion.substring( default_in_current + default_exclusion.length, current_exclusion.length );
721 + jQuery( exclusion_node ).val( new_exclusion );
722 + }
620 723 }
621 724 </script>
622 725 </div>
623 726
@@ -625,14 +728,24 @@
625 728 }
626 729
627 730 public function addmenu()
628 731 {
629 - if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
630 - $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
631 - } elseif ( ! is_multisite() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
632 - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
732 + $_my_name = apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? esc_html__( 'Autoptimize Pro', 'autoptimize' ) : esc_html__( 'Autoptimize', 'autoptimize' );
733 +
734 + global $title;
735 + if ( empty( $title ) && true === autoptimizeUtils::is_ao_settings() ) {
736 + $title = $_my_name;
737 + }
738 +
739 + if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
740 + // multisite, network admin, ao network activated: add normal settings page at network level.
741 + $hook = add_submenu_page( 'settings.php', esc_html__( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
742 + } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
743 + // 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.
744 + $hook = add_options_page( esc_html__( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
633 745 } else {
634 - $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
746 + // 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.
747 + $hook = add_options_page( esc_html__( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
635 748 }
636 749
637 750 add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
638 751 add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
@@ -639,24 +752,26 @@
639 752 }
640 753
641 754 public function autoptimize_admin_scripts()
642 755 {
643 - wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true );
644 - wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
756 + wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider.min.js', __FILE__ ), array( 'jquery' ), AUTOPTIMIZE_PLUGIN_VERSION, true );
645 757 }
646 758
647 759 public function autoptimize_admin_styles()
648 760 {
649 - wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) );
650 - wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) );
761 + wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ), null, AUTOPTIMIZE_PLUGIN_VERSION );
762 + wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ), null, AUTOPTIMIZE_PLUGIN_VERSION );
651 763 }
652 764
653 765 public function registersettings() {
654 766 register_setting( 'autoptimize', 'autoptimize_html' );
655 767 register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
768 + register_setting( 'autoptimize', 'autoptimize_html_minify_inline' );
656 769 register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
657 770 register_setting( 'autoptimize', 'autoptimize_js' );
658 771 register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
772 + register_setting( 'autoptimize', 'autoptimize_js_defer_not_aggregate' );
773 + register_setting( 'autoptimize', 'autoptimize_js_defer_inline' );
659 774 register_setting( 'autoptimize', 'autoptimize_js_exclude' );
660 775 register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
661 776 register_setting( 'autoptimize', 'autoptimize_js_justhead' );
662 777 register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
@@ -675,8 +790,11 @@
675 790 register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
676 791 register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
677 792 register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
678 793 register_setting( 'autoptimize', 'autoptimize_minify_excluded' );
794 + register_setting( 'autoptimize', 'autoptimize_cache_fallback' );
795 + register_setting( 'autoptimize', 'autoptimize_enable_meta_ao_settings' );
796 + register_setting( 'autoptimize', 'autoptimize_installed_before_compatibility' );
679 797 }
680 798
681 799 public function setmeta( $links, $file = null )
682 800 {
@@ -688,15 +806,15 @@
688 806 }
689 807
690 808 if ( null === $file ) {
691 809 // 2.7 and lower.
692 - $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) );
810 + $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', esc_html__( 'Settings' ) );
693 811 array_unshift( $links, $settings_link );
694 812 } else {
695 813 // 2.8 and higher.
696 814 // If it's us, add the link.
697 815 if ( $file === $plugin ) {
698 - $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) );
816 + $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', esc_html__( 'Settings' ) ) );
699 817 $links = array_merge( $links, $newlink );
700 818 }
701 819 }
702 820
@@ -710,32 +828,38 @@
710 828 */
711 829 public static function get_defaults()
712 830 {
713 831 static $config = array(
714 - 'autoptimize_html' => 0,
715 - 'autoptimize_html_keepcomments' => 0,
716 - 'autoptimize_enable_site_config' => 1,
717 - 'autoptimize_js' => 0,
718 - 'autoptimize_js_aggregate' => 1,
719 - 'autoptimize_js_exclude' => 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js',
720 - 'autoptimize_js_trycatch' => 0,
721 - 'autoptimize_js_justhead' => 0,
722 - 'autoptimize_js_include_inline' => 0,
723 - 'autoptimize_js_forcehead' => 0,
724 - 'autoptimize_css' => 0,
725 - 'autoptimize_css_aggregate' => 1,
726 - 'autoptimize_css_exclude' => 'admin-bar.min.css, dashicons.min.css, wp-content/cache/, wp-content/uploads/',
727 - 'autoptimize_css_justhead' => 0,
728 - 'autoptimize_css_include_inline' => 1,
729 - 'autoptimize_css_defer' => 0,
730 - 'autoptimize_css_defer_inline' => '',
731 - 'autoptimize_css_inline' => 0,
732 - 'autoptimize_css_datauris' => 0,
733 - 'autoptimize_cdn_url' => '',
734 - 'autoptimize_cache_nogzip' => 1,
735 - 'autoptimize_optimize_logged' => 1,
736 - 'autoptimize_optimize_checkout' => 0,
737 - 'autoptimize_minify_excluded' => 1,
832 + 'autoptimize_html' => 1,
833 + 'autoptimize_html_keepcomments' => 0,
834 + 'autoptimize_html_minify_inline' => 0,
835 + 'autoptimize_enable_site_config' => 1,
836 + 'autoptimize_js' => 1,
837 + 'autoptimize_js_aggregate' => 0,
838 + 'autoptimize_js_defer_not_aggregate' => 1,
839 + 'autoptimize_js_defer_inline' => 1,
840 + 'autoptimize_js_exclude' => '',
841 + 'autoptimize_js_trycatch' => 0,
842 + 'autoptimize_js_justhead' => 0,
843 + 'autoptimize_js_include_inline' => 0,
844 + 'autoptimize_js_forcehead' => 0,
845 + 'autoptimize_css' => 1,
846 + 'autoptimize_css_aggregate' => 0,
847 + 'autoptimize_css_exclude' => '',
848 + 'autoptimize_css_justhead' => 0,
849 + 'autoptimize_css_include_inline' => 0,
850 + 'autoptimize_css_defer' => 0,
851 + 'autoptimize_css_defer_inline' => '',
852 + 'autoptimize_css_inline' => 0,
853 + 'autoptimize_css_datauris' => 0,
854 + 'autoptimize_cdn_url' => '',
855 + 'autoptimize_cache_nogzip' => 1,
856 + 'autoptimize_optimize_logged' => 1,
857 + 'autoptimize_optimize_checkout' => 0,
858 + 'autoptimize_minify_excluded' => 1,
859 + 'autoptimize_cache_fallback' => 1,
860 + 'autoptimize_enable_meta_ao_settings' => 1,
861 + 'autoptimize_installed_before_compatibility' => 0,
738 862 );
739 863
740 864 return $config;
741 865 }
@@ -753,8 +877,9 @@
753 877 'autoptimize_extra_radio_field_4' => '1',
754 878 'autoptimize_extra_text_field_2' => '',
755 879 'autoptimize_extra_text_field_3' => '',
756 880 'autoptimize_extra_text_field_7' => '',
881 + 'autoptimize_extra_checkbox_field_8' => '0',
757 882 );
758 883
759 884 return $defaults;
760 885 }
@@ -769,33 +894,26 @@
769 894 $defaults = array(
770 895 'autoptimize_imgopt_checkbox_field_1' => '0', // imgopt off.
771 896 'autoptimize_imgopt_select_field_2' => '2', // quality glossy.
772 897 'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
773 - 'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
898 + 'autoptimize_imgopt_checkbox_field_4' => '0', // avif off (might be removed).
774 899 'autoptimize_imgopt_text_field_5' => '', // lazy load exclusions empty.
900 + 'autoptimize_imgopt_text_field_6' => '', // optimization exclusions empty.
901 + 'autoptimize_imgopt_number_field_7' => '2', // lazy load from nth image (0 = lazyload all).
775 902 );
776 903 return $defaults;
777 904 }
778 905
779 906 /**
780 - * Returns preload polyfill JS.
907 + * Returns preload JS onload handler.
781 908 *
782 - * @return string
783 - */
784 - public static function get_ao_css_preload_polyfill()
785 - {
786 - $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>' );
787 - return $preload_poly;
788 - }
789 -
790 - /**
791 - * Returns preload JS onload handler.
909 + * @param string $media media attribute value the JS to use.
792 910 *
793 911 * @return string
794 912 */
795 - public static function get_ao_css_preload_onload()
913 + public static function get_ao_css_preload_onload( $media = 'all' )
796 914 {
797 - $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.rel='stylesheet'" );
915 + $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" );
798 916 return $preload_onload;
799 917 }
800 918
801 919 public function get( $key )
@@ -835,15 +953,15 @@
835 953 }
836 954 ?>
837 955 <ul>
838 956 <?php if ( 0 == $maxitems ) : ?>
839 - <li><?php _e( 'No items', 'autoptimize' ); ?></li>
957 + <li><?php esc_html_e( 'No items', 'autoptimize' ); ?></li>
840 958 <?php else : ?>
841 959 <?php foreach ( $rss_items as $item ) : ?>
842 960 <li>
843 961 <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
844 962 <?php // translators: the variable contains a date. ?>
845 - title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>">
963 + title="<?php printf( esc_html__( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>">
846 964 <?php echo esc_html( $item->get_title() ); ?>
847 965 </a>
848 966 </li>
849 967 <?php endforeach; ?>
@@ -855,9 +973,9 @@
855 973
856 974 static function ao_admin_tabs()
857 975 {
858 976 // based on http://wordpress.stackexchange.com/a/58826 .
859 - $tabs = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS &amp; HTML', 'autoptimize' ) ) );
977 + $tabs = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => esc_html__( 'JS, CSS &amp; HTML', 'autoptimize' ) ) );
860 978 $tab_content = '';
861 979 $tabs_count = count( $tabs );
862 980 if ( $tabs_count > 1 ) {
863 981 if ( isset( $_GET['page'] ) ) {
@@ -910,11 +1028,89 @@
910 1028 *
911 1029 * @return bool
912 1030 */
913 1031 public static function should_show_menu_tabs() {
914 - if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
1032 + if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) || false === autoptimizeOptionWrapper::is_ao_active_for_network() ) {
915 1033 return true;
916 1034 } else {
917 1035 return false;
918 1036 }
1037 + }
1038 +
1039 + /**
1040 + * Returns the post meta AO settings for reuse in different optimizers.
1041 + *
1042 + * @param string $optim What optimization we need meta setting for.
1043 + *
1044 + * @return bool
1045 + */
1046 + public static function get_post_meta_ao_settings( $optim ) {
1047 + if ( ! autoptimizeConfig::is_ao_meta_settings_active() ) {
1048 + // Per page/post settings not active, so always return true (as in; can be optimized).
1049 + if ( in_array( $optim, apply_filters( 'autoptimize_filter_meta_inactive_return_false_for', array( 'ao_post_preload' ) ) ) ) {
1050 + // but make sure to return false for text input.
1051 + return false;
1052 + }
1053 + return true;
1054 + }
1055 +
1056 + static $_meta_value = null;
1057 + if ( null === $_meta_value ) {
1058 + global $wp_query;
1059 + if ( isset( $wp_query ) ) {
1060 + $_meta_value = get_post_meta( get_the_ID(), 'ao_post_optimize', true );
1061 + } else {
1062 + $_meta_value = false;
1063 + }
1064 + }
1065 +
1066 + // If autoptimize_post_optimize !== 'on' (except for ao_post_preload, which can have other values) then always return false as all is off.
1067 + // fixme: need unit tests to ensure below logic is sane!
1068 + if ( empty( $_meta_value ) || ! is_array( $_meta_value ) ) {
1069 + // no metabox values so all optimizations are a go.
1070 + if ( in_array( $optim, apply_filters( 'autoptimize_filter_meta_optim_nonbool', array( 'ao_post_preload' ) ) ) ) {
1071 + // but make sure to return false for text input.
1072 + return false;
1073 + }
1074 + return true;
1075 + } else if ( array_key_exists( 'ao_post_optimize', $_meta_value ) && 'on' !== $_meta_value['ao_post_optimize'] ) {
1076 + // ao entirely off for this page.
1077 + return false;
1078 + } else if ( in_array( $optim, apply_filters( 'autoptimize_filter_meta_optim_with_filters', array() ) ) ) {
1079 + // if an $optim is registered as having a filter, apply filter and return that (default false).
1080 + return apply_filters( 'autoptimize_filter_meta_filtered_optim', false, $optim, $_meta_value );
1081 + } else if ( array_key_exists( $optim, $_meta_value ) && empty( $_meta_value[ $optim ] ) ) {
1082 + // sub-optimization off for this page.
1083 + return false;
1084 + } else if ( array_key_exists( $optim, $_meta_value ) && 'on' === $_meta_value[ $optim ] ) {
1085 + // sub-optimization is explictly on.
1086 + return true;
1087 + } else if ( array_key_exists( $optim, $_meta_value ) && in_array( $optim, array( 'ao_post_preload' ) ) && ! empty( $_meta_value[ $optim ] ) ) {
1088 + // a non-bool metabox optimization (currently only preload field), return value instead of bool.
1089 + return $_meta_value[ $optim ];
1090 + } else if ( in_array( $optim, array( 'ao_post_preload' ) ) && ( ! array_key_exists( $optim, $_meta_value ) || empty( $_meta_value[ $optim ] ) ) ) {
1091 + // a non-bool metabox optimization not found or empty, so returning false.
1092 + return false;
1093 + } else {
1094 + // when in doubt "go" for optimization, but this should never happen?
1095 + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
1096 + error_log( 'AO meta box logic fallback; well, how did I get here? Maybe this helps: looking for ' . $optim . ' in ' . json_encode( $_meta_value ) );
1097 + }
1098 + return true;
1099 + }
1100 + }
1101 +
1102 + /**
1103 + * Are the post meta AO settings active (default: no)?
1104 + *
1105 + * @return bool
1106 + */
1107 + public static function is_ao_meta_settings_active() {
1108 + static $_meta_settings_active = null;
1109 +
1110 + if ( null === $_meta_settings_active ) {
1111 + $_meta_settings_active = apply_filters( 'autoptimize_filter_enable_meta_ao_settings', autoptimizeOptionWrapper::get_option( 'autoptimize_enable_meta_ao_settings', '1' ) );
1112 + }
1113 +
1114 + return $_meta_settings_active;
919 1115 }
920 1116 }