| @@ -1,84 +1,112 @@ | ||
| 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 | + $metaBox = 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 _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', __( '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 | + $conf = self::instance(); | |
| 104 | + ?> | |
| 48 | 105 | <style> |
| 49 | 106 | /* title and button */ |
| 50 | 107 | #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 | 108 | |
| 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 | 109 | /* form */ |
| 82 | 110 | .itemDetail { |
| 83 | 111 | background: #fff; |
| 84 | 112 | border: 1px solid #ccc; |
| @@ -87,14 +115,17 @@ | ||
| 87 | 115 | } |
| 88 | 116 | .itemTitle { |
| 89 | 117 | margin-top: 0; |
| 90 | 118 | } |
| 91 | -input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:100;} | |
| 119 | + | |
| 120 | +input[type=url]:invalid {color: red; border-color:red;} .form-table th{font-weight:normal;} | |
| 92 | 121 | #autoptimize_main .cb_label {display: block; padding-left: 25px; text-indent: -25px;} |
| 122 | +#autoptimize_main .form-table th {padding-top: 15px; padding-bottom: 15px;} | |
| 123 | +#autoptimize_main .js_aggregate td, #autoptimize_main .js_aggregate th, #autoptimize_main .js_not_aggregate td, #autoptimize_main .js_not_aggregate th{padding-top:0px;} | |
| 93 | 124 | |
| 94 | 125 | /* rss block */ |
| 95 | 126 | #futtta_feed ul{list-style:outside;} |
| 96 | -#futtta_feed {font-size:medium; margin:0px 20px;} | |
| 127 | +#futtta_feed {font-size:medium; margin:0px 20px;} | |
| 97 | 128 | |
| 98 | 129 | /* banner + unslider */ |
| 99 | 130 | .autoptimize_banner { |
| 100 | 131 | margin: 0 38px; |
| @@ -137,8 +168,9 @@ | ||
| 137 | 168 | } |
| 138 | 169 | .unslider-arrow.next::before { |
| 139 | 170 | content: "\f345"; |
| 140 | 171 | } |
| 172 | + | |
| 141 | 173 | /* responsive stuff: hide admin-feed on smaller screens */ |
| 142 | 174 | @media (min-width: 961px) { |
| 143 | 175 | #autoptimize_main {float:left;width:69%;} |
| 144 | 176 | #autoptimize_admin_feed{float:right;width:30%;display:block !important;} |
| @@ -147,11 +179,8 @@ | ||
| 147 | 179 | #autoptimize_main {width:100%;} |
| 148 | 180 | #autoptimize_admin_feed {width:0%;display:none !important;} |
| 149 | 181 | } |
| 150 | 182 | @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 | 183 | #autoptimize_main input[type="checkbox"] {margin-left: 10px;} |
| 155 | 184 | #autoptimize_main .cb_label {display: block; padding-left: 45px; text-indent: -45px;} |
| 156 | 185 | } |
| 157 | 186 | </style> |
| @@ -157,316 +186,355 @@ | ||
| 157 | 186 | </style> |
| 158 | 187 | |
| 159 | 188 | <div class="wrap"> |
| 160 | 189 | |
| 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> (5.2.x or older) which has <a href=%s>serious security and performance issues</a>. Support for PHP 5.5 and below will be removed in one of the next AO released, please ask your hoster to provide you with an upgrade path to 7.x.','autoptimize'), '"http://blog.futtta.be/2016/03/15/why-would-you-still-be-on-php-5-2/" target="_blank"') . '</p>'; ?></div> | |
| 190 | +<!-- Temporary nudge to disable aoccss power-up. --> | |
| 191 | +<?php if ( autoptimizeUtils::is_plugin_active( 'autoptimize-criticalcss/ao_criticss_aas.php' ) ) { ?> | |
| 192 | + <div class="notice-info notice"><p> | |
| 193 | + <?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' ); ?> | |
| 194 | + </p></div> | |
| 163 | 195 | <?php } ?> |
| 164 | 196 | |
| 165 | 197 | <div id="autoptimize_main"> |
| 166 | -<div id="ao_title_and_button"> | |
| 167 | - <h1 id="ao_title"><?php _e('Autoptimize Settings','autoptimize'); ?> | |
| 168 | - <span id="ao_adv_button"> | |
| 169 | - <?php | |
| 170 | - if (get_option('autoptimize_show_adv','0')=='1') { | |
| 171 | - ?> | |
| 172 | - <a href="javascript:void(0);" id="ao_show_adv" class="button" style="display:none;"><span><?php _e("Show advanced settings","autoptimize") ?></span></a> | |
| 173 | - <a href="javascript:void(0);" id="ao_hide_adv" class="button"><span><?php _e("Hide advanced settings","autoptimize") ?></span></a> | |
| 174 | - <style>tr.ao_adv{display:table-row;} li.ao_adv{display:list-item;}</style> | |
| 175 | - <?php | |
| 176 | - $hiddenClass=""; | |
| 177 | - } else { | |
| 178 | - ?> | |
| 179 | - <a href="javascript:void(0);" id="ao_show_adv" class="button"><span><?php _e("Show advanced settings","autoptimize") ?></span></a> | |
| 180 | - <a href="javascript:void(0);" id="ao_hide_adv" class="button" style="display:none;"><span><?php _e("Hide advanced settings","autoptimize") ?></span></a> | |
| 181 | - <?php | |
| 182 | - $hiddenClass="hidden "; | |
| 183 | - } | |
| 184 | - ?> | |
| 185 | - </span> | |
| 186 | - </h1> | |
| 187 | -</div> | |
| 198 | + <h1 id="ao_title"><?php apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? _e( 'Autoptimize Pro Settings', 'autoptimize' ) : _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> | |
| 199 | + <?php echo $this->ao_admin_tabs(); ?> | |
| 188 | 200 | |
| 189 | -<?php echo $this->ao_admin_tabs(); ?> | |
| 201 | +<form method="post" action="<?php echo admin_url( 'options.php' ); ?>"> | |
| 202 | +<?php settings_fields( 'autoptimize' ); ?> | |
| 190 | 203 | |
| 191 | -<form method="post" action="options.php"> | |
| 192 | -<?php settings_fields('autoptimize'); ?> | |
| 204 | +<ul> | |
| 193 | 205 | |
| 194 | -<ul> | |
| 206 | +<?php | |
| 207 | +// Only show enable site configuration in network site option. | |
| 208 | +if ( is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { | |
| 209 | +?> | |
| 210 | + <li class="itemDetail multiSite"> | |
| 211 | + <h2 class="itemTitle"><?php _e( 'Multisite Options', 'autoptimize' ); ?></h2> | |
| 212 | + <table class="form-table"> | |
| 213 | + <tr valign="top"> | |
| 214 | + <th scope="row"><?php _e( 'Enable site configuration?', 'autoptimize' ); ?></th> | |
| 215 | + <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" ' : ''; ?>/> | |
| 216 | + <?php _e( 'Enable Autoptimize configuration per site.', 'autoptimize' ); ?></label></td> | |
| 217 | + </tr> | |
| 218 | + </table> | |
| 219 | + </li> | |
| 220 | +<?php } else { ?> | |
| 221 | + <input type="hidden" id="autoptimize_enable_site_config" name="autoptimize_enable_site_config" value="on" /> | |
| 222 | +<?php } ?> | |
| 195 | 223 | |
| 196 | 224 | <li class="itemDetail"> |
| 197 | -<h2 class="itemTitle"><?php _e('HTML Options','autoptimize'); ?></h2> | |
| 225 | +<h2 class="itemTitle"><?php _e( 'JavaScript Options', 'autoptimize' ); ?></h2> | |
| 198 | 226 | <table class="form-table"> |
| 199 | 227 | <tr valign="top"> |
| 200 | -<th scope="row"><?php _e('Optimize HTML Code?','autoptimize'); ?></th> | |
| 201 | -<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo get_option('autoptimize_html')?'checked="checked" ':''; ?>/></td> | |
| 228 | +<th scope="row"><?php _e( 'Optimize JavaScript Code?', 'autoptimize' ); ?></th> | |
| 229 | +<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo $conf->get( 'autoptimize_js' ) ? 'checked="checked" ' : ''; ?>/></td> | |
| 202 | 230 | </tr> |
| 203 | -<tr class="<?php echo $hiddenClass;?>html_sub ao_adv" valign="top"> | |
| 204 | -<th scope="row"><?php _e('Keep HTML comments?','autoptimize'); ?></th> | |
| 205 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo get_option('autoptimize_html_keepcomments')?'checked="checked" ':''; ?>/> | |
| 206 | -<?php _e('Enable this if you want HTML comments to remain in the page.','autoptimize'); ?></label></td> | |
| 231 | +<tr valign="top" class="js_sub js_aggregate_master"> | |
| 232 | +<th scope="row"><?php _e( 'Aggregate JS-files?', 'autoptimize' ); ?></th> | |
| 233 | +<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_aggregate" name="autoptimize_js_aggregate" <?php echo $conf->get( 'autoptimize_js_aggregate' ) ? 'checked="checked" ' : ''; ?>/> | |
| 234 | +<?php _e( 'Aggregate all linked JS-files to have them loaded non-render blocking?', 'autoptimize' ); ?></label></td> | |
| 207 | 235 | </tr> |
| 208 | -</table> | |
| 209 | -</li> | |
| 210 | - | |
| 211 | -<li class="itemDetail"> | |
| 212 | -<h2 class="itemTitle"><?php _e('JavaScript Options','autoptimize'); ?></h2> | |
| 213 | -<table class="form-table"> | |
| 214 | -<tr valign="top"> | |
| 215 | -<th scope="row"><?php _e('Optimize JavaScript Code?','autoptimize'); ?></th> | |
| 216 | -<td><input type="checkbox" id="autoptimize_js" name="autoptimize_js" <?php echo get_option('autoptimize_js')?'checked="checked" ':''; ?>/></td> | |
| 236 | +<tr valign="top" class="js_sub js_aggregate hidden"> | |
| 237 | +<th scope="row"> <?php _e( 'Also aggregate inline JS?', 'autoptimize' ); ?></th> | |
| 238 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_include_inline" <?php echo $conf->get( 'autoptimize_js_include_inline' ) ? 'checked="checked" ' : ''; ?>/> | |
| 239 | +<?php _e( 'Let Autoptimize also extract JS from the HTML (discouraged as it can make Autoptimize\'s cache size grow quickly)', 'autoptimize' ); ?></label></td> | |
| 217 | 240 | </tr> |
| 218 | -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv"> | |
| 219 | -<th scope="row"><?php _e('Force JavaScript in <head>?','autoptimize'); ?></th> | |
| 220 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo get_option('autoptimize_js_forcehead')?'checked="checked" ':''; ?>/> | |
| 221 | -<?php _e('Load JavaScript early, this can potentially fix some JS-errors, but makes the JS render blocking.','autoptimize'); ?></label></td> | |
| 241 | +<tr valign="top" class="js_sub js_aggregate hidden"> | |
| 242 | +<th scope="row"> <?php _e( 'Force JavaScript in <head>?', 'autoptimize' ); ?></th> | |
| 243 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_forcehead" <?php echo $conf->get( 'autoptimize_js_forcehead' ) ? 'checked="checked" ' : ''; ?>/> | |
| 244 | +<?php _e( 'Load JavaScript early (discouraged as it makes the JS render blocking)', 'autoptimize' ); ?></label></td> | |
| 222 | 245 | </tr> |
| 223 | -<?php if (get_option('autoptimize_js_justhead')) { ?> | |
| 224 | -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv"> | |
| 225 | -<th scope="row"><?php _e('Look for scripts only in <head>?','autoptimize'); echo ' <i>'. __('(deprecated)','autoptimize') . '</i>'; ?></th> | |
| 226 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo get_option('autoptimize_js_justhead')?'checked="checked" ':''; ?>/> | |
| 227 | -<?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> | |
| 246 | +<tr valign="top" class="js_sub js_aggregate hidden"> | |
| 247 | +<th scope="row"> <?php _e( 'Add try-catch wrapping?', 'autoptimize' ); ?></th> | |
| 248 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo $conf->get( 'autoptimize_js_trycatch' ) ? 'checked="checked" ' : ''; ?>/> | |
| 249 | +<?php _e( 'If your aggregated scripts break because of a JS-error, you might want to try this, but generally discouraged.', 'autoptimize' ); ?></label></td> | |
| 228 | 250 | </tr> |
| 251 | +<tr valign="top" class="js_sub js_not_aggregate_master"> | |
| 252 | +<th scope="row"><?php _e( 'Do not aggregate but defer?', 'autoptimize' ); ?></th> | |
| 253 | +<td><label class="cb_label"><input type="checkbox" id="autoptimize_js_defer_not_aggregate" name="autoptimize_js_defer_not_aggregate" <?php echo $conf->get( 'autoptimize_js_defer_not_aggregate' ) ? 'checked="checked" ' : ''; ?>/> | |
| 254 | +<?php _e( 'Individual JS-files will be minified and deferred, making them non-render-blocking.', 'autoptimize' ); ?></label></td> | |
| 255 | +</tr> | |
| 256 | +<tr valign="top" id="js_defer_inline" class="js_sub js_not_aggregate hidden"> | |
| 257 | +<th scope="row"> <?php _e( 'Also defer inline JS?', 'autoptimize' ); ?></th> | |
| 258 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_defer_inline" <?php echo $conf->get( 'autoptimize_js_defer_inline' ) ? 'checked="checked" ' : ''; ?>/> | |
| 259 | +<?php _e( 'Also defer inline JS. Generally this will allow all JS to be deferred, so you should remove default exclusions, test and only exclude specific items if still needed.', 'autoptimize' ); ?></label></td> | |
| 260 | +</tr> | |
| 261 | +<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_js_justhead' ) ) { ?> | |
| 262 | +<tr valign="top" class="js_sub js_aggregate"> | |
| 263 | +<th scope="row"> | |
| 264 | +<?php | |
| 265 | + _e( 'Look for scripts only in <head>?', 'autoptimize' ); | |
| 266 | + echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>'; | |
| 267 | +?> | |
| 268 | +</th> | |
| 269 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_justhead" <?php echo $conf->get( 'autoptimize_js_justhead' ) ? 'checked="checked" ' : ''; ?>/> | |
| 270 | +<?php _e( 'Mostly useful in combination with previous option when using jQuery-based templates, but might help keeping cache size under control.', 'autoptimize' ); ?></label></td> | |
| 271 | +</tr> | |
| 229 | 272 | <?php } ?> |
| 230 | -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv"> | |
| 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 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> | |
| 273 | +<tr valign="top" class="js_sub"> | |
| 274 | +<th scope="row"><?php _e( 'Exclude scripts from Autoptimize:', 'autoptimize' ); ?></th> | |
| 275 | +<td><label><input type="text" style="width:100%;" name="autoptimize_js_exclude" value="<?php echo esc_attr( autoptimizeOptionWrapper::get_option( 'autoptimize_js_exclude', '' ) ); ?>"/><br /> | |
| 276 | +<?php | |
| 277 | +echo __( 'A comma-separated list of scripts you do not want optimized, for example \'whatever.js, my_var\' (without the quotes).', 'autoptimize' ) . ' ' . __( 'Important: when "aggregate JS-files" is on, excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' ); | |
| 278 | +?> | |
| 279 | +</label></td> | |
| 234 | 280 | </tr> |
| 235 | -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv"> | |
| 236 | -<th scope="row"><?php _e('Exclude scripts from Autoptimize:','autoptimize'); ?></th> | |
| 237 | -<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 /> | |
| 238 | -<?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> | |
| 281 | +<tr valign="top"> | |
| 282 | +<th scope="row"><?php _e( 'Remove Unused JavaScript?', 'autoptimize' ); ?></th> | |
| 283 | +<td><?php _e( 'Autoptimize combines your theme & plugins\' JavaScript, but does not know what is used and what not. If Google Pagespeed Insights detects unused JavaScript, consider using a plugin like "Plugin Organizer" or similar to manage what JavaScript is added where.', 'autoptimize' ); ?></td> | |
| 239 | 284 | </tr> |
| 240 | -<tr valign="top" class="<?php echo $hiddenClass;?>js_sub ao_adv"> | |
| 241 | -<th scope="row"><?php _e('Add try-catch wrapping?','autoptimize'); ?></th> | |
| 242 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_js_trycatch" <?php echo get_option('autoptimize_js_trycatch')?'checked="checked" ':''; ?>/> | |
| 243 | -<?php _e('If your scripts break because of a JS-error, you might want to try this.','autoptimize'); ?></label></td> | |
| 244 | -</tr> | |
| 245 | 285 | </table> |
| 246 | 286 | </li> |
| 247 | 287 | |
| 248 | 288 | <li class="itemDetail"> |
| 249 | -<h2 class="itemTitle"><?php _e('CSS Options','autoptimize'); ?></h2> | |
| 250 | -<table class="form-table"> | |
| 289 | +<h2 class="itemTitle"><?php _e( 'CSS Options', 'autoptimize' ); ?></h2> | |
| 290 | +<table class="form-table"> | |
| 251 | 291 | <tr valign="top"> |
| 252 | -<th scope="row"><?php _e('Optimize CSS Code?','autoptimize'); ?></th> | |
| 253 | -<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo get_option('autoptimize_css')?'checked="checked" ':''; ?>/></td> | |
| 292 | +<th scope="row"><?php _e( 'Optimize CSS Code?', 'autoptimize' ); ?></th> | |
| 293 | +<td><input type="checkbox" id="autoptimize_css" name="autoptimize_css" <?php echo $conf->get( 'autoptimize_css' ) ? 'checked="checked" ' : ''; ?>/></td> | |
| 254 | 294 | </tr> |
| 255 | -<tr class="<?php echo $hiddenClass;?>css_sub ao_adv" valign="top"> | |
| 256 | -<th scope="row"><?php _e('Generate data: URIs for images?','autoptimize'); ?></th> | |
| 257 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo get_option('autoptimize_css_datauris')?'checked="checked" ':''; ?>/> | |
| 258 | -<?php _e('Enable this to include small background-images in the CSS itself instead of as separate downloads.','autoptimize'); ?></label></td> | |
| 295 | +<tr class="css_sub" valign="top"> | |
| 296 | +<th scope="row"><?php _e( 'Aggregate CSS-files?', 'autoptimize' ); ?></th> | |
| 297 | +<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_aggregate" name="autoptimize_css_aggregate" <?php echo $conf->get( 'autoptimize_css_aggregate' ) ? 'checked="checked" ' : ''; ?>/> | |
| 298 | +<?php _e( 'Aggregate all linked CSS-files? If this option is off, the individual CSS-files will remain in place but will be minified.', 'autoptimize' ); ?></label></td> | |
| 259 | 299 | </tr> |
| 260 | -<tr class="<?php echo $hiddenClass;?>css_sub ao_adv" valign="top"> | |
| 261 | -<th scope="row"><?php _e('Remove Google Fonts?','autoptimize'); ?></th> | |
| 262 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_nogooglefont" <?php echo get_option('autoptimize_css_nogooglefont')?'checked="checked" ':''; ?>/> | |
| 263 | -<?php _e('Check this if you don\'t need or want Google Fonts being loaded.','autoptimize'); ?></label></td> | |
| 300 | +<tr valign="top" class="css_sub css_aggregate"> | |
| 301 | +<th scope="row"><?php _e( 'Also aggregate inline CSS?', 'autoptimize' ); ?></th> | |
| 302 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo $conf->get( 'autoptimize_css_include_inline', '1' ) ? 'checked="checked" ' : ''; ?>/> | |
| 303 | +<?php _e( 'Check this option for Autoptimize to also aggregate CSS in the HTML.', 'autoptimize' ); ?></label></td> | |
| 264 | 304 | </tr> |
| 265 | -<?php if (get_option('autoptimize_css_justhead')) { ?> | |
| 266 | -<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv"> | |
| 267 | -<th scope="row"><?php _e('Look for styles only in <head>?','autoptimize'); echo ' <i>'. __('(deprecated)','autoptimize') . '</i>'; ?></th> | |
| 268 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo get_option('autoptimize_css_justhead')?'checked="checked" ':''; ?>/> | |
| 269 | -<?php _e('Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.','autoptimize'); ?></label></td> | |
| 305 | +<tr class="css_sub css_aggregate" valign="top"> | |
| 306 | +<th scope="row"><?php _e( 'Generate data: URIs for images?', 'autoptimize' ); ?></th> | |
| 307 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_datauris" <?php echo $conf->get( 'autoptimize_css_datauris' ) ? 'checked="checked" ' : ''; ?>/> | |
| 308 | +<?php _e( 'Enable this to include small background-images in the CSS itself instead of as separate downloads.', 'autoptimize' ); ?></label></td> | |
| 270 | 309 | </tr> |
| 310 | +<?php if ( autoptimizeOptionWrapper::get_option( 'autoptimize_css_justhead' ) ) { ?> | |
| 311 | +<tr valign="top" class="css_sub css_aggregate"> | |
| 312 | +<th scope="row"> | |
| 313 | +<?php | |
| 314 | +_e( 'Look for styles only in <head>?', 'autoptimize' ); | |
| 315 | +echo ' <i>' . __( '(deprecated)', 'autoptimize' ) . '</i>'; | |
| 316 | +?> | |
| 317 | +</th> | |
| 318 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_justhead" <?php echo $conf->get( 'autoptimize_css_justhead' ) ? 'checked="checked" ' : ''; ?>/> | |
| 319 | +<?php _e( 'Don\'t autoptimize CSS outside the head-section. If the cache gets big, you might want to enable this.', 'autoptimize' ); ?></label></td> | |
| 320 | +</tr> | |
| 271 | 321 | <?php } ?> |
| 272 | -<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv"> | |
| 273 | -<th scope="row"><?php _e('Also aggregate inline CSS?','autoptimize'); ?></th> | |
| 274 | -<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_include_inline" <?php echo get_option('autoptimize_css_include_inline','1')?'checked="checked" ':''; ?>/> | |
| 275 | -<?php _e('Check this option for Autoptimize to also aggregate CSS in the HTML.','autoptimize'); ?></label></td> | |
| 322 | +<tr valign="top" class="css_sub"> | |
| 323 | +<th scope="row"><?php _e( 'Eliminate render-blocking CSS?', 'autoptimize' ); ?></th> | |
| 324 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_css_defer" id="autoptimize_css_defer" <?php echo $conf->get( 'autoptimize_css_defer' ) ? 'checked="checked" ' : ''; ?>/> | |
| 325 | +<?php | |
| 326 | +_e( 'Inline "above the fold CSS" while loading the main autoptimized CSS only after page load. <a href="https://wordpress.org/plugins/autoptimize/faq/" target="_blank">Check the FAQ</a> for more info.', 'autoptimize' ); | |
| 327 | +echo ' '; | |
| 328 | +$critcss_settings_url = get_admin_url( null, 'options-general.php?page=ao_critcss' ); | |
| 329 | +// translators: links "autoptimize critical CSS" tab. | |
| 330 | +echo sprintf( __( 'You can manually create rules for different types of pages or have this done fully automated on the %s tab.', 'autoptimize' ), '<a href="' . $critcss_settings_url . '">CriticalCSS</a>' ); | |
| 331 | +?> | |
| 332 | +</label></td> | |
| 276 | 333 | </tr> |
| 277 | -<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv"> | |
| 278 | -<th scope="row"><?php _e('Inline and Defer CSS?','autoptimize'); ?></th> | |
| 279 | -<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" ':''; ?>/> | |
| 280 | -<?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> | |
| 334 | +<tr valign="top" class="css_sub" id="autoptimize_css_defer_inline"> | |
| 335 | +<th scope="row"></th> | |
| 336 | +<td><label><textarea rows="10" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste the above the fold CSS here. You can leave this empty when using the automated Critical CSS integration.', 'autoptimize' ); ?>" name="autoptimize_css_defer_inline"><?php echo autoptimizeStyles::sanitize_css( autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' ) ); ?></textarea></label></td> | |
| 281 | 337 | </tr> |
| 282 | -<tr valign="top" class="<?php echo $hiddenClass;?>css_sub ao_adv" id="autoptimize_css_defer_inline"> | |
| 283 | -<th scope="row"></th> | |
| 284 | -<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> | |
| 338 | +<tr valign="top" class="css_sub css_aggregate"> | |
| 339 | +<th scope="row"><?php _e( 'Inline all CSS?', 'autoptimize' ); ?></th> | |
| 340 | +<td><label class="cb_label"><input type="checkbox" id="autoptimize_css_inline" name="autoptimize_css_inline" <?php echo $conf->get( 'autoptimize_css_inline' ) ? 'checked="checked" ' : ''; ?>/> | |
| 341 | +<?php _e( 'Inlining all CSS is an easy way to stop the CSS from being render-blocking, but is generally not recommended because the size of the HTML increases significantly. Additionally it might push meta-tags down to a position where e.g. Facebook and Whatsapp will not find them any more, breaking thumbnails when sharing.', 'autoptimize' ); ?></label></td> | |
| 285 | 342 | </tr> |
| 286 | -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv css_sub"> | |
| 287 | -<th scope="row"><?php _e('Inline all CSS?','autoptimize'); ?></th> | |
| 288 | -<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" ':''; ?>/> | |
| 289 | -<?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> | |
| 343 | +<tr valign="top" class="css_sub"> | |
| 344 | +<th scope="row"><?php _e( 'Exclude CSS from Autoptimize:', 'autoptimize' ); ?></th> | |
| 345 | +<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo esc_attr( $conf->get( 'autoptimize_css_exclude', '' ) ); ?>"/><br /> | |
| 346 | +<?php | |
| 347 | +echo __( 'A comma-separated list of CSS you want to exclude from being optimized.', 'autoptimize' ) . ' ' . __( 'Important: excluded non-minified files are still minified by Autoptimize unless that option under "misc" is disabled.', 'autoptimize' ); | |
| 348 | +?> | |
| 349 | +</label></td> | |
| 290 | 350 | </tr> |
| 291 | -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv css_sub"> | |
| 292 | -<th scope="row"><?php _e('Exclude CSS from Autoptimize:','autoptimize'); ?></th> | |
| 293 | -<td><label><input type="text" style="width:100%;" name="autoptimize_css_exclude" value="<?php echo get_option('autoptimize_css_exclude','admin-bar.min.css, dashicons.min.css'); ?>"/><br /> | |
| 294 | -<?php _e('A comma-separated list of CSS you want to exclude from being optimized.','autoptimize'); ?></label></td> | |
| 351 | +<?php if ( false === autoptimizeUtils::is_plugin_active( 'unusedcss/unusedcss.php' ) ) { ?> | |
| 352 | +<tr valign="top"> | |
| 353 | +<th scope="row"><?php _e( 'Remove Unused CSS?', 'autoptimize' ); ?></th> | |
| 354 | +<?php | |
| 355 | +$_rapidload_link = 'https://misc.optimizingmatters.com/partners/?from=csssettings&partner=rapidload'; | |
| 356 | +?> | |
| 357 | +<td><?php echo sprintf( __( 'If Google Pagespeed Insights detects unused CSS, consider using %s to <strong>reduce your site\'s CSS size to up to 90%</strong>, resulting in a slimmer, faster site!', 'autoptimize' ), '<a href="' . $_rapidload_link . '" target="_blank">the premium Rapidload service</a>' ); ?></td> | |
| 295 | 358 | </tr> |
| 359 | +<?php } ?> | |
| 296 | 360 | </table> |
| 297 | 361 | </li> |
| 298 | 362 | |
| 299 | 363 | <li class="itemDetail"> |
| 300 | -<h2 class="itemTitle"><?php _e('CDN Options','autoptimize'); ?></h2> | |
| 301 | -<table class="form-table"> | |
| 364 | +<h2 class="itemTitle"><?php _e( 'HTML Options', 'autoptimize' ); ?></h2> | |
| 365 | +<table class="form-table"> | |
| 302 | 366 | <tr valign="top"> |
| 303 | -<th scope="row"><?php _e('CDN Base URL','autoptimize'); ?></th> | |
| 304 | -<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 /> | |
| 305 | -<?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> | |
| 367 | +<th scope="row"><?php _e( 'Optimize HTML Code?', 'autoptimize' ); ?></th> | |
| 368 | +<td><input type="checkbox" id="autoptimize_html" name="autoptimize_html" <?php echo $conf->get( 'autoptimize_html' ) ? 'checked="checked" ' : ''; ?>/></td> | |
| 306 | 369 | </tr> |
| 370 | +<tr class="html_sub" valign="top"> | |
| 371 | +<th scope="row"><?php _e( 'Keep HTML comments?', 'autoptimize' ); ?></th> | |
| 372 | +<td><label class="cb_label"><input type="checkbox" name="autoptimize_html_keepcomments" <?php echo $conf->get( 'autoptimize_html_keepcomments' ) ? 'checked="checked" ' : ''; ?>/> | |
| 373 | +<?php _e( 'Enable this if you want HTML comments to remain in the page.', 'autoptimize' ); ?></label></td> | |
| 374 | +</tr> | |
| 307 | 375 | </table> |
| 308 | 376 | </li> |
| 309 | 377 | |
| 310 | -<li class="<?php echo $hiddenClass;?>itemDetail ao_adv"> | |
| 311 | -<h2 class="itemTitle"><?php _e('Cache Info','autoptimize'); ?></h2> | |
| 312 | -<table class="form-table" > | |
| 313 | -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv"> | |
| 314 | -<th scope="row"><?php _e('Cache folder','autoptimize'); ?></th> | |
| 315 | -<td><?php echo htmlentities(AUTOPTIMIZE_CACHE_DIR); ?></td> | |
| 378 | +<li class="itemDetail"> | |
| 379 | +<h2 class="itemTitle"><?php _e( 'CDN Options', 'autoptimize' ); ?></h2> | |
| 380 | +<table class="form-table"> | |
| 381 | +<tr valign="top"> | |
| 382 | +<th scope="row"><?php _e( 'CDN Base URL', 'autoptimize' ); ?></th> | |
| 383 | +<?php | |
| 384 | +if ( true === autoptimizeImages::imgopt_active() && true === apply_filters( 'autoptimize_filter_cdn_set_by_imgopt', false ) ) { | |
| 385 | + // cdn set by imgopt, not to be changealbe in the settings. | |
| 386 | + $cdn_editable = 'disabled'; | |
| 387 | + $cdn_placeholder = 'placeholder="' . __( 'The CDN has automatically been set to make use of the image optimization CDN.', 'autoptimize' ) . ' "'; | |
| 388 | + $cdn_description = ''; | |
| 389 | +} else { | |
| 390 | + $cdn_editable = ''; | |
| 391 | + $cdn_placeholder = 'placeholder="' . __( 'example: //cdn.yoursite.com/', 'autoptimize' ) . ' "'; | |
| 392 | + $cdn_description = __( 'Enter your CDN root URL to enable CDN for Autoptimized files. The URL can be http, https or protocol-relative. This is not needed for Cloudflare.', 'autoptimize' ); | |
| 393 | +} | |
| 394 | +?> | |
| 395 | +<td><label><input id="cdn_url" type="text" name="autoptimize_cdn_url" pattern="^(https?:)?\/\/([\da-z\.-]+)\.([\da-z\.]{2,6})([\/\w \.-]*)*(:\d{2,5})?\/?$" style="width:100%" <?php echo $cdn_placeholder . $cdn_editable; ?> value="<?php echo esc_url( autoptimizeOptionWrapper::get_option( 'autoptimize_cdn_url', '' ), array( 'http', 'https' ) ); ?>" /><br /> | |
| 396 | +<?php echo $cdn_description; ?> | |
| 397 | +</label></td> | |
| 316 | 398 | </tr> |
| 317 | -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv"> | |
| 318 | -<th scope="row"><?php _e('Can we write?','autoptimize'); ?></th> | |
| 319 | -<td><?php echo (autoptimizeCache::cacheavail() ? __('Yes','autoptimize') : __('No','autoptimize')); ?></td> | |
| 399 | +</table> | |
| 400 | +</li> | |
| 401 | + | |
| 402 | +<li class="itemDetail"> | |
| 403 | +<h2 class="itemTitle"><?php _e( 'Cache Info', 'autoptimize' ); ?></h2> | |
| 404 | +<table class="form-table" > | |
| 405 | +<tr valign="top" > | |
| 406 | +<th scope="row"><?php _e( 'Cache folder', 'autoptimize' ); ?></th> | |
| 407 | +<td><?php echo htmlentities( AUTOPTIMIZE_CACHE_DIR ); ?></td> | |
| 320 | 408 | </tr> |
| 321 | -<tr valign="top" class="<?php echo $hiddenClass;?>ao_adv"> | |
| 322 | -<th scope="row"><?php _e('Cached styles and scripts','autoptimize'); ?></th> | |
| 323 | -<td><?php | |
| 324 | - $AOstatArr=autoptimizeCache::stats(); | |
| 325 | - $AOcacheSize=round($AOstatArr[1]/1024); | |
| 326 | - printf( __( '%1$s files, totalling %2$s Kbytes (calculated at %3$s)', 'autoptimize'), $AOstatArr[0], $AOcacheSize, date("H:i e", $AOstatArr[2]) ); | |
| 327 | -?></td> | |
| 409 | +<tr valign="top" > | |
| 410 | +<th scope="row"><?php _e( 'Can we write?', 'autoptimize' ); ?></th> | |
| 411 | +<td><?php echo ( autoptimizeCache::cacheavail() ? __( 'Yes', 'autoptimize' ) : __( 'No', 'autoptimize' ) ); ?></td> | |
| 328 | 412 | </tr> |
| 413 | +<tr valign="top" > | |
| 414 | +<th scope="row"><?php _e( 'Cached styles and scripts', 'autoptimize' ); ?></th> | |
| 415 | +<td> | |
| 416 | + <?php | |
| 417 | + $ao_stat_arr = autoptimizeCache::stats(); | |
| 418 | + if ( ! empty( $ao_stat_arr ) && is_array( $ao_stat_arr ) ) { | |
| 419 | + $ao_cache_size = size_format( $ao_stat_arr[1], 2 ); | |
| 420 | + $details = ''; | |
| 421 | + if ( $ao_cache_size > 0 ) { | |
| 422 | + $details = ', ~' . $ao_cache_size . ' total'; | |
| 423 | + } | |
| 424 | + // translators: Kilobytes + timestamp shown. | |
| 425 | + printf( __( '%1$s files, totalling %2$s (calculated at %3$s)', 'autoptimize' ), $ao_stat_arr[0], $ao_cache_size, date( 'H:i e', $ao_stat_arr[2] ) ); | |
| 426 | + } | |
| 427 | + ?> | |
| 428 | +</td> | |
| 429 | +</tr> | |
| 329 | 430 | </table> |
| 330 | 431 | </li> |
| 331 | 432 | |
| 332 | -<li class="<?php echo $hiddenClass;?>itemDetail ao_adv"> | |
| 333 | -<h2 class="itemTitle"><?php _e('Misc Options','autoptimize'); ?></h2> | |
| 334 | -<table class="form-table"> | |
| 335 | - <tr valign="top" class="<?php echo $hiddenClass;?>ao_adv"> | |
| 336 | - <th scope="row"><?php _e('Save aggregated script/css as static files?','autoptimize'); ?></th> | |
| 337 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo get_option('autoptimize_cache_nogzip','1')?'checked="checked" ':''; ?>/> | |
| 338 | - <?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> | |
| 339 | - </td> | |
| 340 | - </tr> | |
| 341 | - <tr valign="top" class="<?php echo $hiddenClass;?>ao_adv"> | |
| 342 | - <th scope="row"><?php _e('Also optimize for logged in users?','autoptimize'); ?></th> | |
| 343 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo get_option('autoptimize_optimize_logged','1')?'checked="checked" ':''; ?>/> | |
| 344 | - <?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> | |
| 345 | - </td> | |
| 346 | - </tr> | |
| 347 | - <?php | |
| 348 | - if ( function_exists("is_checkout") || function_exists("is_cart") || function_exists("edd_is_checkout") || function_exists("wpsc_is_cart") || function_exists("wpsc_is_checkout") ) { | |
| 349 | - ?> | |
| 350 | - <tr valign="top" class="<?php echo $hiddenClass;?>ao_adv"> | |
| 351 | - <th scope="row"><?php _e('Also optimize shop cart/ checkout?','autoptimize'); ?></th> | |
| 352 | - <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo get_option('autoptimize_optimize_checkout','1')?'checked="checked" ':''; ?>/> | |
| 353 | - <?php _e('By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.','autoptimize'); ?></label> | |
| 354 | - </td> | |
| 355 | - </tr> | |
| 356 | - <?php | |
| 357 | - } | |
| 358 | - ?> | |
| 433 | +<li class="itemDetail"> | |
| 434 | +<h2 class="itemTitle"><?php _e( 'Misc Options', 'autoptimize' ); ?></h2> | |
| 435 | +<table class="form-table"> | |
| 436 | + <tr valign="top" > | |
| 437 | + <th scope="row"><?php _e( 'Save aggregated script/css as static files?', 'autoptimize' ); ?></th> | |
| 438 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_nogzip" <?php echo $conf->get( 'autoptimize_cache_nogzip') ? 'checked="checked" ' : ''; ?>/> | |
| 439 | + <?php _e( 'By default files saved are static css/js, uncheck this option if your webserver doesn\'t properly handle the compression and expiry.', 'autoptimize' ); ?></label></td> | |
| 440 | + </tr> | |
| 441 | + <?php | |
| 442 | + $_min_excl_class = ''; | |
| 443 | + if ( ! $conf->get( 'autoptimize_css_aggregate' ) && ! $conf->get( 'autoptimize_js_aggregate' ) ) { | |
| 444 | + $_min_excl_class = 'hidden'; | |
| 445 | + } | |
| 446 | + ?> | |
| 447 | + <tr valign="top" id="min_excl_row" class="<?php echo $_min_excl_class; ?>"> | |
| 448 | + <th scope="row"><?php _e( 'Minify excluded CSS and JS files?', 'autoptimize' ); ?></th> | |
| 449 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_minify_excluded" <?php echo $conf->get( 'autoptimize_minify_excluded' ) ? 'checked="checked" ' : ''; ?>/> | |
| 450 | + <?php _e( 'When aggregating JS or CSS, excluded files that are not minified (based on filename) are by default minified by Autoptimize despite being excluded. Uncheck this option if anything breaks despite excluding.', 'autoptimize' ); ?></label></td> | |
| 451 | + </tr> | |
| 452 | + <tr valign="top"> | |
| 453 | + <th scope="row"><?php _e( 'Enable 404 fallbacks?', 'autoptimize' ); ?></th> | |
| 454 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_cache_fallback" <?php echo $conf->get( 'autoptimize_cache_fallback' ) ? 'checked="checked" ' : ''; ?>/> | |
| 455 | + <?php _e( 'Sometimes Autoptimized JS/ CSS is referenced in cached HTML but is already removed, resulting in broken sites. With this option on, Autoptimize will try to redirect those not-found files to "fallback"-versions, keeping the page/ site somewhat intact. In some cases this will require extra web-server level configuration to ensure <code>wp-content/autoptimize_404_handler.php</code> is set to handle 404\'s in <code>wp-content/cache/autoptimize</code>.', 'autoptimize' ); ?></label></td> | |
| 456 | + </tr> | |
| 457 | + <tr valign="top"> | |
| 458 | + <th scope="row"><?php _e( 'Also optimize for logged in editors/ administrators?', 'autoptimize' ); ?></th> | |
| 459 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_logged" <?php echo $conf->get( 'autoptimize_optimize_logged' ) ? 'checked="checked" ' : ''; ?>/> | |
| 460 | + <?php _e( 'By default Autoptimize is also active for logged on editors/ administrators, uncheck this option if you don\'t want Autoptimize to optimize when logged in e.g. to use a pagebuilder.', 'autoptimize' ); ?></label></td> | |
| 461 | + </tr> | |
| 462 | + <?php | |
| 463 | + if ( function_exists( 'is_checkout' ) || function_exists( 'is_cart' ) || function_exists( 'edd_is_checkout' ) || function_exists( 'wpsc_is_cart' ) || function_exists( 'wpsc_is_checkout' ) ) { | |
| 464 | + ?> | |
| 465 | + <tr valign="top" > | |
| 466 | + <th scope="row"><?php _e( 'Also optimize shop cart/ checkout?', 'autoptimize' ); ?></th> | |
| 467 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_optimize_checkout" <?php echo $conf->get( 'autoptimize_optimize_checkout' ) ? 'checked="checked" ' : ''; ?>/> | |
| 468 | + <?php _e( 'By default Autoptimize is also active on your shop\'s cart/ checkout, uncheck not to optimize those.', 'autoptimize' ); ?></label> | |
| 469 | + </td> | |
| 470 | + </tr> | |
| 471 | + <?php } ?> | |
| 472 | + <?php | |
| 473 | + if ( true === apply_filters( 'autoptimize_filter_enable_meta_ao_settings', true ) ) { | |
| 474 | + ?> | |
| 475 | + <tr valign="top"> | |
| 476 | + <th scope="row"><?php _e( 'Enable configuration per post/ page?', 'autoptimize' ); ?></th> | |
| 477 | + <td><label class="cb_label"><input type="checkbox" name="autoptimize_enable_meta_ao_settings" <?php echo $conf->get( 'autoptimize_enable_meta_ao_settings' ) ? 'checked="checked" ' : ''; ?>/> | |
| 478 | + <?php _e( 'Add a "metabox" to the post/ page edit screen allowing different optimizations to be turned off on a per post/ page level?', 'autoptimize' ); ?></label></td> | |
| 479 | + </tr> | |
| 480 | + <?php } ?> | |
| 359 | 481 | </table> |
| 360 | 482 | </li> |
| 361 | 483 | |
| 362 | 484 | </ul> |
| 363 | 485 | |
| 364 | -<input type="hidden" id="autoptimize_show_adv" name="autoptimize_show_adv" value="<?php echo get_option('autoptimize_show_adv','0'); ?>"> | |
| 365 | - | |
| 366 | 486 | <p class="submit"> |
| 367 | -<input type="submit" class="button-secondary" value="<?php _e('Save Changes','autoptimize') ?>" /> | |
| 368 | -<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e('Save Changes and Empty Cache','autoptimize') ?>" /> | |
| 487 | +<input type="submit" class="button-secondary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /> | |
| 488 | +<input type="submit" class="button-primary" name="autoptimize_cache_clean" value="<?php _e( 'Save Changes and Empty Cache', 'autoptimize' ); ?>" /> | |
| 369 | 489 | </p> |
| 370 | 490 | |
| 371 | 491 | </form> |
| 372 | 492 | </div> |
| 373 | -<div id="autoptimize_admin_feed" class="hidden"> | |
| 493 | +<div id="autoptimize_admin_feed"> | |
| 494 | + <?php if ( apply_filters( 'autoptimize_filter_show_partner_tabs', true ) ) { ?> | |
| 374 | 495 | <div class="autoptimize_banner hidden"> |
| 375 | - <ul> | |
| 376 | - <?php | |
| 377 | - if (apply_filters('autoptimize_settingsscreen_remotehttp',true)) { | |
| 378 | - $AO_banner=get_transient("autoptimize_banner"); | |
| 379 | - if (empty($AO_banner)) { | |
| 380 | - $banner_resp = wp_remote_get("http://misc.optimizingmatters.com/autoptimize_news.html"); | |
| 381 | - if (!is_wp_error($banner_resp)) { | |
| 382 | - if (wp_remote_retrieve_response_code($banner_resp)=="200") { | |
| 383 | - $AO_banner = wp_kses_post(wp_remote_retrieve_body($banner_resp)); | |
| 384 | - set_transient("autoptimize_banner",$AO_banner,DAY_IN_SECONDS); | |
| 385 | - } | |
| 496 | + <ul> | |
| 497 | + <?php | |
| 498 | + if ( $this->settings_screen_do_remote_http ) { | |
| 499 | + $ao_banner = get_transient( 'autoptimize_banner' ); | |
| 500 | + if ( empty( $ao_banner ) ) { | |
| 501 | + $banner_resp = wp_remote_get( 'https://misc.optimizingmatters.com/autoptimize_news.html?ao_ver=' . AUTOPTIMIZE_PLUGIN_VERSION ); | |
| 502 | + if ( ! is_wp_error( $banner_resp ) ) { | |
| 503 | + if ( '200' == wp_remote_retrieve_response_code( $banner_resp ) ) { | |
| 504 | + $ao_banner = wp_kses_post( wp_remote_retrieve_body( $banner_resp ) ); | |
| 505 | + set_transient( 'autoptimize_banner', $ao_banner, WEEK_IN_SECONDS ); | |
| 386 | 506 | } |
| 387 | 507 | } |
| 388 | - echo $AO_banner; | |
| 389 | 508 | } |
| 390 | - ?> | |
| 391 | - <li><?php _e("Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.","autoptimize"); ?></li> | |
| 392 | - <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> | |
| 393 | - </ul> | |
| 509 | + echo $ao_banner; | |
| 510 | + } | |
| 511 | + ?> | |
| 512 | + <li><?php _e( "Need help? <a href='https://wordpress.org/plugins/autoptimize/faq/'>Check out the FAQ here</a>.", 'autoptimize' ); ?></li> | |
| 513 | + <li><?php _e( 'Happy with Autoptimize?', 'autoptimize' ); ?><br /><a href="<?php echo network_admin_url(); ?>plugin-install.php?tab=search&type=author&s=optimizingmatters"><?php _e( 'Try my other plugins!', 'autoptimize' ); ?></a></li> | |
| 514 | + </ul> | |
| 394 | 515 | </div> |
| 516 | + <?php } ?> | |
| 395 | 517 | <div style="margin-left:10px;margin-top:-5px;"> |
| 396 | 518 | <h2> |
| 397 | - <?php _e("futtta about","autoptimize") ?> | |
| 398 | - <select id="feed_dropdown" > | |
| 399 | - <option value="1"><?php _e("Autoptimize","autoptimize") ?></option> | |
| 400 | - <option value="2"><?php _e("WordPress","autoptimize") ?></option> | |
| 401 | - <option value="3"><?php _e("Web Technology","autoptimize") ?></option> | |
| 402 | - </select> | |
| 519 | + <?php _e( 'Autoptimize news', 'autoptimize' ); ?> | |
| 403 | 520 | </h2> |
| 404 | 521 | <div id="futtta_feed"> |
| 405 | 522 | <div id="autoptimizefeed"> |
| 406 | - <?php $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_autoptimize"); ?> | |
| 523 | + <?php $this->get_futtta_feeds( 'http://feeds.feedburner.com/futtta_autoptimize' ); ?> | |
| 407 | 524 | </div> |
| 408 | - <div id="wordpressfeed"> | |
| 409 | - <?php $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_wordpress"); ?> | |
| 410 | - </div> | |
| 411 | - <div id="webtechfeed"> | |
| 412 | - <?php $this->getFutttaFeeds("http://feeds.feedburner.com/futtta_webtech"); ?> | |
| 413 | - </div> | |
| 414 | 525 | </div> |
| 415 | 526 | </div> |
| 416 | - <div style="float:right;margin:50px 15px;"><a href="http://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url().'/'.plugin_basename(dirname(__FILE__)).'/external/do_not_donate_smallest.png'; ?>" title="<?php _e("Do not donate for this plugin!","autoptimize"); ?>"></a></div> | |
| 527 | + <?php if ( apply_filters( 'autoptimize_filter_show_partner_tabs', true ) ) { ?> | |
| 528 | + <div style="float:right;margin:50px 15px;"><a href="https://blog.futtta.be/2013/10/21/do-not-donate-to-me/" target="_blank"><img width="100px" height="85px" src="<?php echo plugins_url() . '/' . plugin_basename( dirname( __FILE__ ) ) . '/external/do_not_donate_smallest.png'; ?>" title="<?php _e( 'Do not donate for this plugin!', 'autoptimize' ); ?>"></a></div> | |
| 529 | + <?php } ?> | |
| 417 | 530 | </div> |
| 418 | - | |
| 419 | 531 | <script type="text/javascript"> |
| 420 | - var feed = new Array; | |
| 421 | - feed[1]="autoptimizefeed"; | |
| 422 | - feed[2]="wordpressfeed"; | |
| 423 | - feed[3]="webtechfeed"; | |
| 424 | - cookiename="autoptimize_feed"; | |
| 425 | - | |
| 426 | 532 | jQuery(document).ready(function() { |
| 427 | 533 | check_ini_state(); |
| 428 | - jQuery('#autoptimize_admin_feed').fadeTo("slow",1).show(); | |
| 534 | + | |
| 429 | 535 | jQuery('.autoptimize_banner').unslider({autoplay:true, delay:3500, infinite: false, arrows:{prev:'<a class="unslider-arrow prev"></a>', next:'<a class="unslider-arrow next"></a>'}}).fadeTo("slow",1).show(); |
| 430 | 536 | |
| 431 | - jQuery( "#feed_dropdown" ).change(function() { | |
| 432 | - jQuery("#futtta_feed").fadeTo(0,0); | |
| 433 | - jQuery("#futtta_feed").fadeTo("slow",1); | |
| 434 | - }); | |
| 435 | - | |
| 436 | - jQuery( "#ao_show_adv" ).click(function() { | |
| 437 | - jQuery( "#ao_show_adv" ).hide(); | |
| 438 | - jQuery( "#ao_hide_adv" ).show(); | |
| 439 | - jQuery( ".ao_adv" ).removeClass("hidden"); | |
| 440 | - jQuery( ".ao_adv" ).show("slow"); | |
| 441 | - if (jQuery("#autoptimize_css").attr('checked')) { | |
| 442 | - jQuery(".css_sub:visible").fadeTo("fast",1); | |
| 443 | - if (!jQuery("#autoptimize_css_defer").attr('checked')) { | |
| 444 | - jQuery("#autoptimize_css_defer_inline").hide(); | |
| 445 | - } | |
| 446 | - } | |
| 447 | - if (jQuery("#autoptimize_js").attr('checked')) { | |
| 448 | - jQuery(".js_sub:visible").fadeTo("fast",1); | |
| 449 | - } | |
| 450 | - check_ini_state() | |
| 451 | - jQuery( "input#autoptimize_show_adv" ).val("1"); | |
| 452 | - }); | |
| 453 | - | |
| 454 | - jQuery( "#ao_hide_adv" ).click(function() { | |
| 455 | - jQuery( "#ao_hide_adv" ).hide(); | |
| 456 | - jQuery( "#ao_show_adv" ).show(); | |
| 457 | - jQuery( ".ao_adv" ).hide("slow"); | |
| 458 | - jQuery( ".ao_adv" ).addClass("hidden"); | |
| 459 | - if (!jQuery("#autoptimize_css").attr('checked')) { | |
| 460 | - jQuery(".css_sub:visible").fadeTo("fast",.33); | |
| 461 | - } | |
| 462 | - if (!jQuery("#autoptimize_js").attr('checked')) { | |
| 463 | - jQuery(".js_sub:visible").fadeTo("fast",.33); | |
| 464 | - } | |
| 465 | - check_ini_state() | |
| 466 | - jQuery( "input#autoptimize_show_adv" ).val("0"); | |
| 467 | - }); | |
| 468 | - | |
| 469 | 537 | jQuery( "#autoptimize_html" ).change(function() { |
| 470 | 538 | if (this.checked) { |
| 471 | 539 | jQuery(".html_sub:visible").fadeTo("fast",1); |
| 472 | 540 | } else { |
| @@ -481,8 +549,41 @@ | ||
| 481 | 549 | jQuery(".js_sub:visible").fadeTo("fast",.33); |
| 482 | 550 | } |
| 483 | 551 | }); |
| 484 | 552 | |
| 553 | + jQuery( "#autoptimize_js_aggregate" ).change(function() { | |
| 554 | + if (this.checked && jQuery("#autoptimize_js").prop('checked')) { | |
| 555 | + jQuery( "#autoptimize_js_defer_not_aggregate" ).prop( 'checked', false ); // uncheck "defer not aggregate" | |
| 556 | + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // ungrey self | |
| 557 | + jQuery( ".js_aggregate" ).show( 'slow' ); // show sub-items | |
| 558 | + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'slow', .33 ); // grey out "not aggregate" | |
| 559 | + jQuery( ".js_not_aggregate" ).hide( 'slow' ); // hide not aggregate sub-items | |
| 560 | + jQuery( "#min_excl_row" ).show(); // make sure "minify excluded" is visible | |
| 561 | + check_exclusions( "js", "on" ); | |
| 562 | + } else { | |
| 563 | + jQuery( ".js_aggregate" ).hide( 'slow' ); // hide sub-itmes | |
| 564 | + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // un-grey-out "not aggregate" | |
| 565 | + if ( jQuery( "#autoptimize_css_aggregate" ).prop( 'checked' ) == false ) { // hide "minify excluded" | |
| 566 | + jQuery( "#min_excl_row" ).hide(); | |
| 567 | + } | |
| 568 | + check_exclusions( "js", "off" ); | |
| 569 | + } | |
| 570 | + }); | |
| 571 | + | |
| 572 | + jQuery( "#autoptimize_js_defer_not_aggregate" ).change(function() { | |
| 573 | + if (this.checked && jQuery("#autoptimize_js").prop('checked')) { | |
| 574 | + jQuery( "#autoptimize_js_aggregate" ).prop( 'checked', false ); // uncheck "aggregate JS" | |
| 575 | + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // ungrey self | |
| 576 | + jQuery( ".js_not_aggregate" ).show( 'slow'); // show sub-items | |
| 577 | + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'slow', .33 ); // grey out "aggregate" | |
| 578 | + jQuery( ".js_aggregate" ).hide( 'slow' ); // hide aggregate sub-items | |
| 579 | + check_exclusions( "js", "off" ); | |
| 580 | + } else { | |
| 581 | + jQuery( ".js_not_aggregate" ).hide( 'slow' ); // hide sub-items | |
| 582 | + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'slow', 1 ); // un-grey-out "aggregate" | |
| 583 | + } | |
| 584 | + }); | |
| 585 | + | |
| 485 | 586 | jQuery( "#autoptimize_css" ).change(function() { |
| 486 | 587 | if (this.checked) { |
| 487 | 588 | jQuery(".css_sub:visible").fadeTo("fast",1); |
| 488 | 589 | } else { |
| @@ -489,8 +590,22 @@ | ||
| 489 | 590 | jQuery(".css_sub:visible").fadeTo("fast",.33); |
| 490 | 591 | } |
| 491 | 592 | }); |
| 492 | 593 | |
| 594 | + jQuery( "#autoptimize_css_aggregate" ).change(function() { | |
| 595 | + if (this.checked && jQuery("#autoptimize_css").prop('checked')) { | |
| 596 | + jQuery(".css_aggregate:visible").fadeTo("fast",1); | |
| 597 | + jQuery( "#min_excl_row" ).show(); | |
| 598 | + check_exclusions( "css", "on" ); | |
| 599 | + } else { | |
| 600 | + jQuery(".css_aggregate:visible").fadeTo("fast",.33); | |
| 601 | + if ( jQuery( "#autoptimize_js_aggregate" ).prop('checked') == false ) { | |
| 602 | + jQuery( "#min_excl_row" ).hide(); | |
| 603 | + } | |
| 604 | + check_exclusions( "css", "off" ); | |
| 605 | + } | |
| 606 | + }); | |
| 607 | + | |
| 493 | 608 | jQuery( "#autoptimize_css_inline" ).change(function() { |
| 494 | 609 | if (this.checked) { |
| 495 | 610 | jQuery("#autoptimize_css_defer").prop("checked",false); |
| 496 | 611 | jQuery("#autoptimize_css_defer_inline").hide("slow"); |
| @@ -505,15 +620,18 @@ | ||
| 505 | 620 | jQuery("#autoptimize_css_defer_inline").hide("slow"); |
| 506 | 621 | } |
| 507 | 622 | }); |
| 508 | 623 | |
| 509 | - jQuery("#feed_dropdown").change(function() { show_feed(jQuery("#feed_dropdown").val()) }); | |
| 510 | - feedid=jQuery.cookie(cookiename); | |
| 511 | - if(typeof(feedid) !== "string") feedid=1; | |
| 512 | - show_feed(feedid); | |
| 624 | + jQuery( "#autoptimize_enable_site_config" ).change(function() { | |
| 625 | + if (this.checked) { | |
| 626 | + jQuery("li.itemDetail:not(.multiSite)").fadeTo("fast",.33); | |
| 627 | + } else { | |
| 628 | + jQuery("li.itemDetail:not(.multiSite)").fadeTo("fast",1); | |
| 629 | + } | |
| 630 | + }); | |
| 513 | 631 | }) |
| 514 | 632 | |
| 515 | - // validate cdn_url | |
| 633 | + // validate cdn_url. | |
| 516 | 634 | var cdn_url=document.getElementById("cdn_url"); |
| 517 | 635 | cdn_url_baseCSS=cdn_url.style.cssText; |
| 518 | 636 | if ("validity" in cdn_url) { |
| 519 | 637 | jQuery("#cdn_url").focusout(function (event) { |
| @@ -524,27 +642,56 @@ | ||
| 524 | 642 | }}); |
| 525 | 643 | } |
| 526 | 644 | |
| 527 | 645 | function check_ini_state() { |
| 528 | - if (!jQuery("#autoptimize_css_defer").attr('checked')) { | |
| 646 | + if (!jQuery("#autoptimize_css_defer").prop('checked')) { | |
| 529 | 647 | jQuery("#autoptimize_css_defer_inline").hide(); |
| 530 | 648 | } |
| 531 | - if (!jQuery("#autoptimize_html").attr('checked')) { | |
| 649 | + if (!jQuery("#autoptimize_html").prop('checked')) { | |
| 532 | 650 | jQuery(".html_sub:visible").fadeTo('fast',.33); |
| 533 | 651 | } |
| 534 | - if (!jQuery("#autoptimize_css").attr('checked')) { | |
| 652 | + if (!jQuery("#autoptimize_css").prop('checked')) { | |
| 535 | 653 | jQuery(".css_sub:visible").fadeTo('fast',.33); |
| 536 | 654 | } |
| 537 | - if (!jQuery("#autoptimize_js").attr('checked')) { | |
| 655 | + if (!jQuery("#autoptimize_css_aggregate").prop('checked')) { | |
| 656 | + jQuery(".css_aggregate:visible").fadeTo('fast',.33); | |
| 657 | + } | |
| 658 | + if (jQuery("#autoptimize_js_aggregate").prop('checked')) { | |
| 659 | + jQuery( ".js_aggregate" ).show( 'fast' ); | |
| 660 | + jQuery( ".js_not_aggregate_master:visible" ).fadeTo( 'fast', .33 ); | |
| 661 | + } | |
| 662 | + if (jQuery("#autoptimize_js_defer_not_aggregate").prop('checked')) { | |
| 663 | + jQuery( ".js_not_aggregate" ).show( 'fast' ); | |
| 664 | + jQuery( ".js_aggregate_master:visible" ).fadeTo( 'fast', .33 ); | |
| 665 | + } | |
| 666 | + if (jQuery("#autoptimize_enable_site_config").prop('checked')) { | |
| 667 | + jQuery("li.itemDetail:not(.multiSite)").fadeTo('fast',.33); | |
| 668 | + } | |
| 669 | + if (!jQuery("#autoptimize_js").prop('checked')) { | |
| 538 | 670 | jQuery(".js_sub:visible").fadeTo('fast',.33); |
| 539 | 671 | } |
| 540 | 672 | } |
| 673 | + | |
| 674 | + function check_exclusions( what, state ) { | |
| 675 | + exclusion_node = 'input[name="autoptimize_' + what + '_exclude"]'; | |
| 676 | + current_exclusion = jQuery( exclusion_node ).val(); | |
| 541 | 677 | |
| 542 | - function show_feed(id) { | |
| 543 | - jQuery('#futtta_feed').children().hide(); | |
| 544 | - jQuery('#'+feed[id]).show(); | |
| 545 | - jQuery("#feed_dropdown").val(id); | |
| 546 | - jQuery.cookie(cookiename,id,{ expires: 365 }); | |
| 678 | + if ( what == "js" ) { | |
| 679 | + default_exclusion = ", wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.min.js"; | |
| 680 | + } else if ( what == "css") { | |
| 681 | + default_exclusion = ", admin-bar.min.css, dashicons.min.css, wp-content/cache/, wp-content/uploads/"; | |
| 682 | + } | |
| 683 | + | |
| 684 | + default_in_current = current_exclusion.indexOf(default_exclusion); | |
| 685 | + | |
| 686 | + if ( state == "on" && default_in_current == -1 ) { | |
| 687 | + jQuery( exclusion_node ).val( current_exclusion + default_exclusion ); | |
| 688 | + } else if ( state = "off" && current_exclusion == default_exclusion ) { | |
| 689 | + jQuery( exclusion_node ).val( "" ); | |
| 690 | + } else if ( state = "off" && default_in_current != -1 ) { | |
| 691 | + new_exclusion = current_exclusion.substring( 0, default_in_current) + current_exclusion.substring( default_in_current + default_exclusion.length, current_exclusion.length ); | |
| 692 | + jQuery( exclusion_node ).val( new_exclusion ); | |
| 693 | + } | |
| 547 | 694 | } |
| 548 | 695 | </script> |
| 549 | 696 | </div> |
| 550 | 697 | |
| @@ -550,67 +697,88 @@ | ||
| 550 | 697 | |
| 551 | 698 | <?php |
| 552 | 699 | } |
| 553 | 700 | |
| 554 | - public function addmenu() { | |
| 555 | - $hook=add_options_page(__('Autoptimize Options','autoptimize'),'Autoptimize','manage_options','autoptimize',array($this,'show')); | |
| 556 | - add_action( 'admin_print_scripts-'.$hook,array($this,'autoptimize_admin_scripts')); | |
| 557 | - add_action( 'admin_print_styles-'.$hook,array($this,'autoptimize_admin_styles')); | |
| 701 | + public function addmenu() | |
| 702 | + { | |
| 703 | + $_my_name = apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? __( 'Autoptimize Pro', 'autoptimize' ) : __( 'Autoptimize', 'autoptimize' ); | |
| 704 | + if ( is_multisite() && is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() ) { | |
| 705 | + // multisite, network admin, ao network activated: add normal settings page at network level. | |
| 706 | + $hook = add_submenu_page( 'settings.php', __( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_network_options', 'autoptimize', array( $this, 'show_config' ) ); | |
| 707 | + } elseif ( is_multisite() && ! is_network_admin() && autoptimizeOptionWrapper::is_ao_active_for_network() && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) ) { | |
| 708 | + // multisite, ao network activated, not network admin so site specific settings, but "autoptimize_enable_site_config" is off: show "sorry, ask network admin" message iso options. | |
| 709 | + $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_options', 'autoptimize', array( $this, 'show_network_message' ) ); | |
| 710 | + } else { | |
| 711 | + // default: show normal options page if not multisite, if multisite but not network activated, if multisite and network activated and "autoptimize_enable_site_config" is on. | |
| 712 | + $hook = add_options_page( __( 'Autoptimize Options', 'autoptimize' ), $_my_name, 'manage_options', 'autoptimize', array( $this, 'show_config' ) ); | |
| 713 | + } | |
| 714 | + | |
| 715 | + add_action( 'admin_print_scripts-' . $hook, array( $this, 'autoptimize_admin_scripts' ) ); | |
| 716 | + add_action( 'admin_print_styles-' . $hook, array( $this, 'autoptimize_admin_styles' ) ); | |
| 558 | 717 | } |
| 559 | 718 | |
| 560 | - public function autoptimize_admin_scripts() { | |
| 561 | - wp_enqueue_script('jqcookie', plugins_url('/external/js/jquery.cookie.min.js', __FILE__), array('jquery'),null,true); | |
| 562 | - wp_enqueue_script('unslider', plugins_url('/external/js/unslider-min.js', __FILE__), array('jquery'),null,true); | |
| 719 | + public function autoptimize_admin_scripts() | |
| 720 | + { | |
| 721 | + wp_enqueue_script( 'unslider', plugins_url( '/external/js/unslider-min.js', __FILE__ ), array( 'jquery' ), null, true ); | |
| 563 | 722 | } |
| 564 | 723 | |
| 565 | - public function autoptimize_admin_styles() { | |
| 566 | - wp_enqueue_style('unslider', plugins_url('/external/js/unslider.css', __FILE__)); | |
| 567 | - wp_enqueue_style('unslider-dots', plugins_url('/external/js/unslider-dots.css', __FILE__)); | |
| 724 | + public function autoptimize_admin_styles() | |
| 725 | + { | |
| 726 | + wp_enqueue_style( 'unslider', plugins_url( '/external/js/unslider.css', __FILE__ ) ); | |
| 727 | + wp_enqueue_style( 'unslider-dots', plugins_url( '/external/js/unslider-dots.css', __FILE__ ) ); | |
| 568 | 728 | } |
| 569 | 729 | |
| 570 | 730 | public function registersettings() { |
| 571 | - register_setting('autoptimize','autoptimize_html'); | |
| 572 | - register_setting('autoptimize','autoptimize_html_keepcomments'); | |
| 573 | - register_setting('autoptimize','autoptimize_js'); | |
| 574 | - register_setting('autoptimize','autoptimize_js_exclude'); | |
| 575 | - register_setting('autoptimize','autoptimize_js_trycatch'); | |
| 576 | - register_setting('autoptimize','autoptimize_js_justhead'); | |
| 577 | - register_setting('autoptimize','autoptimize_js_forcehead'); | |
| 578 | - register_setting('autoptimize','autoptimize_js_include_inline'); | |
| 579 | - register_setting('autoptimize','autoptimize_css'); | |
| 580 | - register_setting('autoptimize','autoptimize_css_exclude'); | |
| 581 | - register_setting('autoptimize','autoptimize_css_justhead'); | |
| 582 | - register_setting('autoptimize','autoptimize_css_datauris'); | |
| 583 | - register_setting('autoptimize','autoptimize_css_defer'); | |
| 584 | - register_setting('autoptimize','autoptimize_css_defer_inline'); | |
| 585 | - register_setting('autoptimize','autoptimize_css_inline'); | |
| 586 | - register_setting('autoptimize','autoptimize_css_include_inline'); | |
| 587 | - register_setting('autoptimize','autoptimize_css_nogooglefont'); | |
| 588 | - register_setting('autoptimize','autoptimize_cdn_url'); | |
| 589 | - register_setting('autoptimize','autoptimize_cache_clean'); | |
| 590 | - register_setting('autoptimize','autoptimize_cache_nogzip'); | |
| 591 | - register_setting('autoptimize','autoptimize_show_adv'); | |
| 592 | - register_setting('autoptimize','autoptimize_optimize_logged'); | |
| 593 | - register_setting('autoptimize','autoptimize_optimize_checkout'); | |
| 731 | + register_setting( 'autoptimize', 'autoptimize_html' ); | |
| 732 | + register_setting( 'autoptimize', 'autoptimize_html_keepcomments' ); | |
| 733 | + register_setting( 'autoptimize', 'autoptimize_enable_site_config' ); | |
| 734 | + register_setting( 'autoptimize', 'autoptimize_js' ); | |
| 735 | + register_setting( 'autoptimize', 'autoptimize_js_aggregate' ); | |
| 736 | + register_setting( 'autoptimize', 'autoptimize_js_defer_not_aggregate' ); | |
| 737 | + register_setting( 'autoptimize', 'autoptimize_js_defer_inline' ); | |
| 738 | + register_setting( 'autoptimize', 'autoptimize_js_exclude' ); | |
| 739 | + register_setting( 'autoptimize', 'autoptimize_js_trycatch' ); | |
| 740 | + register_setting( 'autoptimize', 'autoptimize_js_justhead' ); | |
| 741 | + register_setting( 'autoptimize', 'autoptimize_js_forcehead' ); | |
| 742 | + register_setting( 'autoptimize', 'autoptimize_js_include_inline' ); | |
| 743 | + register_setting( 'autoptimize', 'autoptimize_css' ); | |
| 744 | + register_setting( 'autoptimize', 'autoptimize_css_aggregate' ); | |
| 745 | + register_setting( 'autoptimize', 'autoptimize_css_exclude' ); | |
| 746 | + register_setting( 'autoptimize', 'autoptimize_css_justhead' ); | |
| 747 | + register_setting( 'autoptimize', 'autoptimize_css_datauris' ); | |
| 748 | + register_setting( 'autoptimize', 'autoptimize_css_defer' ); | |
| 749 | + register_setting( 'autoptimize', 'autoptimize_css_defer_inline' ); | |
| 750 | + register_setting( 'autoptimize', 'autoptimize_css_inline' ); | |
| 751 | + register_setting( 'autoptimize', 'autoptimize_css_include_inline' ); | |
| 752 | + register_setting( 'autoptimize', 'autoptimize_cdn_url' ); | |
| 753 | + register_setting( 'autoptimize', 'autoptimize_cache_clean' ); | |
| 754 | + register_setting( 'autoptimize', 'autoptimize_cache_nogzip' ); | |
| 755 | + register_setting( 'autoptimize', 'autoptimize_optimize_logged' ); | |
| 756 | + register_setting( 'autoptimize', 'autoptimize_optimize_checkout' ); | |
| 757 | + register_setting( 'autoptimize', 'autoptimize_minify_excluded' ); | |
| 758 | + register_setting( 'autoptimize', 'autoptimize_cache_fallback' ); | |
| 759 | + register_setting( 'autoptimize', 'autoptimize_enable_meta_ao_settings' ); | |
| 594 | 760 | } |
| 595 | 761 | |
| 596 | - public function setmeta($links,$file=null) { | |
| 597 | - //Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/ | |
| 598 | - //Do it only once - saves time | |
| 762 | + public function setmeta( $links, $file = null ) | |
| 763 | + { | |
| 764 | + // Inspired on http://wpengineer.com/meta-links-for-wordpress-plugins/. | |
| 765 | + // Do it only once - saves time. | |
| 599 | 766 | static $plugin; |
| 600 | - if(empty($plugin)) | |
| 601 | - $plugin = plugin_basename(AUTOPTIMIZE_PLUGIN_DIR.'autoptimize.php'); | |
| 602 | - | |
| 603 | - if($file===null) { | |
| 604 | - //2.7 | |
| 605 | - $settings_link = sprintf('<a href="options-general.php?page=autoptimize">%s</a>', __('Settings')); | |
| 606 | - array_unshift($links,$settings_link); | |
| 767 | + if ( empty( $plugin ) ) { | |
| 768 | + $plugin = plugin_basename( AUTOPTIMIZE_PLUGIN_DIR . 'autoptimize.php' ); | |
| 769 | + } | |
| 770 | + | |
| 771 | + if ( null === $file ) { | |
| 772 | + // 2.7 and lower. | |
| 773 | + $settings_link = sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ); | |
| 774 | + array_unshift( $links, $settings_link ); | |
| 607 | 775 | } else { |
| 608 | - //2.8 | |
| 609 | - //If it's us, add the link | |
| 610 | - if($file === $plugin) { | |
| 611 | - $newlink = array(sprintf('<a href="options-general.php?page=autoptimize">%s</a>',__('Settings'))); | |
| 612 | - $links = array_merge($links,$newlink); | |
| 776 | + // 2.8 and higher. | |
| 777 | + // If it's us, add the link. | |
| 778 | + if ( $file === $plugin ) { | |
| 779 | + $newlink = array( sprintf( '<a href="options-general.php?page=autoptimize">%s</a>', __( 'Settings' ) ) ); | |
| 780 | + $links = array_merge( $links, $newlink ); | |
| 613 | 781 | } |
| 614 | 782 | } |
| 615 | 783 | |
| 616 | 784 | return $links; |
| @@ -615,72 +783,146 @@ | ||
| 615 | 783 | |
| 616 | 784 | return $links; |
| 617 | 785 | } |
| 618 | 786 | |
| 619 | - public function get($key) { | |
| 620 | - if(!is_array($this->config)) { | |
| 621 | - //Default config | |
| 622 | - $config = array('autoptimize_html' => 0, | |
| 623 | - 'autoptimize_html_keepcomments' => 0, | |
| 624 | - 'autoptimize_js' => 0, | |
| 625 | - 'autoptimize_js_exclude' => "seal.js, js/jquery/jquery.js", | |
| 626 | - 'autoptimize_js_trycatch' => 0, | |
| 627 | - 'autoptimize_js_justhead' => 0, | |
| 628 | - 'autoptimize_js_include_inline' => 0, | |
| 629 | - 'autoptimize_js_forcehead' => 0, | |
| 630 | - 'autoptimize_css' => 0, | |
| 631 | - 'autoptimize_css_exclude' => "admin-bar.min.css, dashicons.min.css", | |
| 632 | - 'autoptimize_css_justhead' => 0, | |
| 633 | - 'autoptimize_css_include_inline' => 1, | |
| 634 | - 'autoptimize_css_defer' => 0, | |
| 635 | - 'autoptimize_css_defer_inline' => "", | |
| 636 | - 'autoptimize_css_inline' => 0, | |
| 637 | - 'autoptimize_css_datauris' => 0, | |
| 638 | - 'autoptimize_css_nogooglefont' => 0, | |
| 639 | - 'autoptimize_cdn_url' => "", | |
| 640 | - 'autoptimize_cache_nogzip' => 1, | |
| 641 | - 'autoptimize_show_adv' => 0, | |
| 642 | - 'autoptimize_optimize_logged' => 1, | |
| 643 | - 'autoptimize_optimize_checkout' => 1 | |
| 644 | - ); | |
| 787 | + /** | |
| 788 | + * Provides the default options. | |
| 789 | + * | |
| 790 | + * @return array | |
| 791 | + */ | |
| 792 | + public static function get_defaults() | |
| 793 | + { | |
| 794 | + static $config = array( | |
| 795 | + 'autoptimize_html' => 0, | |
| 796 | + 'autoptimize_html_keepcomments' => 0, | |
| 797 | + 'autoptimize_enable_site_config' => 1, | |
| 798 | + 'autoptimize_js' => 0, | |
| 799 | + 'autoptimize_js_aggregate' => 0, | |
| 800 | + 'autoptimize_js_defer_not_aggregate' => 1, | |
| 801 | + 'autoptimize_js_defer_inline' => 1, | |
| 802 | + 'autoptimize_js_exclude' => '', // 'wp-includes/js/dist/, wp-includes/js/tinymce/, js/jquery/jquery.min.js', | |
| 803 | + 'autoptimize_js_trycatch' => 0, | |
| 804 | + 'autoptimize_js_justhead' => 0, | |
| 805 | + 'autoptimize_js_include_inline' => 0, | |
| 806 | + 'autoptimize_js_forcehead' => 0, | |
| 807 | + 'autoptimize_css' => 0, | |
| 808 | + 'autoptimize_css_aggregate' => 0, | |
| 809 | + 'autoptimize_css_exclude' => '', // admin-bar.min.css, dashicons.min.css, wp-content/cache/, wp-content/uploads/', | |
| 810 | + 'autoptimize_css_justhead' => 0, | |
| 811 | + 'autoptimize_css_include_inline' => 0, | |
| 812 | + 'autoptimize_css_defer' => 0, | |
| 813 | + 'autoptimize_css_defer_inline' => '', | |
| 814 | + 'autoptimize_css_inline' => 0, | |
| 815 | + 'autoptimize_css_datauris' => 0, | |
| 816 | + 'autoptimize_cdn_url' => '', | |
| 817 | + 'autoptimize_cache_nogzip' => 1, | |
| 818 | + 'autoptimize_optimize_logged' => 1, | |
| 819 | + 'autoptimize_optimize_checkout' => 0, | |
| 820 | + 'autoptimize_minify_excluded' => 1, | |
| 821 | + 'autoptimize_cache_fallback' => 1, | |
| 822 | + 'autoptimize_enable_meta_ao_settings' => 1, | |
| 823 | + ); | |
| 645 | 824 | |
| 646 | - //Override with user settings | |
| 647 | - foreach(array_keys($config) as $name) { | |
| 648 | - $conf = get_option($name); | |
| 649 | - if($conf!==false) { | |
| 650 | - //It was set before! | |
| 651 | - $config[$name] = $conf; | |
| 825 | + return $config; | |
| 826 | + } | |
| 827 | + | |
| 828 | + /** | |
| 829 | + * Returns default option values for autoptimizeExtra. | |
| 830 | + * | |
| 831 | + * @return array | |
| 832 | + */ | |
| 833 | + public static function get_ao_extra_default_options() | |
| 834 | + { | |
| 835 | + $defaults = array( | |
| 836 | + 'autoptimize_extra_checkbox_field_1' => '0', | |
| 837 | + 'autoptimize_extra_checkbox_field_0' => '0', | |
| 838 | + 'autoptimize_extra_radio_field_4' => '1', | |
| 839 | + 'autoptimize_extra_text_field_2' => '', | |
| 840 | + 'autoptimize_extra_text_field_3' => '', | |
| 841 | + 'autoptimize_extra_text_field_7' => '', | |
| 842 | + 'autoptimize_extra_checkbox_field_8' => '0', | |
| 843 | + ); | |
| 844 | + | |
| 845 | + return $defaults; | |
| 846 | + } | |
| 847 | + | |
| 848 | + /** | |
| 849 | + * Returns default option values for autoptimizeExtra. | |
| 850 | + * | |
| 851 | + * @return array | |
| 852 | + */ | |
| 853 | + public static function get_ao_imgopt_default_options() | |
| 854 | + { | |
| 855 | + $defaults = array( | |
| 856 | + 'autoptimize_imgopt_checkbox_field_1' => '0', // imgopt off. | |
| 857 | + 'autoptimize_imgopt_select_field_2' => '2', // quality glossy. | |
| 858 | + 'autoptimize_imgopt_checkbox_field_3' => '0', // lazy load off. | |
| 859 | + 'autoptimize_imgopt_checkbox_field_4' => '0', // webp off (might be removed). | |
| 860 | + 'autoptimize_imgopt_text_field_5' => '', // lazy load exclusions empty. | |
| 861 | + 'autoptimize_imgopt_text_field_6' => '', // optimization exclusions empty. | |
| 862 | + 'autoptimize_imgopt_number_field_7' => '2', // lazy load from nth image (0 = lazyload all). | |
| 863 | + ); | |
| 864 | + return $defaults; | |
| 865 | + } | |
| 866 | + | |
| 867 | + /** | |
| 868 | + * Returns preload JS onload handler. | |
| 869 | + * | |
| 870 | + * @param string $media media attribute value the JS to use. | |
| 871 | + * | |
| 872 | + * @return string | |
| 873 | + */ | |
| 874 | + public static function get_ao_css_preload_onload( $media = 'all' ) | |
| 875 | + { | |
| 876 | + $preload_onload = apply_filters( 'autoptimize_filter_css_preload_onload', "this.onload=null;this.media='" . $media . "';" ); | |
| 877 | + return $preload_onload; | |
| 878 | + } | |
| 879 | + | |
| 880 | + public function get( $key ) | |
| 881 | + { | |
| 882 | + if ( ! is_array( $this->config ) ) { | |
| 883 | + // Default config. | |
| 884 | + $config = self::get_defaults(); | |
| 885 | + | |
| 886 | + // Override with user settings. | |
| 887 | + foreach ( array_keys( $config ) as $name ) { | |
| 888 | + $conf = autoptimizeOptionWrapper::get_option( $name ); | |
| 889 | + if ( false !== $conf ) { | |
| 890 | + // It was set before! | |
| 891 | + $config[ $name ] = $conf; | |
| 652 | 892 | } |
| 653 | 893 | } |
| 654 | 894 | |
| 655 | - //Save for next question | |
| 656 | - $this->config = $config; | |
| 895 | + // Save for next call. | |
| 896 | + $this->config = apply_filters( 'autoptimize_filter_get_config', $config ); | |
| 657 | 897 | } |
| 658 | 898 | |
| 659 | - if(isset($this->config[$key])) | |
| 660 | - return $this->config[$key]; | |
| 899 | + if ( isset( $this->config[ $key ] ) ) { | |
| 900 | + return $this->config[ $key ]; | |
| 901 | + } | |
| 661 | 902 | |
| 662 | 903 | return false; |
| 663 | 904 | } |
| 664 | 905 | |
| 665 | - private function getFutttaFeeds($url) { | |
| 666 | - if (apply_filters('autoptimize_settingsscreen_remotehttp',true)) { | |
| 667 | - $rss = fetch_feed( $url ); | |
| 906 | + private function get_futtta_feeds( $url ) { | |
| 907 | + if ( $this->settings_screen_do_remote_http ) { | |
| 908 | + $rss = fetch_feed( $url ); | |
| 668 | 909 | $maxitems = 0; |
| 669 | 910 | |
| 670 | 911 | if ( ! is_wp_error( $rss ) ) { |
| 671 | - $maxitems = $rss->get_item_quantity( 7 ); | |
| 912 | + $maxitems = $rss->get_item_quantity( 7 ); | |
| 672 | 913 | $rss_items = $rss->get_items( 0, $maxitems ); |
| 673 | 914 | } |
| 674 | 915 | ?> |
| 675 | 916 | <ul> |
| 676 | - <?php if ( $maxitems == 0 ) : ?> | |
| 917 | + <?php if ( 0 == $maxitems ) : ?> | |
| 677 | 918 | <li><?php _e( 'No items', 'autoptimize' ); ?></li> |
| 678 | 919 | <?php else : ?> |
| 679 | 920 | <?php foreach ( $rss_items as $item ) : ?> |
| 680 | 921 | <li> |
| 681 | 922 | <a href="<?php echo esc_url( $item->get_permalink() ); ?>" |
| 682 | - title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date('j F Y | g:i a') ); ?>"> | |
| 923 | + <?php // translators: the variable contains a date. ?> | |
| 924 | + title="<?php printf( __( 'Posted %s', 'autoptimize' ), $item->get_date( 'j F Y | g:i a' ) ); ?>"> | |
| 683 | 925 | <?php echo esc_html( $item->get_title() ); ?> |
| 684 | 926 | </a> |
| 685 | 927 | </li> |
| 686 | 928 | <?php endforeach; ?> |
| @@ -685,35 +927,146 @@ | ||
| 685 | 927 | </li> |
| 686 | 928 | <?php endforeach; ?> |
| 687 | 929 | <?php endif; ?> |
| 688 | 930 | </ul> |
| 689 | - <?php | |
| 931 | + <?php | |
| 690 | 932 | } |
| 691 | 933 | } |
| 692 | 934 | |
| 693 | - // based on http://wordpress.stackexchange.com/a/58826 | |
| 694 | - static function ao_admin_tabs(){ | |
| 695 | - $tabs = apply_filters('autoptimize_filter_settingsscreen_tabs',array('autoptimize' => __('Main','autoptimize'))); | |
| 696 | - $tabContent=""; | |
| 697 | - if (count($tabs)>1) { | |
| 698 | - if(isset($_GET['page'])){ | |
| 699 | - $currentId = $_GET['page']; | |
| 935 | + static function ao_admin_tabs() | |
| 936 | + { | |
| 937 | + // based on http://wordpress.stackexchange.com/a/58826 . | |
| 938 | + $tabs = apply_filters( 'autoptimize_filter_settingsscreen_tabs', array( 'autoptimize' => __( 'JS, CSS & HTML', 'autoptimize' ) ) ); | |
| 939 | + $tab_content = ''; | |
| 940 | + $tabs_count = count( $tabs ); | |
| 941 | + if ( $tabs_count > 1 ) { | |
| 942 | + if ( isset( $_GET['page'] ) ) { | |
| 943 | + $current_id = $_GET['page']; | |
| 700 | 944 | } else { |
| 701 | - $currentId = "autoptimize"; | |
| 945 | + $current_id = 'autoptimize'; | |
| 702 | 946 | } |
| 703 | - $tabContent .= "<h2 class=\"nav-tab-wrapper\">"; | |
| 704 | - foreach($tabs as $tabId => $tabName){ | |
| 705 | - if($currentId == $tabId){ | |
| 706 | - $class = " nav-tab-active"; | |
| 707 | - } else{ | |
| 708 | - $class = ""; | |
| 947 | + $tab_content .= '<h2 class="nav-tab-wrapper">'; | |
| 948 | + foreach ( $tabs as $tab_id => $tab_name ) { | |
| 949 | + if ( $current_id == $tab_id ) { | |
| 950 | + $class = ' nav-tab-active'; | |
| 951 | + } else { | |
| 952 | + $class = ''; | |
| 709 | 953 | } |
| 710 | - $tabContent .= '<a class="nav-tab'.$class.'" href="?page='.$tabId.'">'.$tabName.'</a>'; | |
| 954 | + $tab_content .= '<a class="nav-tab' . $class . '" href="?page=' . $tab_id . '">' . $tab_name . '</a>'; | |
| 711 | 955 | } |
| 712 | - $tabContent .= "</h2>"; | |
| 956 | + $tab_content .= '</h2>'; | |
| 713 | 957 | } else { |
| 714 | - $tabContent = "<hr/>"; | |
| 958 | + $tab_content = '<hr/>'; | |
| 715 | 959 | } |
| 716 | 960 | |
| 717 | - return $tabContent; | |
| 961 | + return $tab_content; | |
| 962 | + } | |
| 963 | + | |
| 964 | + /** | |
| 965 | + * Returns true if in admin (and not in admin-ajax.php!) | |
| 966 | + * | |
| 967 | + * @return bool | |
| 968 | + */ | |
| 969 | + public static function is_admin_and_not_ajax() | |
| 970 | + { | |
| 971 | + return ( is_admin() && ! self::doing_ajax() ); | |
| 972 | + } | |
| 973 | + | |
| 974 | + /** | |
| 975 | + * Returns true if doing ajax. | |
| 976 | + * | |
| 977 | + * @return bool | |
| 978 | + */ | |
| 979 | + protected static function doing_ajax() | |
| 980 | + { | |
| 981 | + if ( function_exists( 'wp_doing_ajax' ) ) { | |
| 982 | + return wp_doing_ajax(); | |
| 983 | + } | |
| 984 | + return ( defined( 'DOING_AJAX' ) && DOING_AJAX ); | |
| 985 | + } | |
| 986 | + | |
| 987 | + /** | |
| 988 | + * Returns true menu or tab is to be shown. | |
| 989 | + * | |
| 990 | + * @return bool | |
| 991 | + */ | |
| 992 | + public static function should_show_menu_tabs() { | |
| 993 | + if ( ! is_multisite() || is_network_admin() || 'on' === autoptimizeOptionWrapper::get_option( 'autoptimize_enable_site_config' ) || false === autoptimizeOptionWrapper::is_ao_active_for_network() ) { | |
| 994 | + return true; | |
| 995 | + } else { | |
| 996 | + return false; | |
| 997 | + } | |
| 998 | + } | |
| 999 | + | |
| 1000 | + /** | |
| 1001 | + * Returns the post meta AO settings for reuse in different optimizers. | |
| 1002 | + * | |
| 1003 | + * @return bool | |
| 1004 | + */ | |
| 1005 | + public static function get_post_meta_ao_settings( $optim ) { | |
| 1006 | + if ( ! autoptimizeConfig::is_ao_meta_settings_active() ) { | |
| 1007 | + // Per page/post settings not active, so always return true (as in; can be optimized). | |
| 1008 | + if ( in_array( $optim, array( 'ao_post_preload' ) ) ) { | |
| 1009 | + // but make sure to return false for text input. | |
| 1010 | + return false; | |
| 1011 | + } | |
| 1012 | + return true; | |
| 1013 | + } | |
| 1014 | + | |
| 1015 | + static $_meta_value = null; | |
| 1016 | + if ( null === $_meta_value ) { | |
| 1017 | + global $wp_query; | |
| 1018 | + if ( isset( $wp_query ) && ( is_page() || is_single() ) ) { | |
| 1019 | + $_meta_value = get_post_meta( get_the_ID(), 'ao_post_optimize', true ); | |
| 1020 | + } else if ( isset( $wp_query ) ) { | |
| 1021 | + $_meta_value = false; | |
| 1022 | + } | |
| 1023 | + } | |
| 1024 | + | |
| 1025 | + // If autoptimize_post_optimize !== 'on' (except for ao_post_preload, which can have other values) then always return false as all is off. | |
| 1026 | + // fixme: need unit tests to ensure below logic is sane! | |
| 1027 | + if ( empty( $_meta_value ) || ! is_array( $_meta_value ) ) { | |
| 1028 | + // no metabox values so all optimizations are a go. | |
| 1029 | + if ( in_array( $optim, array( 'ao_post_preload' ) ) ) { | |
| 1030 | + // but make sure to return false for text input. | |
| 1031 | + return false; | |
| 1032 | + } | |
| 1033 | + return true; | |
| 1034 | + } else if ( array_key_exists( 'ao_post_optimize', $_meta_value ) && 'on' !== $_meta_value['ao_post_optimize'] ) { | |
| 1035 | + // ao entirely off for this page. | |
| 1036 | + return false; | |
| 1037 | + } else if ( array_key_exists( $optim, $_meta_value ) && empty( $_meta_value[$optim] ) ) { | |
| 1038 | + // sub-optimization off for this page. | |
| 1039 | + return false; | |
| 1040 | + } else if ( array_key_exists( $optim, $_meta_value ) && 'on' === $_meta_value[$optim] ) { | |
| 1041 | + // sub-optimization is explictly on. | |
| 1042 | + return true; | |
| 1043 | + } else if ( array_key_exists( $optim, $_meta_value ) && in_array( $optim, array( 'ao_post_preload' ) ) && ! empty( $_meta_value[$optim] ) ) { | |
| 1044 | + // a non-bool metabox optimization (currently only preload field), return value instead of bool. | |
| 1045 | + return $_meta_value[$optim]; | |
| 1046 | + } else if ( in_array( $optim, array( 'ao_post_preload' ) ) && ( ! array_key_exists( $optim, $_meta_value ) || empty( $_meta_value[$optim] ) ) ) { | |
| 1047 | + // a non-bool metabox optimization not found or empty, so returning false. | |
| 1048 | + return false; | |
| 1049 | + } else { | |
| 1050 | + // when in doubt "go" for optimization, but this should never happen? | |
| 1051 | + if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { | |
| 1052 | + error_log( 'AO metabox logic fallback; well, how did I get here? Maybe this helps: looking for ' . $optim . ' in ' . json_encode( $_meta_value ) ); | |
| 1053 | + } | |
| 1054 | + return true; | |
| 1055 | + } | |
| 1056 | + } | |
| 1057 | + | |
| 1058 | + /** | |
| 1059 | + * Are the post meta AO settings active (default: no)? | |
| 1060 | + * | |
| 1061 | + * @return bool | |
| 1062 | + */ | |
| 1063 | + public static function is_ao_meta_settings_active() { | |
| 1064 | + static $_meta_settings_active = null; | |
| 1065 | + | |
| 1066 | + if ( null === $_meta_settings_active ) { | |
| 1067 | + $_meta_settings_active = apply_filters( 'autoptimize_filter_enable_meta_ao_settings', autoptimizeOptionWrapper::get_option( 'autoptimize_enable_meta_ao_settings', '1' ) ); | |
| 1068 | + } | |
| 1069 | + | |
| 1070 | + return $_meta_settings_active; | |
| 718 | 1071 | } |
| 719 | 1072 | } |