PluginProbe
Autoptimize / 2.7.8
Autoptimize v2.7.8
2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.5.0 2.5.1 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 All 107 releases
autoptimize / classes / autoptimizeConfig.php

autoptimizeConfig.php in Autoptimize 2.7.8, at classes/autoptimizeConfig.php

922 lines 41.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Main configuration logic.
4 */
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit;
8 }
9
10 class autoptimizeConfig
11 {
12 /**
13 * Options.
14 *
15 * @var array
16 */
17 private $config = null;
18
19 /**
20 * Singleton instance.
21 *
22 * @var self|null
23 */
24 static private $instance = null;
25
26 /**
27 * Options.
28 *
29 * @var bool
30 */
31 private $settings_screen_do_remote_http = true;
32
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' ) );
42 }
43
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' ) ) {
60 autoptimizeCache::clearall();
61 autoptimizeOptionWrapper::update_option( 'autoptimize_cache_clean', 0 );
62 }
63
64 $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http );
65 }
66
67 // Adds the Autoptimize Toolbar to the Admin bar.
68 // (we load outside the is_admin check so it's also displayed on the frontend toolbar).
69 $toolbar = new autoptimizeToolbar();
70 }
71
72 /**
73 * Instantiates aoconfig.
74 *
75 * @return autoptimizeConfig
76 */
77 static public function instance()
78 {
79 // Only one instance.
80 if ( null === self::$instance ) {
81 self::$instance = new autoptimizeConfig();
82 }
83
84 return self::$instance;
85 }
86
87 public function show_network_message() {
88 ?>
89 <div class="wrap">
90 <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
91 <?php echo $this->ao_admin_tabs(); ?>
92 <p style="font-size:120%;"><?php echo apply_filters( 'autoptimize_filter_settingsscreen_multisite_network_message', __( 'Autoptimize is enabled and configured on a WordPress network level. Please contact your network administrator if you need Autoptimize settings changed.', 'autoptimize' ) ); ?></p>
93 </div>
94 <?php
95 }
96
97 public function show_config()
98 {
99 $conf = self::instance();
100 ?>
101 <style>
102 /* title and button */
103 #ao_title_and_button:after {content:''; display:block; clear:both;}
104
105 /* form */
106 .itemDetail {
107 background: #fff;
108 border: 1px solid #ccc;
109 padding: 15px;
110 margin: 15px 10px 10px 0;
111 }
112 .itemTitle {
113 margin-top: 0;
114 }
115
116 input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:normal;}
117 #autoptimize_main .cb_label {display: block; padding-left: 25px; text-indent: -25px;}
118
119 /* rss block */
120 #futtta_feed ul{list-style:outside;}
121 #futtta_feed {font-size:medium; margin:0px 20px;}
122
123 /* banner + unslider */
124 .autoptimize_banner {
125 margin: 0 38px;
126 padding-bottom: 5px;
127 }
128 .autoptimize_banner ul li {
129 font-size:medium;
130 text-align:center;
131 }
132 .unslider {
133 position:relative;
134 }
135 .unslider-arrow {
136 display: block;
137 left: unset;
138 margin-top: -35px;
139 margin-left: 7px;
140 margin-right: 7px;
141 border-radius: 32px;
142 background: rgba(0, 0, 0, 0.10) no-repeat 50% 50%;
143 color: rgba(255, 255, 255, 0.8);
144 font: normal 20px/1 dashicons;
145 speak: none;
146 padding: 3px 2px 3px 4px;
147 -webkit-font-smoothing: antialiased;
148 -moz-osx-font-smoothing: grayscale;
149 }
150 .unslider-arrow:hover {
151 background-color: rgba(0, 0, 0, 0.20);
152 color: #FFF;
153 }
154 .unslider-arrow.prev {
155 padding: 3px 4px 3px 2px;
156 }
157 .unslider-arrow.next {
158 right: 0px;
159 }
160 .unslider-arrow.prev::before {
161 content: "\f341";
162 }
163 .unslider-arrow.next::before {
164 content: "\f345";
165 }
166
167 /* responsive stuff: hide admin-feed on smaller screens */
168 @media (min-width: 961px) {
169 #autoptimize_main {float:left;width:69%;}
170 #autoptimize_admin_feed{float:right;width:30%;display:block !important;}
171 }
172 @media (max-width: 960px) {
173 #autoptimize_main {width:100%;}
174 #autoptimize_admin_feed {width:0%;display:none !important;}
175 }
176 @media (max-width: 782px) {
177 #autoptimize_main input[type="checkbox"] {margin-left: 10px;}
178 #autoptimize_main .cb_label {display: block; padding-left: 45px; text-indent: -45px;}
179 }
180 </style>
181
182 <div class="wrap">
183
184 <!-- Temporary nudge to disable aoccss power-up. -->
185 <?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?>
186 <div class="notice-info notice"><p>
187 <?php _e( 'Autoptimize now includes the criticalcss.com integration that was previously part of the separate power-up. If you want you can simply disable the power-up and Autoptimize will take over immediately.', 'autoptimize' ); ?>
188 </p></div>
189 <?php } ?>
190
191 <div id="autoptimize_main">
192 <h1 id="ao_title"><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1>
193 <?php echo $this->ao_admin_tabs(); ?>
194
195 <form method="post" action="<?php echo admin_url( 'options.php' ); ?>">
196 <?php settings_fields( 'autoptimize' ); ?>
197
198 <ul>
199
200 <?php
201 // Only show enable site configuration in network site option.
202 if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
203 ?>
204 <li class="itemDetail multiSite">
205 <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2>
206 <table class="form-table">
207 <tr valign="top">
208 <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th>
209 <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" ' : ''; ?>/>
210 <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td>
211 </tr>
212 </table>
213 </li>
214 <?php } else { ?>
215 <input type="hidden" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" value="on" />
216 <?php } ?>
217
218 <li class="itemDetail">
219 <h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2>
220 <table class="form-table">
221 <tr valign="top">
222 <th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th>
223 <td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td>
224 </tr>
225 <tr valign="top" class="js_sub">
226 <th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th>
227 <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" ' : ''; ?>/>
228 <?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>
229 </tr>
230 <tr valign="top" class="js_sub js_aggregate">
231 <th scope="row"><?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th>
232 <td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/>
233 <?php _e( 'Let Autoptimize also extract JS from the HTML. <strong>Warning</strong>: this can make Autoptimize\'s cache size grow quickly, so only enable this if you know what you\'re doing.', 'autoptimize' ); ?></label></td>
234 </tr>
235 <tr valign="top" class="js_sub js_aggregate">
236 <th scope="row"><?php _e( 'Force JavaScript in &lt;head&gt;?', 'autoptimize' ); ?></th>
237 <td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/>
238 <?php _e( 'Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.', 'autoptimize' ); ?></label></td>
239 </tr>
240 <?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?>
241 <tr valign="top" class="js_sub js_aggregate">
242 <th scope="row">
243 <?php
244 _e( 'Look for scripts only in &lt;head&gt;?', 'autoptimize' );
245 echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
246 ?>
247 </th>
248 <td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/>
249 <?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>
250 </tr>
251 <?php } ?>
252 <tr valign="top" class="js_sub">
253 <th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th>
254 <td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js' ) ); ?>"/><br />
255 <?php
256 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' );
257 ?>
258 </label></td>
259 </tr>
260 <tr valign="top" class="js_sub js_aggregate">
261 <th scope="row"><?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th>
262 <td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/>
263 <?php _e( 'If your scripts break because of a JS-error, you might want to try this.', 'autoptimize' ); ?></label></td>
264 </tr>
265 </table>
266 </li>
267
268 <li class="itemDetail">
269 <h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2>
270 <table class="form-table">
271 <tr valign="top">
272 <th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th>
273 <td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td>
274 </tr>
275 <tr class="css_sub" valign="top">
276 <th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th>
277 <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" ' : ''; ?>/>
278 <?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>
279 </tr>
280 <tr valign="top" class="css_sub css_aggregate">
281 <th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th>
282 <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" ' : ''; ?>/>
283 <?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td>
284 </tr>
285 <tr class="css_sub css_aggregate" valign="top">
286 <th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th>
287 <td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/>
288 <?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td>
289 </tr>
290 <?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?>
291 <tr valign="top" class="css_sub css_aggregate">
292 <th scope="row">
293 <?php
294 _e( 'Look for styles only in &lt;head&gt;?', 'autoptimize' );
295 echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>';
296 ?>
297 </th>
298 <td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/>
299 <?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td>
300 </tr>
301 <?php } ?>
302 <tr valign="top" class="css_sub">
303 <th scope="row"><?php _e( 'Inline and Defer CSS?', 'autoptimize' ); ?></th>
304 <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" ' : ''; ?>/>
305 <?php
306 _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' );
307 echo ' ';
308 $critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' );
309 // translators: links "autoptimize critical CSS" tab.
310 echo sprintf( __( 'This can be fully automated for different types of pages on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' );
311 ?>
312 </label></td>
313 </tr>
314 <tr valign="top" class="css_sub" id="autoptimize_css_defer_inline">
315 <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>
317 </tr>
318 <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 is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize' ); ?></label></td>
322 </tr>
323 <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 esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_css_exclude', 'wp-content/cache/, wp-content/uploads/, admin-bar.min.css, dashicons.min.css' ) ); ?>"/><br />
326 <?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' );
328 ?>
329 </label></td>
330 </tr>
331 </table>
332 </li>
333
334 <li class="itemDetail">
335 <h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2>
336 <table class="form-table">
337 <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>
340 </tr>
341 <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>
345 </tr>
346 </table>
347 </li>
348
349 <li class="itemDetail">
350 <h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2>
351 <table class="form-table">
352 <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>
356 </tr>
357 </table>
358 </li>
359
360 <li class="itemDetail">
361 <h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2>
362 <table class="form-table" >
363 <tr valign="top" >
364 <th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th>
365 <td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td>
366 </tr>
367 <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>
370 </tr>
371 <tr valign="top" >
372 <th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th>
373 <td>
374 <?php
375 $ao_stat_arr = autoptimizeCache::stats();
376 if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) {
377 $ao_cache_size = size_format( $ao_stat_arr[1], 2 );
378 $details = '';
379 if ( $ao_cache_size > 0 ) {
380 $details = ', ~' . $ao_cache_size . ' total';
381 }
382 // translators: Kilobytes + timestamp shown.
383 printf( __( '%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize' ), $ao_stat_arr[0], $ao_cache_size, date( 'H:i e', $ao_stat_arr[2] ) );
384 }
385 ?>
386 </td>
387 </tr>
388 </table>
389 </li>
390
391 <li class="itemDetail">
392 <h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2>
393 <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>
398 </tr>
399 <?php
400 $_min_excl_class = '';
401 if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) {
402 $_min_excl_class = 'hidden';
403 }
404 ?>
405 <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>
409 </tr>
410 <tr valign="top">
411 <th scope="row"><?php _e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th>
412 <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_cache_fallback', '1' ) ? 'checked="checked" ' : ''; ?>/>
413 <?php _e( 'Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. With this option on, Autoptimize will try to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize' ); ?></label></td>
414 </tr>
415 <tr valign="top">
416 <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th>
417 <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', '1' ) ? 'checked="checked" ' : ''; ?>/>
418 <?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>
419 </tr>
420 <?php
421 if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) {
422 ?>
423 <tr valign="top" >
424 <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th>
425 <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_checkout', '0' ) ? 'checked="checked" ' : ''; ?>/>
426 <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label>
427 </td>
428 </tr>
429 <?php } ?>
430 </table>
431 </li>
432
433 </ul>
434
435 <p class="submit">
436 <input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" />
437 <input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" />
438 </p>
439
440 </form>
441 </div>
442 <div id="autoptimize_admin_feed" class="hidden">
443 <div class="autoptimize_banner hidden">
444 <ul>
445 <?php
446 if ( $this->settings_screen_do_remote_http ) {
447 $ao_banner = get_transient( 'autoptimize_banner' );
448 if ( empty( $ao_banner ) ) {
449 $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION );
450 if ( ! is_wp_error( $banner_resp ) ) {
451 if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) {
452 $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) );
453 set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS );
454 }
455 }
456 }
457 echo $ao_banner;
458 }
459 ?>
460 <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li>
461 <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>
462 </ul>
463 </div>
464 <div style="margin-left:10px;margin-top:-5px;">
465 <h2>
466 <?php _e( 'futtta about', 'autoptimize' ); ?>
467 <select id="feed_dropdown" >
468 <option value="1"><?php _e( 'Autoptimize', 'autoptimize' ); ?></option>
469 <option value="2"><?php _e( 'WordPress', 'autoptimize' ); ?></option>
470 <option value="3"><?php _e( 'Web Technology', 'autoptimize' ); ?></option>
471 </select>
472 </h2>
473 <div id="futtta_feed">
474 <div id="autoptimizefeed">
475 <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?>
476 </div>
477 <div id="wordpressfeed">
478 <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_wordpress' ); ?>
479 </div>
480 <div id="webtechfeed">
481 <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_webtech' ); ?>
482 </div>
483 </div>
484 </div>
485 <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url() . '/' . plugin_basename( dirname( __FILE__ ) ) . '/external/do_not_donate_smallest.png'; ?>" title="<?php _e( 'Do not donate for this plugin!', 'autoptimize' ); ?>"></a></div>
486 </div>
487
488 <script type="text/javascript">
489 var feed = new Array;
490 feed[1]="autoptimizefeed";
491 feed[2]="wordpressfeed";
492 feed[3]="webtechfeed";
493 cookiename="autoptimize_feed";
494
495 jQuery(document).ready(function() {
496 check_ini_state();
497
498 jQuery('#autoptimize_admin_feed').fadeTo("slow",1).show();
499 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();
500
501 jQuery( "#feed_dropdown" ).change(function() {
502 jQuery("#futtta_feed").fadeTo(0,0);
503 jQuery("#futtta_feed").fadeTo("slow",1);
504 });
505
506 jQuery( "#autoptimize_html" ).change(function() {
507 if (this.checked) {
508 jQuery(".html_sub:visible").fadeTo("fast",1);
509 } else {
510 jQuery(".html_sub:visible").fadeTo("fast",.33);
511 }
512 });
513
514 jQuery( "#autoptimize_js" ).change(function() {
515 if (this.checked) {
516 jQuery(".js_sub:visible").fadeTo("fast",1);
517 } else {
518 jQuery(".js_sub:visible").fadeTo("fast",.33);
519 }
520 });
521
522 jQuery( "#autoptimize_js_aggregate" ).change(function() {
523 if (this.checked && jQuery("#autoptimize_js").prop('checked')) {
524 jQuery(".js_aggregate:visible").fadeTo("fast",1);
525 jQuery( "#min_excl_row" ).show();
526 } else {
527 jQuery(".js_aggregate:visible").fadeTo("fast",.33);
528 if ( jQuery( "#autoptimize_css_aggregate" ).prop('checked') == false ) {
529 jQuery( "#min_excl_row" ).hide();
530 }
531 }
532 });
533
534 jQuery( "#autoptimize_css" ).change(function() {
535 if (this.checked) {
536 jQuery(".css_sub:visible").fadeTo("fast",1);
537 } else {
538 jQuery(".css_sub:visible").fadeTo("fast",.33);
539 }
540 });
541
542 jQuery( "#autoptimize_css_aggregate" ).change(function() {
543 if (this.checked && jQuery("#autoptimize_css").prop('checked')) {
544 jQuery(".css_aggregate:visible").fadeTo("fast",1);
545 jQuery( "#min_excl_row" ).show();
546 } else {
547 jQuery(".css_aggregate:visible").fadeTo("fast",.33);
548 if ( jQuery( "#autoptimize_js_aggregate" ).prop('checked') == false ) {
549 jQuery( "#min_excl_row" ).hide();
550 }
551 }
552 });
553
554 jQuery( "#autoptimize_css_inline" ).change(function() {
555 if (this.checked) {
556 jQuery("#autoptimize_css_defer").prop("checked",false);
557 jQuery("#autoptimize_css_defer_inline").hide("slow");
558 }
559 });
560
561 jQuery( "#autoptimize_css_defer" ).change(function() {
562 if (this.checked) {
563 jQuery("#autoptimize_css_inline").prop("checked",false);
564 jQuery("#autoptimize_css_defer_inline").show("slow");
565 } else {
566 jQuery("#autoptimize_css_defer_inline").hide("slow");
567 }
568 });
569
570 jQuery( "#autoptimize_enable_site_config" ).change(function() {
571 if (this.checked) {
572 jQuery("li.itemDetail:not(.multiSite)").fadeTo("fast",.33);
573 } else {
574 jQuery("li.itemDetail:not(.multiSite)").fadeTo("fast",1);
575 }
576 });
577
578 jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) });
579 feedid=jQuery.cookie(cookiename);
580 if(typeof(feedid) !== "string") feedid=1;
581 show_feed(feedid);
582 })
583
584 // validate cdn_url.
585 var cdn_url=document.getElementById("cdn_url");
586 cdn_url_baseCSS=cdn_url.style.cssText;
587 if ("validity" in cdn_url) {
588 jQuery("#cdn_url").focusout(function (event) {
589 if (cdn_url.validity.valid) {
590 cdn_url.style.cssText=cdn_url_baseCSS;
591 } else {
592 cdn_url.style.cssText=cdn_url_baseCSS+"border:1px solid #f00;color:#f00;box-shadow: 0 0 2px #f00;";
593 }});
594 }
595
596 function check_ini_state() {
597 if (!jQuery("#autoptimize_css_defer").prop('checked')) {
598 jQuery("#autoptimize_css_defer_inline").hide();
599 }
600 if (!jQuery("#autoptimize_html").prop('checked')) {
601 jQuery(".html_sub:visible").fadeTo('fast',.33);
602 }
603 if (!jQuery("#autoptimize_css").prop('checked')) {
604 jQuery(".css_sub:visible").fadeTo('fast',.33);
605 }
606 if (!jQuery("#autoptimize_css_aggregate").prop('checked')) {
607 jQuery(".css_aggregate:visible").fadeTo('fast',.33);
608 }
609 if (!jQuery("#autoptimize_js").prop('checked')) {
610 jQuery(".js_sub:visible").fadeTo('fast',.33);
611 }
612 if (!jQuery("#autoptimize_js_aggregate").prop('checked')) {
613 jQuery(".js_aggregate:visible").fadeTo('fast',.33);
614 }
615 if (jQuery("#autoptimize_enable_site_config").prop('checked')) {
616 jQuery("li.itemDetail:not(.multiSite)").fadeTo('fast',.33);
617 }
618 }
619
620 function show_feed(id) {
621 jQuery('#futtta_feed').children().hide();
622 jQuery('#'+feed[id]).show();
623 jQuery("#feed_dropdown").val(id);
624 jQuery.cookie(cookiename,id,{ expires: 365 });
625 }
626 </script>
627 </div>
628
629 <?php
630 }
631
632 public function addmenu()
633 {
634 if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) {
635 // multisite, network admin, ao network activated: add normal settings page at network level.
636 $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) );
637 } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
638 // 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.
639 $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) );
640 } else {
641 // 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.
642 $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), 'Autoptimize', 'manage_options', 'autoptimize', array( $this, 'show_config' ) );
643 }
644
645 add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) );
646 add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) );
647 }
648
649 public function autoptimize_admin_scripts()
650 {
651 wp_enqueue_script( 'jqcookie', plugins_url( '/external/js/jquery.cookie.min.js', __FILE__ ), array( 'jquery' ), null, true );
652 wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true );
653 }
654
655 public function autoptimize_admin_styles()
656 {
657 wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) );
658 wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) );
659 }
660
661 public function registersettings() {
662 register_setting( 'autoptimize', 'autoptimize_html' );
663 register_setting( 'autoptimize', 'autoptimize_html_keepcomments' );
664 register_setting( 'autoptimize', 'autoptimize_enable_site_config' );
665 register_setting( 'autoptimize', 'autoptimize_js' );
666 register_setting( 'autoptimize', 'autoptimize_js_aggregate' );
667 register_setting( 'autoptimize', 'autoptimize_js_exclude' );
668 register_setting( 'autoptimize', 'autoptimize_js_trycatch' );
669 register_setting( 'autoptimize', 'autoptimize_js_justhead' );
670 register_setting( 'autoptimize', 'autoptimize_js_forcehead' );
671 register_setting( 'autoptimize', 'autoptimize_js_include_inline' );
672 register_setting( 'autoptimize', 'autoptimize_css' );
673 register_setting( 'autoptimize', 'autoptimize_css_aggregate' );
674 register_setting( 'autoptimize', 'autoptimize_css_exclude' );
675 register_setting( 'autoptimize', 'autoptimize_css_justhead' );
676 register_setting( 'autoptimize', 'autoptimize_css_datauris' );
677 register_setting( 'autoptimize', 'autoptimize_css_defer' );
678 register_setting( 'autoptimize', 'autoptimize_css_defer_inline' );
679 register_setting( 'autoptimize', 'autoptimize_css_inline' );
680 register_setting( 'autoptimize', 'autoptimize_css_include_inline' );
681 register_setting( 'autoptimize', 'autoptimize_cdn_url' );
682 register_setting( 'autoptimize', 'autoptimize_cache_clean' );
683 register_setting( 'autoptimize', 'autoptimize_cache_nogzip' );
684 register_setting( 'autoptimize', 'autoptimize_optimize_logged' );
685 register_setting( 'autoptimize', 'autoptimize_optimize_checkout' );
686 register_setting( 'autoptimize', 'autoptimize_minify_excluded' );
687 register_setting( 'autoptimize', 'autoptimize_cache_fallback' );
688 }
689
690 public function setmeta( $links, $file = null )
691 {
692 // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/.
693 // Do it only once - saves time.
694 static $plugin;
695 if ( empty( $plugin ) ) {
696 $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' );
697 }
698
699 if ( null === $file ) {
700 // 2.7 and lower.
701 $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) );
702 array_unshift( $links, $settings_link );
703 } else {
704 // 2.8 and higher.
705 // If it's us, add the link.
706 if ( $file === $plugin ) {
707 $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) );
708 $links = array_merge( $links, $newlink );
709 }
710 }
711
712 return $links;
713 }
714
715 /**
716 * Provides the default options.
717 *
718 * @return array
719 */
720 public static function get_defaults()
721 {
722 static $config = array(
723 'autoptimize_html' => 0,
724 'autoptimize_html_keepcomments' => 0,
725 'autoptimize_enable_site_config' => 1,
726 'autoptimize_js' => 0,
727 'autoptimize_js_aggregate' => 1,
728 'autoptimize_js_exclude' => 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.js',
729 'autoptimize_js_trycatch' => 0,
730 'autoptimize_js_justhead' => 0,
731 'autoptimize_js_include_inline' => 0,
732 'autoptimize_js_forcehead' => 0,
733 'autoptimize_css' => 0,
734 'autoptimize_css_aggregate' => 1,
735 'autoptimize_css_exclude' => 'admin-bar.min.css, dashicons.min.css, wp-content/cache/, wp-content/uploads/',
736 'autoptimize_css_justhead' => 0,
737 'autoptimize_css_include_inline' => 1,
738 'autoptimize_css_defer' => 0,
739 'autoptimize_css_defer_inline' => '',
740 'autoptimize_css_inline' => 0,
741 'autoptimize_css_datauris' => 0,
742 'autoptimize_cdn_url' => '',
743 'autoptimize_cache_nogzip' => 1,
744 'autoptimize_optimize_logged' => 1,
745 'autoptimize_optimize_checkout' => 0,
746 'autoptimize_minify_excluded' => 1,
747 'autoptimize_cache_fallback' => 1,
748 );
749
750 return $config;
751 }
752
753 /**
754 * Returns default option values for autoptimizeExtra.
755 *
756 * @return array
757 */
758 public static function get_ao_extra_default_options()
759 {
760 $defaults = array(
761 'autoptimize_extra_checkbox_field_1' => '0',
762 'autoptimize_extra_checkbox_field_0' => '0',
763 'autoptimize_extra_radio_field_4' => '1',
764 'autoptimize_extra_text_field_2' => '',
765 'autoptimize_extra_text_field_3' => '',
766 'autoptimize_extra_text_field_7' => '',
767 );
768
769 return $defaults;
770 }
771
772 /**
773 * Returns default option values for autoptimizeExtra.
774 *
775 * @return array
776 */
777 public static function get_ao_imgopt_default_options()
778 {
779 $defaults = array(
780 'autoptimize_imgopt_checkbox_field_1' => '0', // imgopt off.
781 'autoptimize_imgopt_select_field_2' => '2', // quality glossy.
782 'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off.
783 'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed).
784 'autoptimize_imgopt_text_field_5' => '', // lazy load exclusions empty.
785 );
786 return $defaults;
787 }
788
789 /**
790 * Returns preload JS onload handler.
791 *
792 * @param string $media media attribute value the JS to use.
793 *
794 * @return string
795 */
796 public static function get_ao_css_preload_onload( $media = 'all' )
797 {
798 $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" );
799 return $preload_onload;
800 }
801
802 public function get( $key )
803 {
804 if ( ! is_array( $this->config ) ) {
805 // Default config.
806 $config = self::get_defaults();
807
808 // Override with user settings.
809 foreach ( array_keys( $config ) as $name ) {
810 $conf = autoptimizeOptionWrapper::get_option( $name );
811 if ( false !== $conf ) {
812 // It was set before!
813 $config[ $name ] = $conf;
814 }
815 }
816
817 // Save for next call.
818 $this->config = apply_filters( 'autoptimize_filter_get_config', $config );
819 }
820
821 if ( isset( $this->config[ $key ] ) ) {
822 return $this->config[ $key ];
823 }
824
825 return false;
826 }
827
828 private function get_futtta_feeds( $url ) {
829 if ( $this->settings_screen_do_remote_http ) {
830 $rss = fetch_feed( $url );
831 $maxitems = 0;
832
833 if ( ! is_wp_error( $rss ) ) {
834 $maxitems = $rss->get_item_quantity( 7 );
835 $rss_items = $rss->get_items( 0, $maxitems );
836 }
837 ?>
838 <ul>
839 <?php if ( 0 == $maxitems ) : ?>
840 <li><?php _e( 'No items', 'autoptimize' ); ?></li>
841 <?php else : ?>
842 <?php foreach ( $rss_items as $item ) : ?>
843 <li>
844 <a href="<?php echo esc_url( $item->get_permalink() ); ?>"
845 <?php // translators: the variable contains a date. ?>
846 title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>">
847 <?php echo esc_html( $item->get_title() ); ?>
848 </a>
849 </li>
850 <?php endforeach; ?>
851 <?php endif; ?>
852 </ul>
853 <?php
854 }
855 }
856
857 static function ao_admin_tabs()
858 {
859 // based on http://wordpress.stackexchange.com/a/58826 .
860 $tabs = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS &amp; HTML', 'autoptimize' ) ) );
861 $tab_content = '';
862 $tabs_count = count( $tabs );
863 if ( $tabs_count > 1 ) {
864 if ( isset( $_GET['page'] ) ) {
865 $current_id = $_GET['page'];
866 } else {
867 $current_id = 'autoptimize';
868 }
869 $tab_content .= '<h2 class="nav-tab-wrapper">';
870 foreach ( $tabs as $tab_id => $tab_name ) {
871 if ( $current_id == $tab_id ) {
872 $class = ' nav-tab-active';
873 } else {
874 $class = '';
875 }
876 $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>';
877 }
878 $tab_content .= '</h2>';
879 } else {
880 $tab_content = '<hr/>';
881 }
882
883 return $tab_content;
884 }
885
886 /**
887 * Returns true if in admin (and not in admin-ajax.php!)
888 *
889 * @return bool
890 */
891 public static function is_admin_and_not_ajax()
892 {
893 return ( is_admin() && ! self::doing_ajax() );
894 }
895
896 /**
897 * Returns true if doing ajax.
898 *
899 * @return bool
900 */
901 protected static function doing_ajax()
902 {
903 if ( function_exists( 'wp_doing_ajax' ) ) {
904 return wp_doing_ajax();
905 }
906 return ( defined( 'DOING_AJAX' ) && DOING_AJAX );
907 }
908
909 /**
910 * Returns true menu or tab is to be shown.
911 *
912 * @return bool
913 */
914 public static function should_show_menu_tabs() {
915 if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) {
916 return true;
917 } else {
918 return false;
919 }
920 }
921 }
922