| @@ -7,10 +7,15 @@ | ||
| 7 | 7 | * Main function to render the rules panel. |
| 8 | 8 | */ |
| 9 | 9 | function ao_ccss_render_rules() { |
| 10 | 10 | // Attach required arrays. |
| 11 | - global $ao_ccss_rules; | |
| 12 | - global $ao_ccss_types; | |
| 11 | + $criticalcss = autoptimize()->criticalcss(); | |
| 12 | + $ao_ccss_rules = $criticalcss->get_option( 'rules' ); | |
| 13 | + $ao_ccss_types = $criticalcss->get_types(); | |
| 14 | + | |
| 15 | + if ( empty( $ao_ccss_types ) || ! is_array( $ao_ccss_types ) ) { | |
| 16 | + $ao_ccss_types = array( 'No conditionals, check CSS optimization settings.' ); | |
| 17 | + } | |
| 13 | 18 | ?> |
| 14 | 19 | <ul id="rules-panel"> |
| 15 | 20 | <li class="itemDetail"> |
| 16 | 21 | <h2 class="itemTitle"><?php _e( 'Rules', 'autoptimize' ); ?></h2> |
| @@ -149,24 +154,20 @@ | ||
| 149 | 154 | </div> |
| 150 | 155 | |
| 151 | 156 | <!-- Add/edit default critical CSS dialog --> |
| 152 | 157 | <div id="default_critcss_wrapper" class="hidden"> |
| 153 | - <textarea id="dummyDefault" rows="19" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your MINIFIED default critical CSS here and hit submit to save. This is the critical CSS to be used for every page NOT MATCHING any rule.', 'autoptimize' ); ?>"></textarea> | |
| 158 | + <textarea id="dummyDefault" rows="19" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your minified default critical CSS here and hit submit to save. This is the critical CSS to be used for every page not matching any rule.', 'autoptimize' ); ?>"></textarea> | |
| 154 | 159 | </div> |
| 155 | 160 | |
| 156 | 161 | <!-- Add/edit additional critical CSS dialog --> |
| 157 | 162 | <div id="additional_critcss_wrapper" class="hidden"> |
| 158 | - <textarea id="dummyAdditional" rows="19" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your MINIFIED additional critical CSS here and hit submit to save. This is the CSS to be added AT THE END of every critical CSS provided by a matching rule, or the default one.', 'autoptimize' ); ?>"></textarea> | |
| 163 | + <textarea id="dummyAdditional" rows="19" cols="10" style="width:100%;" placeholder="<?php _e( 'Paste your minified additional critical CSS here and hit submit to save. This is the CSS to be added AT THE END of every critical CSS provided by a matching rule, or the default one.', 'autoptimize' ); ?>"></textarea> | |
| 159 | 164 | </div> |
| 160 | 165 | |
| 161 | - <!-- Wrapper for in screen notices --> | |
| 162 | - <div id="rules-notices"></div> | |
| 163 | - <!-- END Rule add/edit dialogs --> | |
| 164 | - | |
| 165 | 166 | <!-- BEGIN Rules UI --> |
| 166 | 167 | <div class="howto"> |
| 167 | 168 | <div class="title-wrap"> |
| 168 | - <h4 class="title"><?php _e( 'How To Use Autoptimize CriticalCSS Power-Up Rules', 'autoptimize' ); ?></h4> | |
| 169 | + <h4 class="title"><?php _e( 'How To Use Autoptimize CriticalCSS Rules', 'autoptimize' ); ?></h4> | |
| 169 | 170 | <p class="subtitle"><?php _e( 'Click the side arrow to toggle instructions', 'autoptimize' ); ?></p> |
| 170 | 171 | </div> |
| 171 | 172 | <button type="button" class="toggle-btn"> |
| 172 | 173 | <span class="toggle-indicator dashicons dashicons-arrow-up dashicons-arrow-down"></span> |
| @@ -173,23 +174,24 @@ | ||
| 173 | 174 | </button> |
| 174 | 175 | <div class="howto-wrap hidden"> |
| 175 | 176 | <p><?php _e( "TL;DR:<br />Critical CSS files from <span class='badge auto'>AUTO</span> <strong>rules are updated automatically</strong> while from <span class='badge manual'>MANUAL</span> <strong>rules are not.</strong>", 'autoptimize' ); ?></p> |
| 176 | 177 | <ol> |
| 177 | - <li><?php _e( 'When a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key is in place, Autoptimize CriticalCSS Power-Up starts to operate <strong>automatically</strong>.', 'autoptimize' ); ?></li> | |
| 178 | + <li><?php _e( 'When a valid <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> API key is in place, Autoptimize starts to operate <strong>automatically</strong>.', 'autoptimize' ); ?></li> | |
| 178 | 179 | <li><?php _e( 'Upon a request to any of the frontend pages made by a <strong>not logged in user</strong>, it will <strong>asynchronously</strong> fetch and update the critical CSS from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for conditional tags you have on your site (e.g. is_page, is_single, is_archive etc.)', 'autoptimize' ); ?></li> |
| 179 | 180 | <li><?php _e( 'These requests also creates an <span class="badge auto">AUTO</span> rule for you. The critical CSS files from <span class="badge auto">AUTO</span> <strong>rules are updated automatically</strong> when a CSS file in your theme or frontend plugins changes.', 'autoptimize' ); ?></li> |
| 180 | 181 | <li><?php _e( 'If you want to make any fine tunning in the critical CSS file of an <span class="badge auto">AUTO</span> rule, click on "Edit" button of that rule, change what you need, submit and save it. The rule you\'ve just edited becomes a <span class="badge manual">MANUAL</span> rule then.', 'autoptimize' ); ?></li> |
| 181 | 182 | <li><?php _e( 'You can create <span class="badge manual">MANUAL</span> rules for specific page paths (URL). Longer, more specific paths have higher priority over shorter ones, which in turn have higher priority over <span class="badge auto">AUTO</span> rules. Also, critical CSS files from <span class="badge manual">MANUAL</span> <strong>rules are NEVER updated automatically.</strong>', 'autoptimize' ); ?></li> |
| 182 | - <li><?php _e( 'You can also create an <span class="badge auto">AUTO</span> rule for a path by leaving its critical CSS content empty. The critical CSS for that path will be automatically fetched from <a href="https://criticalcss.com/?aff=1" target="_blank">criticalcss.com</a> for you and updated whenever it changes.', 'autoptimize' ); ?></li> | |
| 183 | - <li><?php _e( "If you see an <span class='badge auto'>AUTO</span> rule with a <span class='badge review'>R</span> besides it (R is after REVIEW), it means that the fetched critical CSS for that rule is not 100% garanteed to work according to <a href='https://criticalcss.com/?aff=1' target='_blank'>criticalcss.com</a> analysis. It's advised that you edit and review that rule to make any required adjustments.", 'autoptimize' ); ?></li> | |
| 184 | 183 | <li><?php _e( 'At any time you can delete an <span class="badge auto">AUTO</span> or <span class="badge manual">MANUAL</span> rule by cliking on "Remove" button of the desired rule and saving your changes.', 'autoptimize' ); ?></li> |
| 185 | 184 | </ol> |
| 186 | 185 | </div> |
| 187 | 186 | </div> |
| 188 | - <textarea id="autoptimize_css_defer_inline" name="autoptimize_css_defer_inline" rows="19" cols="10" style="width:100%;"><?php echo get_option( 'autoptimize_css_defer_inline', '' ); ?></textarea> | |
| 189 | - <textarea id="autoptimize_ccss_additional" name="autoptimize_ccss_additional" rows="19" cols="10" style="width:100%;"><?php echo get_option( 'autoptimize_ccss_additional', '' ); ?></textarea> | |
| 187 | + <textarea id="autoptimize_css_defer_inline" name="autoptimize_css_defer_inline" rows="19" cols="10" style="width:100%;"><?php echo autoptimizeStyles::sanitize_css( get_option( 'autoptimize_css_defer_inline', '' ) ); ?></textarea> | |
| 188 | + <textarea id="autoptimize_ccss_additional" name="autoptimize_ccss_additional" rows="19" cols="10" style="width:100%;"><?php echo autoptimizeStyles::sanitize_css( get_option( 'autoptimize_ccss_additional', '' ) ); ?></textarea> | |
| 190 | 189 | <table class="rules-list" cellspacing="0"><tbody id="rules-list"></tbody></table> |
| 191 | 190 | <input class="hidden" type="text" id="critCssOrigin" name="autoptimize_ccss_rules" value='<?php echo ( json_encode( $ao_ccss_rules, JSON_FORCE_OBJECT ) ); ?>'> |
| 191 | + <!-- Wrapper for in screen notices --> | |
| 192 | + <div id="rules-notices"></div> | |
| 193 | + <!-- END Rule add/edit dialogs --> | |
| 192 | 194 | <div class="submit rules-btn"> |
| 193 | 195 | <div class="alignleft"> |
| 194 | 196 | <span id="addCritCssButton" class="button-secondary"><?php _e( 'Add New Rule', 'autoptimize' ); ?></span> |
| 195 | 197 | <span id="editDefaultButton" class="button-secondary"><?php _e( 'Edit Default Rule CSS', 'autoptimize' ); ?></span> |