| @@ -14,10 +14,17 @@ | ||
| 14 | 14 | * @var bool |
| 15 | 15 | */ |
| 16 | 16 | private $settings_screen_do_remote_http = true; |
| 17 | 17 | |
| 18 | - public function __construct() | |
| 19 | - { | |
| 18 | + /** | |
| 19 | + * Critical CSS object. | |
| 20 | + * | |
| 21 | + * @var object | |
| 22 | + */ | |
| 23 | + protected $criticalcss; | |
| 24 | + | |
| 25 | + public function __construct() { | |
| 26 | + $this->criticalcss = autoptimize()->criticalcss(); | |
| 20 | 27 | $this->settings_screen_do_remote_http = apply_filters( 'autoptimize_settingsscreen_remotehttp', $this->settings_screen_do_remote_http ); |
| 21 | 28 | $this->run(); |
| 22 | 29 | } |
| 23 | 30 | |
| @@ -38,14 +45,19 @@ | ||
| 38 | 45 | add_action( 'admin_menu', array( $this, 'add_critcss_admin_menu' ) ); |
| 39 | 46 | } |
| 40 | 47 | |
| 41 | 48 | $criticalcss_ajax = new autoptimizeCriticalCSSSettingsAjax(); |
| 49 | + | |
| 50 | + // if debug logging is off but the file is present, then remove the debug log file. | |
| 51 | + if ( empty( $this->criticalcss->get_option( 'debug' ) ) && file_exists( AO_CCSS_LOG ) ) { | |
| 52 | + unlink( AO_CCSS_LOG ); | |
| 53 | + } | |
| 42 | 54 | } |
| 43 | 55 | } |
| 44 | 56 | |
| 45 | 57 | public function add_critcss_tabs( $in ) |
| 46 | 58 | { |
| 47 | - $in = array_merge( $in, array( 'ao_critcss' => '⚡ ' . __( 'Critical CSS', 'autoptimize' ) ) ); | |
| 59 | + $in = array_merge( $in, array( 'ao_critcss' => apply_filters( 'autoptimize_filter_ccss_tab_text', '⚡ ' . esc_html__( 'Critical CSS', 'autoptimize' ) ) ) ); | |
| 48 | 60 | |
| 49 | 61 | return $in; |
| 50 | 62 | } |
| 51 | 63 | |
| @@ -57,9 +69,9 @@ | ||
| 57 | 69 | register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_additional' ); |
| 58 | 70 | register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_queue' ); |
| 59 | 71 | register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_viewport' ); |
| 60 | 72 | register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_finclude' ); |
| 61 | - register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rlimit' ); | |
| 73 | + register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_rtimelimit' ); | |
| 62 | 74 | register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_noptimize' ); |
| 63 | 75 | register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_debug' ); |
| 64 | 76 | register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_key' ); |
| 65 | 77 | register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_keyst' ); |
| @@ -69,9 +81,9 @@ | ||
| 69 | 81 | register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_domain' ); |
| 70 | 82 | register_setting( 'ao_ccss_options_group', 'autoptimize_ccss_unloadccss' ); |
| 71 | 83 | |
| 72 | 84 | // And add submenu-page. |
| 73 | - add_submenu_page( null, 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array( $this, 'ao_criticalcsssettings_page' ) ); | |
| 85 | + add_submenu_page( '', 'Critical CSS', 'Critical CSS', 'manage_options', 'ao_critcss', array( $this, 'ao_criticalcsssettings_page' ) ); | |
| 74 | 86 | } |
| 75 | 87 | |
| 76 | 88 | public function admin_assets( $hook ) { |
| 77 | 89 | // Return if plugin is not hooked. |
| @@ -80,16 +92,16 @@ | ||
| 80 | 92 | } |
| 81 | 93 | |
| 82 | 94 | // Stylesheets to add. |
| 83 | 95 | wp_enqueue_style( 'wp-jquery-ui-dialog' ); |
| 84 | - wp_enqueue_style( 'ao-tablesorter', plugins_url( 'critcss-inc/css/ao-tablesorter/style.css', __FILE__ ) ); | |
| 85 | - wp_enqueue_style( 'ao-ccss-admin-css', plugins_url( 'critcss-inc/css/admin_styles.css', __FILE__ ) ); | |
| 96 | + wp_enqueue_style( 'ao-tablesorter', plugins_url( 'critcss-inc/css/ao-tablesorter/style.css', __FILE__ ), null, AUTOPTIMIZE_PLUGIN_VERSION ); | |
| 97 | + wp_enqueue_style( 'ao-ccss-admin-css', plugins_url( 'critcss-inc/css/admin_styles.css', __FILE__ ), null, AUTOPTIMIZE_PLUGIN_VERSION ); | |
| 86 | 98 | |
| 87 | 99 | // Scripts to add. |
| 88 | - wp_enqueue_script( 'jquery-ui-dialog', array( 'jquery' ) ); | |
| 89 | - wp_enqueue_script( 'md5', plugins_url( 'critcss-inc/js/md5.min.js', __FILE__ ), null, null, true ); | |
| 90 | - wp_enqueue_script( 'tablesorter', plugins_url( 'critcss-inc/js/jquery.tablesorter.min.js', __FILE__ ), array( 'jquery' ), null, true ); | |
| 91 | - wp_enqueue_script( 'ao-ccss-admin-license', plugins_url( 'critcss-inc/js/admin_settings.js', __FILE__ ), array( 'jquery' ), null, true ); | |
| 100 | + wp_enqueue_script( 'jquery-ui-dialog', '', array( 'jquery' ), null, true ); | |
| 101 | + wp_enqueue_script( 'md5', plugins_url( 'critcss-inc/js/md5.min.js', __FILE__ ), null, AUTOPTIMIZE_PLUGIN_VERSION, true ); | |
| 102 | + wp_enqueue_script( 'tablesorter', plugins_url( 'critcss-inc/js/jquery.tablesorter.min.js', __FILE__ ), array( 'jquery' ), AUTOPTIMIZE_PLUGIN_VERSION, true ); | |
| 103 | + wp_enqueue_script( 'ao-ccss-admin-license', plugins_url( 'critcss-inc/js/admin_settings.js', __FILE__ ), array( 'jquery' ), AUTOPTIMIZE_PLUGIN_VERSION, true ); | |
| 92 | 104 | } |
| 93 | 105 | |
| 94 | 106 | public function ao_criticalcsssettings_page() |
| 95 | 107 | { |
| @@ -99,20 +111,29 @@ | ||
| 99 | 111 | require_once( 'critcss-inc/admin_settings_key.php' ); |
| 100 | 112 | require_once( 'critcss-inc/admin_settings_adv.php' ); |
| 101 | 113 | require_once( 'critcss-inc/admin_settings_explain.php' ); |
| 102 | 114 | |
| 103 | - // fetch all options at once and populate them individually explicitely as globals. | |
| 104 | - $all_options = autoptimizeCriticalCSSBase::fetch_options(); | |
| 105 | - foreach ( $all_options as $_option => $_value ) { | |
| 106 | - global ${$_option}; | |
| 107 | - ${$_option} = $_value; | |
| 108 | - } | |
| 115 | + $ao_ccss_key = $this->criticalcss->get_option( 'key' ); | |
| 116 | + $ao_ccss_keyst = $this->criticalcss->get_option( 'keyst' ); | |
| 117 | + $ao_css_defer = $this->criticalcss->get_option( 'css_defer' ); | |
| 118 | + $ao_ccss_deferjquery = $this->criticalcss->get_option( 'deferjquery' ); | |
| 119 | + $ao_ccss_queue = $this->criticalcss->get_option( 'queue' ); | |
| 120 | + $ao_ccss_rules = $this->criticalcss->get_option( 'rules' ); | |
| 121 | + $ao_ccss_servicestatus = $this->criticalcss->get_option( 'servicestatus' ); | |
| 122 | + $ao_ccss_finclude = $this->criticalcss->get_option( 'finclude' ); | |
| 123 | + $ao_ccss_rtimelimit = $this->criticalcss->get_option( 'rtimelimit' ); | |
| 124 | + $ao_ccss_debug = $this->criticalcss->get_option( 'debug' ); | |
| 125 | + $ao_ccss_noptimize = $this->criticalcss->get_option( 'noptimize' ); | |
| 126 | + $ao_css_defer_inline = $this->criticalcss->get_option( 'css_defer_inline' ); | |
| 127 | + $ao_ccss_loggedin = $this->criticalcss->get_option( 'loggedin' ); | |
| 128 | + $ao_ccss_forcepath = $this->criticalcss->get_option( 'forcepath' ); | |
| 129 | + $ao_ccss_domain = $this->criticalcss->get_option( 'domain' ); | |
| 109 | 130 | ?> |
| 110 | - <script>document.title = "Autoptimize: <?php _e( 'Critical CSS', 'autoptimize' ); ?> " + document.title;</script> | |
| 131 | + <script>document.title = "Autoptimize: <?php esc_html_e( 'Critical CSS', 'autoptimize' ); ?> " + document.title;</script> | |
| 111 | 132 | <div class="wrap"> |
| 112 | 133 | <div id="autoptimize_main"> |
| 113 | 134 | <div id="ao_title_and_button"> |
| 114 | - <h1><?php _e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> | |
| 135 | + <h1><?php apply_filters( 'autoptimize_filter_settings_is_pro', false ) ? esc_html_e( 'Autoptimize Pro Settings', 'autoptimize' ) : esc_html_e( 'Autoptimize Settings', 'autoptimize' ); ?></h1> | |
| 115 | 136 | </div> |
| 116 | 137 | |
| 117 | 138 | <?php |
| 118 | 139 | // Print AO settings tabs. |
| @@ -117,41 +138,59 @@ | ||
| 117 | 138 | <?php |
| 118 | 139 | // Print AO settings tabs. |
| 119 | 140 | echo autoptimizeConfig::ao_admin_tabs(); |
| 120 | 141 | |
| 121 | - // Make sure dir to write ao_ccss exists and is writable. | |
| 122 | - if ( ! is_dir( AO_CCSS_DIR ) ) { | |
| 123 | - $mkdirresp = @mkdir( AO_CCSS_DIR, 0775, true ); // @codingStandardsIgnoreLine | |
| 124 | - $fileresp = file_put_contents( AO_CCSS_DIR . 'index.html', '<html><head><meta name="robots" content="noindex, nofollow"></head><body>Generated by <a href="http://wordpress.org/extend/plugins/autoptimize/" rel="nofollow">Autoptimize</a></body></html>' ); | |
| 125 | - if ( ( ! $mkdirresp ) || ( ! $fileresp ) ) { | |
| 126 | - ?> | |
| 127 | - <div class="notice-error notice"><p> | |
| 128 | - <?php | |
| 129 | - _e( 'Could not create the required directory. Make sure the webserver can write to the wp-content directory.', 'autoptimize' ); | |
| 130 | - ?> | |
| 131 | - </p></div> | |
| 132 | - <?php | |
| 133 | - } | |
| 142 | + if ( autoptimizeUtils::is_local_server() && isset( $ao_ccss_key ) ) { ?> | |
| 143 | + <div class="notice-warning notice"><p> | |
| 144 | + <?php | |
| 145 | + echo esc_html__( 'The Critical CSS service does not work on locally hosted sites or when the server is on a private network.', 'autoptimize' ); | |
| 146 | + ?> | |
| 147 | + </p></div> | |
| 148 | + <?php } | |
| 149 | + | |
| 150 | + $mkdirresult = $this->criticalcss->create_ao_ccss_dir(); | |
| 151 | + | |
| 152 | + // Warn if we could not create those files. | |
| 153 | + if ( ( true !== $mkdirresult ) ) { | |
| 154 | + ?> | |
| 155 | + <div class="notice-error notice"><p> | |
| 156 | + <?php | |
| 157 | + esc_html_e( 'Could not create the required directory. Make sure the webserver can write to the wp-content/uploads directory.', 'autoptimize' ); | |
| 158 | + ?> | |
| 159 | + </p></div> | |
| 160 | + <?php | |
| 134 | 161 | } |
| 135 | 162 | |
| 136 | - // Check for Autoptimize. | |
| 137 | - if ( ! empty( $ao_ccss_key ) && ! $ao_css_defer ) { | |
| 163 | + // Check if CSS optimization is on. | |
| 164 | + if ( 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_css' ) || 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' ) ) { | |
| 138 | 165 | ?> |
| 139 | - <div class="notice-error notice"><p> | |
| 166 | + <div class="notice-info notice"><p> | |
| 140 | 167 | <?php |
| 141 | - _e( "Oops! Please <strong>activate the \"Inline and Defer CSS\" option</strong> on Autoptimize's main settings page to use this power-up.", 'autoptimize' ); | |
| 168 | + esc_html_e( 'To be able to use Critical CSS you will have to enable CSS optimization and make sure "eliminate render-blocking CSS" is active on the main Autoptimize settings page.', 'autoptimize' ); | |
| 142 | 169 | ?> |
| 143 | 170 | </p></div> |
| 144 | 171 | <?php |
| 145 | - return; | |
| 146 | 172 | } |
| 147 | 173 | |
| 148 | - // check if WordPress cron is disabled and warn if so. | |
| 149 | - if ( ! empty( $ao_ccss_key ) && defined( 'DISABLE_WP_CRON' ) && DISABLE_WP_CRON && PAnD::is_admin_notice_active( 'i-know-about-disable-cron-forever' ) ) { | |
| 174 | + // Check for "inline & defer CSS" being active in Autoptimize. | |
| 175 | + if ( ! empty( $ao_ccss_key ) && ! $ao_css_defer && empty( $ao_ccss_keyst ) ) { | |
| 176 | + // no keystate so likely in activation-process of CCSS, let's enable "inline & defer CSS" immediately to make things easier! | |
| 177 | + autoptimizeOptionWrapper::update_option( 'autoptimize_css_defer', 'on' ); | |
| 150 | 178 | ?> |
| 151 | - <div data-dismissible="i-know-about-disable-cron-forever" class="notice-warning notice is-dismissible"><p> | |
| 179 | + <div class="notice-info notice"><p> | |
| 180 | + <?php | |
| 181 | + esc_html_e( 'The "Eliminate render-blocking CSS" option was activated to allow critical CSS to be used.', 'autoptimize' ); | |
| 182 | + ?> | |
| 183 | + </p></div> | |
| 184 | + <?php | |
| 185 | + } | |
| 186 | + | |
| 187 | + // check if defer jQuery is active and warn if so. | |
| 188 | + if ( 1 == $ao_ccss_deferjquery && PAnD::is_admin_notice_active( 'i-know-about-defer-inline-forever' ) ) { | |
| 189 | + ?> | |
| 190 | + <div data-dismissible="i-know-about-defer-inline-forever" class="notice-warning notice is-dismissible"><p> | |
| 152 | 191 | <?php |
| 153 | - _e( 'WordPress cron (for task scheduling) seems to be disabled. Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' ); | |
| 192 | + esc_html_e( 'You have "defer jQuery and other non-aggregated JS-files" active (under Advanced Settings), but that functionality is deprecated and will be removed in the next major version of Autoptimize. Consider using the new "Do not aggregate but defer" and "Also defer inline JS" options on the main settings page instead.', 'autoptimize' ); | |
| 154 | 193 | ?> |
| 155 | 194 | </p></div> |
| 156 | 195 | <?php |
| 157 | 196 | } |
| @@ -198,13 +237,13 @@ | ||
| 198 | 237 | // and set transient. |
| 199 | 238 | set_transient( 'ao_ccss_cronwarning', $_warn_cron, $_transient_multiplier * HOUR_IN_SECONDS ); |
| 200 | 239 | } |
| 201 | 240 | |
| 202 | - if ( ! empty( $ao_ccss_key ) && 'on' == $_warn_cron && PAnD::is_admin_notice_active( 'i-know-about-cron-1' ) ) { | |
| 241 | + if ( ! empty( $ao_ccss_key ) && 'on' == $_warn_cron && PAnD::is_admin_notice_active( 'i-know-about-cron-30' ) ) { | |
| 203 | 242 | ?> |
| 204 | - <div data-dismissible="i-know-about-cron-1" class="notice-warning notice is-dismissible"><p> | |
| 243 | + <div data-dismissible="i-know-about-cron-30" class="notice-warning notice is-dismissible"><p> | |
| 205 | 244 | <?php |
| 206 | - _e( 'It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://wordpress.org/plugins/autoptimize-criticalcss/faq/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' ); | |
| 245 | + _e( 'It looks like there might be a problem with WordPress cron (task scheduling). Have a look at <a href="https://blog.futtta.be/2023/03/17/how-to-fix-autoptimize-critical-css-cron-issue/" target="_blank">the FAQ</a> or the info in the Job Queue instructions if all jobs remain in "N" status and no rules are created.', 'autoptimize' ); | |
| 207 | 246 | ?> |
| 208 | 247 | </p></div> |
| 209 | 248 | <?php |
| 210 | 249 | } elseif ( ! empty( $ao_ccss_key ) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && ! $this->ao_ccss_has_autorules() ) { |
| @@ -210,9 +249,11 @@ | ||
| 210 | 249 | } elseif ( ! empty( $ao_ccss_key ) && '2' == $ao_ccss_keyst && 'on' != $_warn_cron && ! $this->ao_ccss_has_autorules() ) { |
| 211 | 250 | ?> |
| 212 | 251 | <div class="notice-success notice"><p> |
| 213 | 252 | <?php |
| 214 | - _e( 'Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize' ); | |
| 253 | + esc_html_e( 'Great, Autoptimize will now automatically start creating new critical CSS rules, you should see those appearing below in the next couple of hours.', 'autoptimize' ); | |
| 254 | + echo ' '; | |
| 255 | + _e( 'In the meantime you might want to <strong>edit default rule CSS now</strong>, to avoid all CSS being inlined when no (applicable) rules are found.', 'autoptimize' ); | |
| 215 | 256 | ?> |
| 216 | 257 | </p></div> |
| 217 | 258 | <?php |
| 218 | 259 | } |
| @@ -221,14 +262,27 @@ | ||
| 221 | 262 | if ( ! empty( $ao_ccss_key ) && ! empty( $ao_ccss_servicestatus ) && is_array( $ao_ccss_servicestatus ) && 'down' === $ao_ccss_servicestatus['critcss']['status'] ) { |
| 222 | 263 | ?> |
| 223 | 264 | <div class="notice-warning notice"><p> |
| 224 | 265 | <?php |
| 225 | - _e( 'The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize' ); | |
| 266 | + esc_html_e( 'The critical CSS service has been reported to be down. Although no new rules will be created for now, this does not prevent existing rules from being applied.', 'autoptimize' ); | |
| 226 | 267 | ?> |
| 227 | 268 | </p></div> |
| 228 | 269 | <?php |
| 229 | 270 | } |
| 230 | 271 | |
| 272 | + // warn if too many rules (based on length of ao_ccss_rules option) as that might cause issues at e.g. wpengine | |
| 273 | + // see https://wpengine.com/support/database-optimization-best-practices/#Autoloaded_Data . | |
| 274 | + $_raw_rules_length = strlen( get_option( 'autoptimize_ccss_rules', '' ) ); | |
| 275 | + if ( $_raw_rules_length > apply_filters( 'autoptimize_ccss_rules_length_warning', 500000 ) ) { | |
| 276 | + ?> | |
| 277 | + <div class="notice-warning notice"><p> | |
| 278 | + <?php | |
| 279 | + esc_html_e( 'It looks like the amount of Critical CSS rules is very high, it is recommended to reconfigure Autoptimize (e.g. by manually creating broader rules) to ensure less rules are created.', 'autoptimize' ); | |
| 280 | + ?> | |
| 281 | + </p></div> | |
| 282 | + <?php | |
| 283 | + } | |
| 284 | + | |
| 231 | 285 | // Settings Form. |
| 232 | 286 | ?> |
| 233 | 287 | <form id="settings" method="post" action="options.php"> |
| 234 | 288 | <?php |
| @@ -234,9 +288,9 @@ | ||
| 234 | 288 | <?php |
| 235 | 289 | settings_fields( 'ao_ccss_options_group' ); |
| 236 | 290 | |
| 237 | 291 | // Get API key status. |
| 238 | - $key = autoptimizeCriticalCSSCore::ao_ccss_key_status( true ); | |
| 292 | + $key = $this->criticalcss->key_status( true ); | |
| 239 | 293 | |
| 240 | 294 | if ( $this->is_multisite_network_admin() ) { |
| 241 | 295 | ?> |
| 242 | 296 | <ul id="key-panel"> |
| @@ -242,15 +296,15 @@ | ||
| 242 | 296 | <ul id="key-panel"> |
| 243 | 297 | <li class="itemDetail"> |
| 244 | 298 | <?php |
| 245 | 299 | // translators: the placesholder is for a line of code in wp-config.php. |
| 246 | - echo sprintf( __( '<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize' ), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>' ); | |
| 300 | + echo sprintf( esc_html__( '<p>Critical CSS settings cannot be set at network level as critical CSS is specific to each sub-site.</p><p>You can however provide the critical CSS API key for use by all sites by adding this your wp-config.php as %s</p>', 'autoptimize' ), '<br/><code>define(\'AUTOPTIMIZE_CRITICALCSS_API_KEY\', \'eyJhbGmorestringsherexHa7MkOQFtDFkZgLmBLe-LpcHx4\');</code>' ); | |
| 247 | 301 | ?> |
| 248 | 302 | </li> |
| 249 | 303 | </ul> |
| 250 | 304 | <?php |
| 251 | 305 | } else { |
| 252 | - if ( 'valid' == $key['status'] ) { | |
| 306 | + if ( 'valid' == $key['status'] || ( defined( 'AO_PRO_VERSION' ) && has_filter( 'autoptimize_filter_ccss_key' ) ) ) { | |
| 253 | 307 | // If key status is valid, render other panels. |
| 254 | 308 | // Render rules section. |
| 255 | 309 | ao_ccss_render_rules(); |
| 256 | 310 | // Render queue section. |
| @@ -257,33 +311,40 @@ | ||
| 257 | 311 | ao_ccss_render_queue(); |
| 258 | 312 | // Render advanced panel. |
| 259 | 313 | ao_ccss_render_adv(); |
| 260 | 314 | } else { |
| 315 | + if ( apply_filters( 'autoptimize_filter_ccss_rules_without_api', true ) ) { | |
| 316 | + // Render rules section for manual rules. | |
| 317 | + ao_ccss_render_rules(); | |
| 318 | + } else { | |
| 319 | + echo "<input class='hidden' name='autoptimize_ccss_rules' value='" . esc_attr( json_encode( $ao_ccss_rules, JSON_FORCE_OBJECT ) ) . "'>"; | |
| 320 | + } | |
| 321 | + | |
| 261 | 322 | // But if key is other than valid, add hidden fields to persist settings when submitting form |
| 262 | 323 | // Show explanation of why and how to get a API key. |
| 263 | 324 | ao_ccss_render_explain(); |
| 264 | 325 | |
| 265 | 326 | // Get viewport size. |
| 266 | - $viewport = autoptimizeCriticalCSSCore::ao_ccss_viewport(); | |
| 327 | + $viewport = $this->criticalcss->viewport(); | |
| 267 | 328 | |
| 268 | 329 | // Add hidden fields. |
| 269 | - echo "<input class='hidden' name='autoptimize_ccss_rules' value='" . $ao_ccss_rules_raw . "'>"; | |
| 270 | - echo "<input class='hidden' name='autoptimize_ccss_queue' value='" . $ao_ccss_queue_raw . "'>"; | |
| 271 | - echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="' . $viewport['w'] . '">'; | |
| 272 | - echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="' . $viewport['h'] . '">'; | |
| 273 | - echo '<input class="hidden" name="autoptimize_ccss_finclude" value="' . $ao_ccss_finclude . '">'; | |
| 274 | - echo '<input class="hidden" name="autoptimize_ccss_rlimit" value="' . $ao_ccss_rlimit . '">'; | |
| 275 | - echo '<input class="hidden" name="autoptimize_ccss_debug" value="' . $ao_ccss_debug . '">'; | |
| 276 | - echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="' . $ao_ccss_noptimize . '">'; | |
| 330 | + echo "<input class='hidden' name='autoptimize_ccss_queue' value='" . esc_attr( json_encode( $ao_ccss_queue, JSON_FORCE_OBJECT ) ) . "'>"; | |
| 331 | + echo '<input class="hidden" name="autoptimize_ccss_viewport[w]" value="' . esc_attr( $viewport['w'] ) . '">'; | |
| 332 | + echo '<input class="hidden" name="autoptimize_ccss_viewport[h]" value="' . esc_attr( $viewport['h'] ) . '">'; | |
| 333 | + echo '<input class="hidden" name="autoptimize_ccss_finclude" value="' . esc_attr( $ao_ccss_finclude ) . '">'; | |
| 334 | + echo '<input class="hidden" name="autoptimize_ccss_rtimelimit" value="' . esc_attr( $ao_ccss_rtimelimit ) . '">'; | |
| 335 | + echo '<input class="hidden" name="autoptimize_ccss_debug" value="' . esc_attr( $ao_ccss_debug ) . '">'; | |
| 336 | + echo '<input class="hidden" name="autoptimize_ccss_noptimize" value="' . esc_attr( $ao_ccss_noptimize ) . '">'; | |
| 277 | 337 | echo '<input class="hidden" name="autoptimize_css_defer_inline" value="' . esc_attr( $ao_css_defer_inline ) . '">'; |
| 278 | - echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="' . $ao_ccss_loggedin . '">'; | |
| 279 | - echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="' . $ao_ccss_forcepath . '">'; | |
| 338 | + echo '<input class="hidden" name="autoptimize_ccss_loggedin" value="' . esc_attr( $ao_ccss_loggedin ) . '">'; | |
| 339 | + echo '<input class="hidden" name="autoptimize_ccss_forcepath" value="' . esc_attr( $ao_ccss_forcepath ) . '">'; | |
| 340 | + echo '<input class="hidden" name="autoptimize_ccss_domain" id="autoptimize_ccss_domain" value="' . esc_attr( $ao_ccss_domain ) . '">'; | |
| 280 | 341 | } |
| 281 | 342 | // Render key panel unconditionally. |
| 282 | 343 | ao_ccss_render_key( $ao_ccss_key, $key['status'], $key['stmsg'], $key['msg'], $key['color'] ); |
| 283 | 344 | ?> |
| 284 | 345 | <p class="submit left"> |
| 285 | - <input type="submit" class="button-primary" value="<?php _e( 'Save Changes', 'autoptimize' ); ?>" /> | |
| 346 | + <input type="submit" class="button-primary" value="<?php esc_html_e( 'Save Changes', 'autoptimize' ); ?>" /> | |
| 286 | 347 | </p> |
| 287 | 348 | <?php |
| 288 | 349 | } |
| 289 | 350 | ?> |
| @@ -299,11 +360,11 @@ | ||
| 299 | 360 | return String.fromCharCode((letter <= 'Z' ? 90 : 122) >= (letter = letter.charCodeAt(0) + itype) ? letter : letter - 26); |
| 300 | 361 | }); |
| 301 | 362 | } |
| 302 | 363 | </script> |
| 303 | - <form id="importSettingsForm"<?php if ( $this->is_multisite_network_admin() ) { echo ' class="hidden"'; } ?>> | |
| 304 | - <span id="exportSettings" class="button-secondary"><?php _e( 'Export Settings', 'autoptimize' ); ?></span> | |
| 305 | - <input class="button-secondary" id="importSettings" type="button" value="<?php _e( 'Import Settings', 'autoptimize' ); ?>" onclick="upload();return false;" /> | |
| 364 | + <form id="importSettingsForm"<?php if ( $this->is_multisite_network_admin() ) { echo ' class="hidden"'; } // @codingStandardsIgnoreLine ?>> | |
| 365 | + <span id="exportSettings" class="button-secondary"><?php esc_html_e( 'Export Settings', 'autoptimize' ); ?></span> | |
| 366 | + <input class="button-secondary" id="importSettings" type="button" value="<?php esc_html_e( 'Import Settings', 'autoptimize' ); ?>" onclick="upload();return false;" /> | |
| 306 | 367 | <input class="button-secondary" id="settingsfile" name="settingsfile" type="file" /> |
| 307 | 368 | </form> |
| 308 | 369 | <div id="importdialog"></div> |
| 309 | 370 | </div><!-- /#autoptimize_main --> |
| @@ -311,16 +372,18 @@ | ||
| 311 | 372 | <?php |
| 312 | 373 | if ( ! $this->is_multisite_network_admin() ) { |
| 313 | 374 | // Include debug panel if debug mode is enable. |
| 314 | 375 | if ( $ao_ccss_debug ) { |
| 315 | - ?> | |
| 376 | + ?> | |
| 316 | 377 | <div id="debug"> |
| 317 | 378 | <?php |
| 318 | 379 | // Include debug panel. |
| 319 | - include( 'critcss-inc/admin_settings_debug.php' ); | |
| 380 | + if ( true === apply_filters( 'autoptimize_filter_ccss_debug_browser_output', true ) ) { | |
| 381 | + include( 'critcss-inc/admin_settings_debug.php' ); | |
| 382 | + } | |
| 320 | 383 | ?> |
| 321 | 384 | </div><!-- /#debug --> |
| 322 | - <?php | |
| 385 | + <?php | |
| 323 | 386 | } |
| 324 | 387 | echo '<script>'; |
| 325 | 388 | include( 'critcss-inc/admin_settings_rules.js.php' ); |
| 326 | 389 | include( 'critcss-inc/admin_settings_queue.js.php' ); |
| @@ -328,13 +391,13 @@ | ||
| 328 | 391 | echo '</script>'; |
| 329 | 392 | } |
| 330 | 393 | } |
| 331 | 394 | |
| 332 | - public static function ao_ccss_has_autorules() { | |
| 395 | + public function ao_ccss_has_autorules() { | |
| 333 | 396 | static $_has_auto_rules = null; |
| 334 | 397 | |
| 335 | 398 | if ( null === $_has_auto_rules ) { |
| 336 | - global $ao_ccss_rules; | |
| 399 | + $ao_ccss_rules = $this->criticalcss->get_option( 'rules' ); | |
| 337 | 400 | $_has_auto_rules = false; |
| 338 | 401 | if ( ! empty( $ao_ccss_rules ) ) { |
| 339 | 402 | foreach ( array( 'types', 'paths' ) as $_typat ) { |
| 340 | 403 | foreach ( $ao_ccss_rules[ $_typat ] as $rule ) { |
| @@ -353,9 +416,9 @@ | ||
| 353 | 416 | |
| 354 | 417 | return $_has_auto_rules; |
| 355 | 418 | } |
| 356 | 419 | |
| 357 | - public function is_multisite_network_admin() { | |
| 420 | + public static function is_multisite_network_admin() { | |
| 358 | 421 | static $_multisite_network_admin = null; |
| 359 | 422 | |
| 360 | 423 | if ( null === $_multisite_network_admin ) { |
| 361 | 424 | if ( is_multisite() && is_network_admin() ) { |