PluginProbe
Autoptimize / 3.1.16
Autoptimize v3.1.16
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 +817 -417 2.3.4 → 3.1.16 View file →
@@ -1,84 +1,114 @@
1 1 <?php
2 -if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
2 +/**
3 + * Main configuration logic.
4 + */
3 5
4 -class autoptimizeConfig {
6 +if ( ! defined( 'ABSPATH' ) ) {
7 + exit;
8 +}
9 +
10 +class autoptimizeConfig
11 +{
12 + /**
13 + * Options.
14 + *
15 + * @var array
16 + */
5 17 private $config = null;
18 +
19 + /**
20 + * Singleton instance.
21 + *
22 + * @var self|null
23 + */
6 24 static private $instance = null;
7 25
8 - //Singleton: private construct
9 - private function __construct() {
10 - if( is_admin() ) {
11 - //Add the admin page and settings
12 - add_action('admin_menu',array($this,'addmenu'));
13 - add_action('admin_init',array($this,'registersettings'));
26 + /**
27 + * Options.
28 + *
29 + * @var bool
30 + */
31 + private $settings_screen_do_remote_http = true;
14 32
15 - //Set meta info
16 - if(function_exists('plugin_row_meta')) {
17 - //2.8+
18 - add_filter('plugin_row_meta',array($this,'setmeta'),10,2);
19 - } elseif(function_exists('post_class')) {
20 - //2.7
21 - $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
22 - add_filter('plugin_action_links_'.$plugin,array($this,'setmeta'));
33 + /**
34 + * Singleton.
35 + */
36 + private function __construct()
37 + {
38 + if ( is_admin() ) {
39 + // Add the admin page and settings.
40 + if ( autoptimizeOptionWrapper::is_ao_active_for_network() ) {
41 + add_action( 'network_admin_menu', array( $this, 'addmenu' ) );
23 42 }
24 43
25 - //Clean cache?
26 - if(get_option('autoptimize_cache_clean')) {
44 + add_action( 'admin_menu', array( $this, 'addmenu' ) );
45 + add_action( 'admin_init', array( $this, 'registersettings' ) );
46 + add_action( 'admin_init', array( 'PAnD', 'init' ) );
47 +
48 + // Set meta info.
49 + if ( function_exists( 'plugin_row_meta' ) ) {
50 + // 2.8 and higher.
51 + add_filter( 'plugin_row_meta', array( $this, 'setmeta' ), 10, 2 );
52 + } elseif ( function_exists( 'post_class' ) ) {
53 + // 2.7 and lower.
54 + $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
55 + add_filter( 'plugin_action_links_' . $plugin, array( $this, 'setmeta' ) );
56 + }
57 +
58 + // Clean cache?
59 + if ( autoptimizeOptionWrapper::get_option( 'autoptimize_cache_clean' ) ) {
27 60 autoptimizeCache::clearall();
28 - update_option('autoptimize_cache_clean',0);
61 + autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 );
29 62 }
63 +
64 + $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
65 +
66 + if ( $this->is_ao_meta_settings_active() ) {
67 + $meta_box = new autoptimizeMetabox();
68 + }
30 69 }
31 70
32 - //Add the Autoptimize Toolbar to the Admin bar
33 - //(we loaded outside the verification of is_admin to also be displayed on the frontend toolbar)
71 + // Adds the Autoptimize Toolbar to the Admin bar.
72 + // (we load outside the is_admin check so it's also displayed on the frontend toolbar).
34 73 $toolbar = new autoptimizeToolbar();
35 74 }
36 -
37 - static public function instance() {
38 - //Only one instance
39 - if (self::$instance == null) {
75 +
76 + /**
77 + * Instantiates aoconfig.
78 + *
79 + * @return autoptimizeConfig
80 + */
81 + static public function instance()
82 + {
83 + // Only one instance.
84 + if ( null === self::$instance ) {
40 85 self::$instance = new autoptimizeConfig();
41 86 }
42 -
87 +
43 88 return self::$instance;
44 - }
45 -
46 - public function show() {
47 -?>
89 + }
90 +
91 + public function show_network_message() {
92 + ?>
93 + <div class="wrap">
94 + <h1><?php esc_html_e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
95 + <?php echo $this->ao_admin_tabs(); ?>
96 + <p style="font-size:120%;"><?php echo apply_filters( 'autoptimize_filter_settingsscreen_multisite_network_message', 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>
97 + </div>
98 + <?php
99 + }
100 +
101 + public function show_config()
102 + {
103 + // phpcs:disable Generic.WhiteSpace.ScopeIndent.IncorrectExact
104 + // phpcs:disable Generic.WhiteSpace.ScopeIndent.Incorrect
105 + $conf = self::instance();
106 + ?>
48 107 <style>
49 108 /* title and button */
50 109 #ao_title_and_button:after {content:''; display:block; clear:both;}
51 -#ao_adv_button{float:right;}
52 -#ao_hide_adv:before, #ao_show_adv:before {
53 - display: inline-block;
54 - float: left;
55 - height: 20px;
56 - width: 35px;
57 - background: none;
58 - color: #b4b9be;
59 - font: normal 20px/26px dashicons;
60 - letter-spacing: -4px;
61 - text-align: left;
62 - speak: none;
63 - -webkit-font-smoothing: antialiased;
64 - -moz-osx-font-smoothing: grayscale;
65 -}
66 -#ao_hide_adv:before {
67 - content: "\f108 \f142";
68 -}
69 -#ao_show_adv:before {
70 - content: "\f108 \f140";
71 -}
72 110
73 -/* animate "show adv" button */
74 -#ao_show_adv { animation: watchmenow 3s linear 5s 10; }
75 -#ao_show_adv:hover { animation: none; }
76 -@keyframes watchmenow {
77 - 0% { box-shadow: unset; }
78 - 100% { box-shadow: 0px 0px 20px yellow; }
79 -}
80 -
81 111 /* form */
82 112 .itemDetail {
83 113 background: #fff;
84 114 border: 1px solid #ccc;
@@ -87,14 +117,18 @@
87 117 }
88 118 .itemTitle {
89 119 margin-top: 0;
90 120 }
91 -input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:100;}
121 +
122 +.form-table th{font-weight:normal;}
123 +#autoptimize_main form input:invalid {box-shadow: 0 0 1px 1px red;}
92 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;}
93 127
94 128 /* rss block */
95 129 #futtta_feed ul{list-style:outside;}
96 -#futtta_feed {font-size:medium; margin:0px 20px;}
130 +#futtta_feed {font-size:medium; margin:0px 20px;}
97 131
98 132 /* banner + unslider */
99 133 .autoptimize_banner {
100 134 margin: 0 38px;
@@ -137,8 +171,9 @@
137 171 }
138 172 .unslider-arrow.next::before {
139 173 content: "\f345";
140 174 }
175 +
141 176 /* responsive stuff: hide admin-feed on smaller screens */
142 177 @media (min-width: 961px) {
143 178 #autoptimize_main {float:left;width:69%;}
144 179 #autoptimize_admin_feed{float:right;width:30%;display:block !important;}
@@ -147,11 +182,8 @@
147 182 #autoptimize_main {width:100%;}
148 183 #autoptimize_admin_feed {width:0%;display:none !important;}
149 184 }
150 185 @media (max-width: 782px) {
151 - #ao_hide_adv span, #ao_show_adv span {display: none;}
152 - #ao_hide_adv,#ao_show_adv {height: 34px;padding: 4px 12px 8px 8px;}
153 - #ao_hide_adv:before,#ao_show_adv:before {font-size: 25px;}
154 186 #autoptimize_main input[type="checkbox"] {margin-left: 10px;}
155 187 #autoptimize_main .cb_label {display: block; padding-left: 45px; text-indent: -45px;}
156 188 }
157 189 </style>
@@ -157,315 +189,381 @@
157 189 </style>
158 190
159 191 <div class="wrap">
160 192
161 -<?php if (version_compare(PHP_VERSION, '5.3.0') < 0) { ?>
162 -<div class="notice-error notice"><?php echo '<p>' . sprintf( __('<strong>You are using a very old version of PHP</strong> which will not be supported as from the upcoming Autoptimize 2.4 any more, cfr. <a href=%s>this blogpost for more info</a>. please ask your hoster to provide you with an upgrade path to 7.x.','autoptimize'), '"https://blog.futtta.be/2018/02/13/introducing-zytzagoos-major-changes-for-autoptimize-2-4/" target="_blank"' ) . '</p>'; ?></div>
163 -<?php } ?>
164 -
165 -<?php if (defined('AUTOPTIMIZE_LEGACY_MINIFIERS')) { ?>
166 -<div class="notice-error notice"><?php echo '<p>' . sprintf( __('You are forcing Autoptimize to use the "legacy minifiers" by setting the AUTOPTIMIZE_LEGACY_MINIFIERS constant in /wp-config.php. The "legacy minifiers" will not be supported as from the upcoming Autoptimize 2.4 any more, cfr. <a href=%s>this blogpost for more info</a>.','autoptimize'), '"https://blog.futtta.be/2018/02/13/introducing-zytzagoos-major-changes-for-autoptimize-2-4/" target="_blank"') . '</p>'; ?></div>
167 -<?php } ?>
168 -
169 193 <div id="autoptimize_main">
170 -<div id="ao_title_and_button">
171 - <h1 id="ao_title"><?php _e('Autoptimize Settings','autoptimize'); ?>
172 - <span id="ao_adv_button">
173 - <?php
174 - if (get_option('autoptimize_show_adv','0')=='1') {
175 - ?>
176 - <a href="javascript:void(0);" id="ao_show_adv" class="button" style="display:none;"><span><?php _e("Show advanced settings","autoptimize") ?></span></a>
177 - <a href="javascript:void(0);" id="ao_hide_adv" class="button"><span><?php _e("Hide advanced settings","autoptimize") ?></span></a>
178 - <style>tr.ao_adv{display:table-row;} li.ao_adv{display:list-item;}</style>
179 - <?php
180 - $hiddenClass="";
181 - } else {
182 - ?>
183 - <a href="javascript:void(0);" id="ao_show_adv" class="button"><span><?php _e("Show advanced settings","autoptimize") ?></span></a>
184 - <a href="javascript:void(0);" id="ao_hide_adv" class="button" style="display:none;"><span><?php _e("Hide advanced settings","autoptimize") ?></span></a>
185 - <?php
186 - $hiddenClass="hidden ";
187 - }
188 - ?>
189 - </span>
190 - </h1>
191 -</div>
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>
195 + <?php echo $this->ao_admin_tabs(); ?>
192 196
193 -<?php echo $this->ao_admin_tabs(); ?>
197 +<form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
198 +<?php settings_fields( 'autoptimize' ); ?>
194 199
195 -<form method="post" action="options.php">
196 -<?php settings_fields('autoptimize'); ?>
200 +<ul>
197 201
198 -<ul>
202 +<?php
203 +// Only show enable site configuration in network site option.
204 +if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
205 +?>
206 + <li class="itemDetail multiSite">
207 + <h2 class="itemTitle"><?php esc_html_e( 'Multisite Options', 'autoptimize' ); ?></h2>
208 + <table class="form-table">
209 + <tr valign="top">
210 + <th scope="row"><?php esc_html_e( 'Enable site configuration?', 'autoptimize' ); ?></th>
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" ' : ''; ?>/>
212 + <?php esc_html_e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td>
213 + </tr>
214 + </table>
215 + </li>
216 +<?php } else { ?>
217 + <input type="hidden" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" value="on" />
218 +<?php } ?>
199 219
200 220 <li class="itemDetail">
201 -<h2 class="itemTitle"><?php _e('HTML Options','autoptimize'); ?></h2>
221 +<h2 class="itemTitle"><?php esc_html_e( 'JavaScript Options', 'autoptimize' ); ?></h2>
202 222 <table class="form-table">
203 223 <tr valign="top">
204 -<th scope="row"><?php _e('Optimize HTML Code?','autoptimize'); ?></th>
205 -<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo get_option('autoptimize_html')?'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>
206 226 </tr>
207 -<tr class="<?php echo $hiddenClass;?>html_sub ao_adv" valign="top">
208 -<th scope="row"><?php _e('Keep HTML comments?','autoptimize'); ?></th>
209 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo get_option('autoptimize_html_keepcomments')?'checked="checked" ':''; ?>/>
210 -<?php _e('Enable this if you want HTML comments to remain in the page.','autoptimize'); ?></label></td>
227 +<tr valign="top" class="js_sub js_aggregate_master">
228 +<th scope="row"><?php esc_html_e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
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" ' : ''; ?>/>
230 +<?php esc_html_e( 'Aggregate all linked JS-files to have them loaded non-render blocking?', 'autoptimize' ); ?></label></td>
211 231 </tr>
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>
236 +</tr>
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>
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>
257 +<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
258 +<tr valign="top" class="js_sub js_aggregate">
259 +<th scope="row">
260 +<?php
261 + esc_html_e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
262 + echo ' <i>' . esc_html__( '(deprecated)', 'autoptimize' ) . '</i>';
263 +?>
264 +</th>
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>
267 +</tr>
268 +<?php } ?>
269 +<tr valign="top" class="js_sub">
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 />
272 +<?php
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' );
274 +?>
275 +</label></td>
276 +</tr>
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>
280 +</tr>
212 281 </table>
213 282 </li>
214 283
215 284 <li class="itemDetail">
216 -<h2 class="itemTitle"><?php _e('JavaScript Options','autoptimize'); ?></h2>
217 -<table class="form-table">
285 +<h2 class="itemTitle"><?php esc_html_e( 'CSS Options', 'autoptimize' ); ?></h2>
286 +<table class="form-table">
218 287 <tr valign="top">
219 -<th scope="row"><?php _e('Optimize JavaScript Code?','autoptimize'); ?></th>
220 -<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo get_option('autoptimize_js')?'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>
221 290 </tr>
222 -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv">
223 -<th scope="row"><?php _e('Force JavaScript in &lt;head&gt;?','autoptimize'); ?></th>
224 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo get_option('autoptimize_js_forcehead')?'checked="checked" ':''; ?>/>
225 -<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.','autoptimize'); ?></label></td>
291 +<tr class="css_sub" valign="top">
292 +<th scope="row"><?php esc_html_e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
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" ' : ''; ?>/>
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>
226 295 </tr>
227 -<?php if (get_option('autoptimize_js_justhead')) { ?>
228 -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv">
229 -<th scope="row"><?php _e('Look for scripts only in &lt;head&gt;?','autoptimize'); echo ' <i>'. __('(deprecated)','autoptimize') . '</i>'; ?></th>
230 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo get_option('autoptimize_js_justhead')?'checked="checked" ':''; ?>/>
231 -<?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>
296 +<tr valign="top" class="css_sub css_aggregate">
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>
232 300 </tr>
301 +<tr class="css_sub css_aggregate" valign="top">
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>
305 +</tr>
306 +<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
307 +<tr valign="top" class="css_sub css_aggregate">
308 +<th scope="row">
309 +<?php
310 +esc_html_e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
311 +echo ' <i>' . esc_html__( '(deprecated)', 'autoptimize' ) . '</i>';
312 +?>
313 +</th>
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>
316 +</tr>
233 317 <?php } ?>
234 -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv">
235 -<th scope="row"><?php _e('Also aggregate inline JS?','autoptimize'); ?></th>
236 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo get_option('autoptimize_js_include_inline')?'checked="checked" ':''; ?>/>
237 -<?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>
318 +<tr valign="top" class="css_sub">
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" ' : ''; ?>/>
321 +<?php
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>' );
327 +?>
328 +</label></td>
238 329 </tr>
239 -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv">
240 -<th scope="row"><?php _e('Exclude scripts from Autoptimize:','autoptimize'); ?></th>
241 -<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo get_option('autoptimize_js_exclude',"seal.js, js/jquery/jquery.js"); ?>"/><br />
242 -<?php _e('A comma-separated list of scripts you want to exclude from being optimized, for example \'whatever.js, another.js\' (without the quotes) to exclude those scripts from being aggregated and minimized by Autoptimize.','autoptimize'); ?></label></td>
330 +<tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
331 +<th scope="row"></th>
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>
243 333 </tr>
244 -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv">
245 -<th scope="row"><?php _e('Add try-catch wrapping?','autoptimize'); ?></th>
246 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo get_option('autoptimize_js_trycatch')?'checked="checked" ':''; ?>/>
247 -<?php _e('If your scripts break because of a JS-error, you might want to try this.','autoptimize'); ?></label></td>
334 +<tr valign="top" class="css_sub css_aggregate">
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>
248 338 </tr>
339 +<tr valign="top" class="css_sub">
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 />
342 +<?php
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' );
344 +?>
345 +</label></td>
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 } ?>
249 370 </table>
250 371 </li>
251 372
252 373 <li class="itemDetail">
253 -<h2 class="itemTitle"><?php _e('CSS Options','autoptimize'); ?></h2>
254 -<table class="form-table">
374 +<h2 class="itemTitle"><?php esc_html_e( 'HTML Options', 'autoptimize' ); ?></h2>
375 +<table class="form-table">
255 376 <tr valign="top">
256 -<th scope="row"><?php _e('Optimize CSS Code?','autoptimize'); ?></th>
257 -<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo get_option('autoptimize_css')?'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>
258 379 </tr>
259 -<tr class="<?php echo $hiddenClass;?>css_sub ao_adv" valign="top">
260 -<th scope="row"><?php _e('Generate data: URIs for images?','autoptimize'); ?></th>
261 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo get_option('autoptimize_css_datauris')?'checked="checked" ':''; ?>/>
262 -<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.','autoptimize'); ?></label></td>
380 +<tr class="html_sub" valign="top">
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>
263 384 </tr>
264 -<?php if (get_option('autoptimize_css_justhead')) { ?>
265 -<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv">
266 -<th scope="row"><?php _e('Look for styles only in &lt;head&gt;?','autoptimize'); echo ' <i>'. __('(deprecated)','autoptimize') . '</i>'; ?></th>
267 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo get_option('autoptimize_css_justhead')?'checked="checked" ':''; ?>/>
268 -<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.','autoptimize'); ?></label></td>
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>
269 389 </tr>
270 -<?php } ?>
271 -<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv">
272 -<th scope="row"><?php _e('Also aggregate inline CSS?','autoptimize'); ?></th>
273 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo get_option('autoptimize_css_include_inline','1')?'checked="checked" ':''; ?>/>
274 -<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.','autoptimize'); ?></label></td>
275 -</tr>
276 -<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv">
277 -<th scope="row"><?php _e('Inline and Defer CSS?','autoptimize'); ?></th>
278 -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo get_option('autoptimize_css_defer')?'checked="checked" ':''; ?>/>
279 -<?php _e('Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="http://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> before activating this option!','autoptimize'); ?></label></td>
280 -</tr>
281 -<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv" id="autoptimize_css_defer_inline">
282 -<th scope="row"></th>
283 -<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e('Paste the above the fold CSS here.','autoptimize'); ?>" name="autoptimize_css_defer_inline"><?php echo get_option('autoptimize_css_defer_inline'); ?></textarea></label></td>
284 -</tr>
285 -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv css_sub">
286 -<th scope="row"><?php _e('Inline all CSS?','autoptimize'); ?></th>
287 -<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo get_option('autoptimize_css_inline')?'checked="checked" ':''; ?>/>
288 -<?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>
289 -</tr>
290 -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv css_sub">
291 -<th scope="row"><?php _e('Exclude CSS from Autoptimize:','autoptimize'); ?></th>
292 -<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo get_option('autoptimize_css_exclude','wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css'); ?>"/><br />
293 -<?php _e('A comma-separated list of CSS you want to exclude from being optimized.','autoptimize'); ?></label></td>
294 -</tr>
295 390 </table>
296 391 </li>
297 392
298 393 <li class="itemDetail">
299 -<h2 class="itemTitle"><?php _e('CDN Options','autoptimize'); ?></h2>
300 -<table class="form-table">
394 +<h2 class="itemTitle"><?php esc_html_e( 'CDN Options', 'autoptimize' ); ?></h2>
395 +<table class="form-table">
301 396 <tr valign="top">
302 -<th scope="row"><?php _e('CDN Base URL','autoptimize'); ?></th>
303 -<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" value="<?php echo esc_url(get_option('autoptimize_cdn_url',''),array("http","https")); ?>" /><br />
304 -<?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>
305 413 </tr>
306 414 </table>
307 415 </li>
308 416
309 -<li class="<?php echo $hiddenClass;?>itemDetail ao_adv">
310 -<h2 class="itemTitle"><?php _e('Cache Info','autoptimize'); ?></h2>
311 -<table class="form-table" >
312 -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
313 -<th scope="row"><?php _e('Cache folder','autoptimize'); ?></th>
314 -<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td>
417 +<li class="itemDetail">
418 +<h2 class="itemTitle"><?php esc_html_e( 'Cache Info', 'autoptimize' ); ?></h2>
419 +<table class="form-table" >
420 +<tr valign="top" >
421 +<th scope="row"><?php esc_html_e( 'Cache folder', 'autoptimize' ); ?></th>
422 +<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td>
315 423 </tr>
316 -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
317 -<th scope="row"><?php _e('Can we write?','autoptimize'); ?></th>
318 -<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes','autoptimize') : __('No','autoptimize')); ?></td>
424 +<tr valign="top" >
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>
319 427 </tr>
320 -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
321 -<th scope="row"><?php _e('Cached styles and scripts','autoptimize'); ?></th>
322 -<td><?php
323 - $AOstatArr=autoptimizeCache::stats();
324 - $AOcacheSize=round($AOstatArr[1]/1024);
325 - printf( __( '%1$s files, totalling %2$s Kbytes (calculated at %3$s)', 'autoptimize'), $AOstatArr[0], $AOcacheSize, date("H:i e", $AOstatArr[2]) );
326 -?></td>
428 +<tr valign="top" >
429 +<th scope="row"><?php esc_html_e( 'Cached styles and scripts', 'autoptimize' ); ?></th>
430 +<td>
431 + <?php
432 + $ao_stat_arr = autoptimizeCache::stats();
433 + if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) {
434 + $ao_cache_size = size_format( $ao_stat_arr[1], 2 );
435 + $details = '';
436 + if ( $ao_cache_size > 0 ) {
437 + $details = ', ~' . $ao_cache_size . ' total';
438 + }
439 + // translators: Kilobytes + timestamp shown.
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
441 + }
442 + ?>
443 +</td>
327 444 </tr>
328 445 </table>
329 446 </li>
330 447
331 -<li class="<?php echo $hiddenClass;?>itemDetail ao_adv">
332 -<h2 class="itemTitle"><?php _e('Misc Options','autoptimize'); ?></h2>
333 -<table class="form-table">
334 - <tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
335 - <th scope="row"><?php _e('Save aggregated script/css as static files?','autoptimize'); ?></th>
336 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo get_option('autoptimize_cache_nogzip','1')?'checked="checked" ':''; ?>/>
337 - <?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>
338 - </td>
339 - </tr>
340 - <tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
341 - <th scope="row"><?php _e('Also optimize for logged in users?','autoptimize'); ?></th>
342 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo get_option('autoptimize_optimize_logged','1')?'checked="checked" ':''; ?>/>
343 - <?php _e('By default Autoptimize is also active for logged on users, uncheck not to optimize when logged in e.g. to use a pagebuilder.','autoptimize'); ?></label>
344 - </td>
345 - </tr>
346 - <?php
347 - if ( function_exists("is_checkout") || function_exists("is_cart") || function_exists("edd_is_checkout") || function_exists("wpsc_is_cart") || function_exists("wpsc_is_checkout") ) {
348 - ?>
349 - <tr valign="top" class="<?php echo $hiddenClass;?>ao_adv">
350 - <th scope="row"><?php _e('Also optimize shop cart/ checkout?','autoptimize'); ?></th>
351 - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo get_option('autoptimize_optimize_checkout','1')?'checked="checked" ':''; ?>/>
352 - <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.','autoptimize'); ?></label>
353 - </td>
354 - </tr>
355 - <?php
356 - }
357 - ?>
448 +<li class="itemDetail">
449 +<h2 class="itemTitle"><?php esc_html_e( 'Misc Options', 'autoptimize' ); ?></h2>
450 +<table class="form-table">
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>
455 + </tr>
456 + <?php
457 + $_min_excl_class = '';
458 + if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) {
459 + $_min_excl_class = 'hidden';
460 + }
461 + ?>
462 + <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>">
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>
466 + </tr>
467 + <tr valign="top">
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>
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>
481 + <?php
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' ) ) {
483 + ?>
484 + <tr valign="top" >
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>
488 + </td>
489 + </tr>
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>
358 505 </table>
359 506 </li>
360 507
361 508 </ul>
362 509
363 -<input type="hidden" id="autoptimize_show_adv" name="autoptimize_show_adv" value="<?php echo get_option('autoptimize_show_adv','0'); ?>">
364 -
365 510 <p class="submit">
366 -<input type="submit" class="button-secondary" value="<?php _e('Save Changes','autoptimize') ?>" />
367 -<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' ); ?>" />
368 513 </p>
369 514
370 515 </form>
371 516 </div>
372 -<div id="autoptimize_admin_feed" class="hidden">
517 +<div id="autoptimize_admin_feed">
518 + <?php if ( apply_filters( 'autoptimize_filter_show_partner_tabs', true ) ) { ?>
373 519 <div class="autoptimize_banner hidden">
374 - <ul>
375 - <?php
376 - if (apply_filters('autoptimize_settingsscreen_remotehttp',true)) {
377 - $AO_banner=get_transient("autoptimize_banner");
378 - if (empty($AO_banner)) {
379 - $banner_resp = wp_remote_get("http://misc.optimizingmatters.com/autoptimize_news.html");
380 - if (!is_wp_error($banner_resp)) {
381 - if (wp_remote_retrieve_response_code($banner_resp)=="200") {
382 - $AO_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp));
383 - set_transient("autoptimize_banner",$AO_banner,DAY_IN_SECONDS);
384 - }
520 + <ul>
521 + <?php
522 + if ( $this->settings_screen_do_remote_http ) {
523 + $ao_banner = get_transient( 'autoptimize_banner' );
524 + if ( empty( $ao_banner ) ) {
525 + $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
526 + if ( ! is_wp_error( $banner_resp ) ) {
527 + if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) {
528 + $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
529 + set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS );
385 530 }
386 531 }
387 - echo $AO_banner;
388 532 }
533 + echo $ao_banner;
534 + }
535 + ?>
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>' );
389 540 ?>
390 - <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.","autoptimize"); ?></li>
391 - <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>
392 - </ul>
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>
543 + </ul>
393 544 </div>
545 + <?php } ?>
394 546 <div style="margin-left:10px;margin-top:-5px;">
395 547 <h2>
396 - <?php _e("futtta about","autoptimize") ?>
397 - <select id="feed_dropdown" >
398 - <option value="1"><?php _e("Autoptimize","autoptimize") ?></option>
399 - <option value="2"><?php _e("WordPress","autoptimize") ?></option>
400 - <option value="3"><?php _e("Web Technology","autoptimize") ?></option>
401 - </select>
548 + <?php esc_html_e( 'Autoptimize news', 'autoptimize' ); ?>
402 549 </h2>
403 550 <div id="futtta_feed">
404 551 <div id="autoptimizefeed">
405 - <?php $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_autoptimize"); ?>
552 + <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
406 553 </div>
407 - <div id="wordpressfeed">
408 - <?php $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_wordpress"); ?>
409 - </div>
410 - <div id="webtechfeed">
411 - <?php $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_webtech"); ?>
412 - </div>
413 554 </div>
414 555 </div>
415 - <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 } ?>
416 559 </div>
417 -
418 560 <script type="text/javascript">
419 - var feed = new Array;
420 - feed[1]="autoptimizefeed";
421 - feed[2]="wordpressfeed";
422 - feed[3]="webtechfeed";
423 - cookiename="autoptimize_feed";
424 -
425 561 jQuery(document).ready(function() {
426 562 check_ini_state();
427 - jQuery('#autoptimize_admin_feed').fadeTo("slow",1).show();
563 +
428 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();
429 565
430 - jQuery( "#feed_dropdown" ).change(function() {
431 - jQuery("#futtta_feed").fadeTo(0,0);
432 - jQuery("#futtta_feed").fadeTo("slow",1);
433 - });
434 -
435 - jQuery( "#ao_show_adv" ).click(function() {
436 - jQuery( "#ao_show_adv" ).hide();
437 - jQuery( "#ao_hide_adv" ).show();
438 - jQuery( ".ao_adv" ).removeClass("hidden");
439 - jQuery( ".ao_adv" ).show("slow");
440 - if (jQuery("#autoptimize_css").attr('checked')) {
441 - jQuery(".css_sub:visible").fadeTo("fast",1);
442 - if (!jQuery("#autoptimize_css_defer").attr('checked')) {
443 - jQuery("#autoptimize_css_defer_inline").hide();
444 - }
445 - }
446 - if (jQuery("#autoptimize_js").attr('checked')) {
447 - jQuery(".js_sub:visible").fadeTo("fast",1);
448 - }
449 - check_ini_state()
450 - jQuery( "input#autoptimize_show_adv" ).val("1");
451 - });
452 -
453 - jQuery( "#ao_hide_adv" ).click(function() {
454 - jQuery( "#ao_hide_adv" ).hide();
455 - jQuery( "#ao_show_adv" ).show();
456 - jQuery( ".ao_adv" ).hide("slow");
457 - jQuery( ".ao_adv" ).addClass("hidden");
458 - if (!jQuery("#autoptimize_css").attr('checked')) {
459 - jQuery(".css_sub:visible").fadeTo("fast",.33);
460 - }
461 - if (!jQuery("#autoptimize_js").attr('checked')) {
462 - jQuery(".js_sub:visible").fadeTo("fast",.33);
463 - }
464 - check_ini_state()
465 - jQuery( "input#autoptimize_show_adv" ).val("0");
466 - });
467 -
468 566 jQuery( "#autoptimize_html" ).change(function() {
469 567 if (this.checked) {
470 568 jQuery(".html_sub:visible").fadeTo("fast",1);
471 569 } else {
@@ -480,8 +578,41 @@
480 578 jQuery(".js_sub:visible").fadeTo("fast",.33);
481 579 }
482 580 });
483 581
582 + jQuery( "#autoptimize_js_aggregate" ).change(function() {
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" );
591 + } else {
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"
595 + jQuery( "#min_excl_row" ).hide();
596 + }
597 + check_exclusions( "js", "off" );
598 + }
599 + });
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 +
484 615 jQuery( "#autoptimize_css" ).change(function() {
485 616 if (this.checked) {
486 617 jQuery(".css_sub:visible").fadeTo("fast",1);
487 618 } else {
@@ -488,8 +619,22 @@
488 619 jQuery(".css_sub:visible").fadeTo("fast",.33);
489 620 }
490 621 });
491 622
623 + jQuery( "#autoptimize_css_aggregate" ).change(function() {
624 + if (this.checked && jQuery("#autoptimize_css").prop('checked')) {
625 + jQuery(".css_aggregate:visible").fadeTo("fast",1);
626 + jQuery( "#min_excl_row" ).show();
627 + check_exclusions( "css", "on" );
628 + } else {
629 + jQuery(".css_aggregate:visible").fadeTo("fast",.33);
630 + if ( jQuery( "#autoptimize_js_aggregate" ).prop('checked') == false ) {
631 + jQuery( "#min_excl_row" ).hide();
632 + }
633 + check_exclusions( "css", "off" );
634 + }
635 + });
636 +
492 637 jQuery( "#autoptimize_css_inline" ).change(function() {
493 638 if (this.checked) {
494 639 jQuery("#autoptimize_css_defer").prop("checked",false);
495 640 jQuery("#autoptimize_css_defer_inline").hide("slow");
@@ -504,15 +649,18 @@
504 649 jQuery("#autoptimize_css_defer_inline").hide("slow");
505 650 }
506 651 });
507 652
508 - jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) });
509 - feedid=jQuery.cookie(cookiename);
510 - if(typeof(feedid) !== "string") feedid=1;
511 - show_feed(feedid);
653 + jQuery( "#autoptimize_enable_site_config" ).change(function() {
654 + if (this.checked) {
655 + jQuery("li.itemDetail:not(.multiSite)").fadeTo("fast",.33);
656 + } else {
657 + jQuery("li.itemDetail:not(.multiSite)").fadeTo("fast",1);
658 + }
659 + });
512 660 })
513 661
514 - // validate cdn_url
662 + // validate cdn_url.
515 663 var cdn_url=document.getElementById("cdn_url");
516 664 cdn_url_baseCSS=cdn_url.style.cssText;
517 665 if ("validity" in cdn_url) {
518 666 jQuery("#cdn_url").focusout(function (event) {
@@ -523,27 +671,56 @@
523 671 }});
524 672 }
525 673
526 674 function check_ini_state() {
527 - if (!jQuery("#autoptimize_css_defer").attr('checked')) {
675 + if (!jQuery("#autoptimize_css_defer").prop('checked')) {
528 676 jQuery("#autoptimize_css_defer_inline").hide();
529 677 }
530 - if (!jQuery("#autoptimize_html").attr('checked')) {
678 + if (!jQuery("#autoptimize_html").prop('checked')) {
531 679 jQuery(".html_sub:visible").fadeTo('fast',.33);
532 680 }
533 - if (!jQuery("#autoptimize_css").attr('checked')) {
681 + if (!jQuery("#autoptimize_css").prop('checked')) {
534 682 jQuery(".css_sub:visible").fadeTo('fast',.33);
535 683 }
536 - if (!jQuery("#autoptimize_js").attr('checked')) {
684 + if (!jQuery("#autoptimize_css_aggregate").prop('checked')) {
685 + jQuery(".css_aggregate:visible").fadeTo('fast',.33);
686 + }
687 + if (jQuery("#autoptimize_js_aggregate").prop('checked')) {
688 + jQuery( ".js_aggregate" ).show( 'fast' );
689 + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'fast', .33 );
690 + }
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 );
694 + }
695 + if (jQuery("#autoptimize_enable_site_config").prop('checked')) {
696 + jQuery("li.itemDetail:not(.multiSite)").fadeTo('fast',.33);
697 + }
698 + if (!jQuery("#autoptimize_js").prop('checked')) {
537 699 jQuery(".js_sub:visible").fadeTo('fast',.33);
538 700 }
539 701 }
540 702
541 - function show_feed(id) {
542 - jQuery('#futtta_feed').children().hide();
543 - jQuery('#'+feed[id]).show();
544 - jQuery("#feed_dropdown").val(id);
545 - 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 + }
546 723 }
547 724 </script>
548 725 </div>
549 726
@@ -549,66 +726,96 @@
549 726
550 727 <?php
551 728 }
552 729
553 - public function addmenu() {
554 - $hook=add_options_page(__('Autoptimize Options','autoptimize'),'Autoptimize','manage_options','autoptimize',array($this,'show'));
555 - add_action( 'admin_print_scripts-'.$hook,array($this,'autoptimize_admin_scripts'));
556 - add_action( 'admin_print_styles-'.$hook,array($this,'autoptimize_admin_styles'));
730 + public function addmenu()
731 + {
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' ) );
745 + } else {
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' ) );
748 + }
749 +
750 + add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
751 + add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
557 752 }
558 753
559 - public function autoptimize_admin_scripts() {
560 - wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'),null,true);
561 - wp_enqueue_script('unslider', plugins_url('/external/js/unslider-min.js', __FILE__), array('jquery'),null,true);
754 + public function autoptimize_admin_scripts()
755 + {
756 + wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider.min.js', __FILE__ ), array( 'jquery' ), AUTOPTIMIZE_PLUGIN_VERSION, true );
562 757 }
563 758
564 - public function autoptimize_admin_styles() {
565 - wp_enqueue_style('unslider', plugins_url('/external/js/unslider.css', __FILE__));
566 - wp_enqueue_style('unslider-dots', plugins_url('/external/js/unslider-dots.css', __FILE__));
759 + public function autoptimize_admin_styles()
760 + {
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 );
567 763 }
568 764
569 765 public function registersettings() {
570 - register_setting('autoptimize','autoptimize_html');
571 - register_setting('autoptimize','autoptimize_html_keepcomments');
572 - register_setting('autoptimize','autoptimize_js');
573 - register_setting('autoptimize','autoptimize_js_exclude');
574 - register_setting('autoptimize','autoptimize_js_trycatch');
575 - register_setting('autoptimize','autoptimize_js_justhead');
576 - register_setting('autoptimize','autoptimize_js_forcehead');
577 - register_setting('autoptimize','autoptimize_js_include_inline');
578 - register_setting('autoptimize','autoptimize_css');
579 - register_setting('autoptimize','autoptimize_css_exclude');
580 - register_setting('autoptimize','autoptimize_css_justhead');
581 - register_setting('autoptimize','autoptimize_css_datauris');
582 - register_setting('autoptimize','autoptimize_css_defer');
583 - register_setting('autoptimize','autoptimize_css_defer_inline');
584 - register_setting('autoptimize','autoptimize_css_inline');
585 - register_setting('autoptimize','autoptimize_css_include_inline');
586 - register_setting('autoptimize','autoptimize_cdn_url');
587 - register_setting('autoptimize','autoptimize_cache_clean');
588 - register_setting('autoptimize','autoptimize_cache_nogzip');
589 - register_setting('autoptimize','autoptimize_show_adv');
590 - register_setting('autoptimize','autoptimize_optimize_logged');
591 - register_setting('autoptimize','autoptimize_optimize_checkout');
766 + register_setting( 'autoptimize', 'autoptimize_html' );
767 + register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
768 + register_setting( 'autoptimize', 'autoptimize_html_minify_inline' );
769 + register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
770 + register_setting( 'autoptimize', 'autoptimize_js' );
771 + register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
772 + register_setting( 'autoptimize', 'autoptimize_js_defer_not_aggregate' );
773 + register_setting( 'autoptimize', 'autoptimize_js_defer_inline' );
774 + register_setting( 'autoptimize', 'autoptimize_js_exclude' );
775 + register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
776 + register_setting( 'autoptimize', 'autoptimize_js_justhead' );
777 + register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
778 + register_setting( 'autoptimize', 'autoptimize_js_include_inline' );
779 + register_setting( 'autoptimize', 'autoptimize_css' );
780 + register_setting( 'autoptimize', 'autoptimize_css_aggregate' );
781 + register_setting( 'autoptimize', 'autoptimize_css_exclude' );
782 + register_setting( 'autoptimize', 'autoptimize_css_justhead' );
783 + register_setting( 'autoptimize', 'autoptimize_css_datauris' );
784 + register_setting( 'autoptimize', 'autoptimize_css_defer' );
785 + register_setting( 'autoptimize', 'autoptimize_css_defer_inline' );
786 + register_setting( 'autoptimize', 'autoptimize_css_inline' );
787 + register_setting( 'autoptimize', 'autoptimize_css_include_inline' );
788 + register_setting( 'autoptimize', 'autoptimize_cdn_url' );
789 + register_setting( 'autoptimize', 'autoptimize_cache_clean' );
790 + register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
791 + register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
792 + register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
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' );
592 797 }
593 798
594 - public function setmeta($links,$file=null) {
595 - //Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/
596 - //Do it only once - saves time
799 + public function setmeta( $links, $file = null )
800 + {
801 + // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/.
802 + // Do it only once - saves time.
597 803 static $plugin;
598 - if(empty($plugin))
599 - $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php');
600 -
601 - if($file===null) {
602 - //2.7
603 - $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings'));
604 - array_unshift($links,$settings_link);
804 + if ( empty( $plugin ) ) {
805 + $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
806 + }
807 +
808 + if ( null === $file ) {
809 + // 2.7 and lower.
810 + $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', esc_html__( 'Settings' ) );
811 + array_unshift( $links, $settings_link );
605 812 } else {
606 - //2.8
607 - //If it's us, add the link
608 - if($file === $plugin) {
609 - $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>',__('Settings')));
610 - $links = array_merge($links,$newlink);
813 + // 2.8 and higher.
814 + // If it's us, add the link.
815 + if ( $file === $plugin ) {
816 + $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', esc_html__( 'Settings' ) ) );
817 + $links = array_merge( $links, $newlink );
611 818 }
612 819 }
613 820
614 821 return $links;
@@ -613,71 +820,148 @@
613 820
614 821 return $links;
615 822 }
616 823
617 - public function get($key) {
618 - if(!is_array($this->config)) {
619 - //Default config
620 - $config = array('autoptimize_html' => 0,
621 - 'autoptimize_html_keepcomments' => 0,
622 - 'autoptimize_js' => 0,
623 - 'autoptimize_js_exclude' => "seal.js, js/jquery/jquery.js",
624 - 'autoptimize_js_trycatch' => 0,
625 - 'autoptimize_js_justhead' => 0,
626 - 'autoptimize_js_include_inline' => 0,
627 - 'autoptimize_js_forcehead' => 0,
628 - 'autoptimize_css' => 0,
629 - 'autoptimize_css_exclude' => "admin-bar.min.css, dashicons.min.css, wp-content/cache/, wp-content/uploads/",
630 - 'autoptimize_css_justhead' => 0,
631 - 'autoptimize_css_include_inline' => 1,
632 - 'autoptimize_css_defer' => 0,
633 - 'autoptimize_css_defer_inline' => "",
634 - 'autoptimize_css_inline' => 0,
635 - 'autoptimize_css_datauris' => 0,
636 - 'autoptimize_cdn_url' => "",
637 - 'autoptimize_cache_nogzip' => 1,
638 - 'autoptimize_show_adv' => 0,
639 - 'autoptimize_optimize_logged' => 1,
640 - 'autoptimize_optimize_checkout' => 1
641 - );
824 + /**
825 + * Provides the default options.
826 + *
827 + * @return array
828 + */
829 + public static function get_defaults()
830 + {
831 + static $config = array(
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,
862 + );
642 863
643 - //Override with user settings
644 - foreach(array_keys($config) as $name) {
645 - $conf = get_option($name);
646 - if($conf!==false) {
647 - //It was set before!
648 - $config[$name] = $conf;
864 + return $config;
865 + }
866 +
867 + /**
868 + * Returns default option values for autoptimizeExtra.
869 + *
870 + * @return array
871 + */
872 + public static function get_ao_extra_default_options()
873 + {
874 + $defaults = array(
875 + 'autoptimize_extra_checkbox_field_1' => '0',
876 + 'autoptimize_extra_checkbox_field_0' => '0',
877 + 'autoptimize_extra_radio_field_4' => '1',
878 + 'autoptimize_extra_text_field_2' => '',
879 + 'autoptimize_extra_text_field_3' => '',
880 + 'autoptimize_extra_text_field_7' => '',
881 + 'autoptimize_extra_checkbox_field_8' => '0',
882 + );
883 +
884 + return $defaults;
885 + }
886 +
887 + /**
888 + * Returns default option values for autoptimizeExtra.
889 + *
890 + * @return array
891 + */
892 + public static function get_ao_imgopt_default_options()
893 + {
894 + $defaults = array(
895 + 'autoptimize_imgopt_checkbox_field_1' => '0', // imgopt off.
896 + 'autoptimize_imgopt_select_field_2' => '2', // quality glossy.
897 + 'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
898 + 'autoptimize_imgopt_checkbox_field_4' => '0', // avif off (might be removed).
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).
902 + );
903 + return $defaults;
904 + }
905 +
906 + /**
907 + * Returns preload JS onload handler.
908 + *
909 + * @param string $media media attribute value the JS to use.
910 + *
911 + * @return string
912 + */
913 + public static function get_ao_css_preload_onload( $media = 'all' )
914 + {
915 + $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" );
916 + return $preload_onload;
917 + }
918 +
919 + public function get( $key )
920 + {
921 + if ( ! is_array( $this->config ) ) {
922 + // Default config.
923 + $config = self::get_defaults();
924 +
925 + // Override with user settings.
926 + foreach ( array_keys( $config ) as $name ) {
927 + $conf = autoptimizeOptionWrapper::get_option( $name );
928 + if ( false !== $conf ) {
929 + // It was set before!
930 + $config[ $name ] = $conf;
649 931 }
650 932 }
651 933
652 - //Save for next question
934 + // Save for next call.
653 935 $this->config = apply_filters( 'autoptimize_filter_get_config', $config );
654 936 }
655 937
656 - if(isset($this->config[$key]))
657 - return $this->config[$key];
938 + if ( isset( $this->config[ $key ] ) ) {
939 + return $this->config[ $key ];
940 + }
658 941
659 942 return false;
660 943 }
661 944
662 - private function getFutttaFeeds($url) {
663 - if (apply_filters('autoptimize_settingsscreen_remotehttp',true)) {
664 - $rss = fetch_feed( $url );
945 + private function get_futtta_feeds( $url ) {
946 + if ( $this->settings_screen_do_remote_http ) {
947 + $rss = fetch_feed( $url );
665 948 $maxitems = 0;
666 949
667 950 if ( ! is_wp_error( $rss ) ) {
668 - $maxitems = $rss->get_item_quantity( 7 );
951 + $maxitems = $rss->get_item_quantity( 7 );
669 952 $rss_items = $rss->get_items( 0, $maxitems );
670 953 }
671 954 ?>
672 955 <ul>
673 - <?php if ( $maxitems == 0 ) : ?>
674 - <li><?php _e( 'No items', 'autoptimize' ); ?></li>
956 + <?php if ( 0 == $maxitems ) : ?>
957 + <li><?php esc_html_e( 'No items', 'autoptimize' ); ?></li>
675 958 <?php else : ?>
676 959 <?php foreach ( $rss_items as $item ) : ?>
677 960 <li>
678 961 <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
679 - title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date('j F Y | g:i a') ); ?>">
962 + <?php // translators: the variable contains a date. ?>
963 + title="<?php printf( esc_html__( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>">
680 964 <?php echo esc_html( $item->get_title() ); ?>
681 965 </a>
682 966 </li>
683 967 <?php endforeach; ?>
@@ -682,35 +966,151 @@
682 966 </li>
683 967 <?php endforeach; ?>
684 968 <?php endif; ?>
685 969 </ul>
686 - <?php
970 + <?php
687 971 }
688 972 }
689 973
690 - // based on http://wordpress.stackexchange.com/a/58826
691 - static function ao_admin_tabs(){
692 - $tabs = apply_filters('autoptimize_filter_settingsscreen_tabs',array('autoptimize' => __('Main','autoptimize')));
693 - $tabContent="";
694 - if (count($tabs)>1) {
695 - if(isset($_GET['page'])){
696 - $currentId = $_GET['page'];
974 + static function ao_admin_tabs()
975 + {
976 + // based on http://wordpress.stackexchange.com/a/58826 .
977 + $tabs = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => esc_html__( 'JS, CSS &amp; HTML', 'autoptimize' ) ) );
978 + $tab_content = '';
979 + $tabs_count = count( $tabs );
980 + if ( $tabs_count > 1 ) {
981 + if ( isset( $_GET['page'] ) ) {
982 + $current_id = $_GET['page'];
697 983 } else {
698 - $currentId = "autoptimize";
984 + $current_id = 'autoptimize';
699 985 }
700 - $tabContent .= "<h2 class=\"nav-tab-wrapper\">";
701 - foreach($tabs as $tabId => $tabName){
702 - if($currentId == $tabId){
703 - $class = " nav-tab-active";
704 - } else{
705 - $class = "";
986 + $tab_content .= '<h2 class="nav-tab-wrapper">';
987 + foreach ( $tabs as $tab_id => $tab_name ) {
988 + if ( $current_id == $tab_id ) {
989 + $class = ' nav-tab-active';
990 + } else {
991 + $class = '';
706 992 }
707 - $tabContent .= '<a class="nav-tab'.$class.'" href="?page='.$tabId.'">'.$tabName.'</a>';
993 + $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>';
708 994 }
709 - $tabContent .= "</h2>";
995 + $tab_content .= '</h2>';
710 996 } else {
711 - $tabContent = "<hr/>";
997 + $tab_content = '<hr/>';
712 998 }
713 999
714 - return $tabContent;
1000 + return $tab_content;
1001 + }
1002 +
1003 + /**
1004 + * Returns true if in admin (and not in admin-ajax.php!)
1005 + *
1006 + * @return bool
1007 + */
1008 + public static function is_admin_and_not_ajax()
1009 + {
1010 + return ( is_admin() && ! self::doing_ajax() );
1011 + }
1012 +
1013 + /**
1014 + * Returns true if doing ajax.
1015 + *
1016 + * @return bool
1017 + */
1018 + protected static function doing_ajax()
1019 + {
1020 + if ( function_exists( 'wp_doing_ajax' ) ) {
1021 + return wp_doing_ajax();
1022 + }
1023 + return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
1024 + }
1025 +
1026 + /**
1027 + * Returns true menu or tab is to be shown.
1028 + *
1029 + * @return bool
1030 + */
1031 + public static function should_show_menu_tabs() {
1032 + if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) || false === autoptimizeOptionWrapper::is_ao_active_for_network() ) {
1033 + return true;
1034 + } else {
1035 + return false;
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;
715 1115 }
716 1116 }