Skip to content

Commit

Permalink
this will be 2.7.2
Browse files Browse the repository at this point in the history
  • Loading branch information
futtta committed May 20, 2020
1 parent 6fcb0f2 commit ff22b73
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 35 deletions.
4 changes: 2 additions & 2 deletions autoptimize.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Plugin Name: Autoptimize
* Plugin URI: https://autoptimize.com/
* Description: Makes your site faster by optimizing CSS, JS, Images, Google fonts and more.
* Version: 2.7.1
* Version: 2.7.2
* Author: Frank Goossens (futtta)
* Author URI: https://autoptimize.com/
* Text Domain: autoptimize
Expand All @@ -20,7 +20,7 @@
exit;
}

define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.7.1' );
define( 'AUTOPTIMIZE_PLUGIN_VERSION', '2.7.2' );

// plugin_dir_path() returns the trailing slash!
define( 'AUTOPTIMIZE_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
Expand Down
4 changes: 2 additions & 2 deletions classes/autoptimizeCriticalCSSBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public function load_requires() {

public static function fetch_options() {
// Get options.
$autoptimize_ccss_options['ao_css_defer'] = get_option( 'autoptimize_css_defer' );
$autoptimize_ccss_options['ao_css_defer_inline'] = get_option( 'autoptimize_css_defer_inline' );
$autoptimize_ccss_options['ao_css_defer'] = autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer' );
$autoptimize_ccss_options['ao_css_defer_inline'] = autoptimizeOptionWrapper::get_option( 'autoptimize_css_defer_inline' );
$autoptimize_ccss_options['ao_ccss_rules_raw'] = get_option( 'autoptimize_ccss_rules', false );
$autoptimize_ccss_options['ao_ccss_additional'] = get_option( 'autoptimize_ccss_additional' );
$autoptimize_ccss_options['ao_ccss_queue_raw'] = get_option( 'autoptimize_ccss_queue', false );
Expand Down
26 changes: 19 additions & 7 deletions classes/autoptimizeCriticalCSSCore.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ public function ao_ccss_frontend( $inlined ) {
// Only if keystatus is OK and option to add CCSS for logged on users is on or user is not logged in.
if ( ( $ao_ccss_keyst && 2 == $ao_ccss_keyst ) && ( $ao_ccss_loggedin || ! is_user_logged_in() ) ) {
// Check for a valid CriticalCSS based on path to return its contents.
$req_path = strtok( urldecode( $_SERVER['REQUEST_URI'] ), '?' );
$req_path = strtok( $_SERVER['REQUEST_URI'], '?' );
if ( ! empty( $ao_ccss_rules['paths'] ) ) {
foreach ( $ao_ccss_rules['paths'] as $path => $rule ) {
// explicit match OR partial match if MANUAL rule.
if ( $req_path == $path || ( false == $rule['hash'] && false != $rule['file'] && strpos( $req_path, str_replace( site_url(), '', $path ) ) !== false ) ) {
if ( $req_path == $path || urldecode( $req_path ) == $path || ( false == $rule['hash'] && false != $rule['file'] && strpos( $req_path, str_replace( site_url(), '', $path ) ) !== false ) ) {
if ( file_exists( AO_CCSS_DIR . $rule['file'] ) ) {
$_ccss_contents = file_get_contents( AO_CCSS_DIR . $rule['file'] );
if ( 'none' != $_ccss_contents ) {
Expand Down Expand Up @@ -407,26 +407,38 @@ public static function ao_ccss_key_status( $render ) {
}

public function ao_ccss_key_validation( $key ) {
global $ao_ccss_noptimize;

// POST a dummy job to criticalcss.com to check for key validation
// Prepare home URL for the request.
$src_url = get_home_url();

// Avoid AO optimizations if required by config or avoid lazyload if lazyload is active in AO.
if ( ! empty( $ao_ccss_noptimize ) ) {
$src_url .= '?ao_noptirocket=1';
} elseif ( class_exists( 'autoptimizeImages', false ) && autoptimizeImages::should_lazyload_wrapper() ) {
$src_url .= '?ao_nolazy=1';
}

$src_url = apply_filters( 'autoptimize_filter_ccss_cron_srcurl', $src_url );

// Prepare the request.
$url = esc_url_raw( AO_CCSS_API . 'generate' );
$args = array(
'headers' => array(
'User-Agent' => 'Autoptimize CriticalCSS Power-Up v' . AO_CCSS_VER,
'User-Agent' => 'Autoptimize v' . AO_CCSS_VER,
'Content-type' => 'application/json; charset=utf-8',
'Authorization' => 'JWT ' . $key,
'Connection' => 'close',
),
// Body must be JSON.
'body' => json_encode(
array(
'url' => $src_url,
'aff' => 1,
'aocssv' => AO_CCSS_VER,
apply_filters( 'autoptimize_ccss_cron_api_generate_body',
array(
'url' => $src_url,
'aff' => 1,
'aocssv' => AO_CCSS_VER,
)
)
),
);
Expand Down
3 changes: 3 additions & 0 deletions classes/autoptimizeCriticalCSSCron.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,9 @@ public function ao_ccss_api_generate( $path, $debug, $dcode ) {
$body['forceInclude'] = $finclude;
}

// Add filter to allow the body array to be altered (e.g. to add customPageHeaders).
$body = apply_filters( 'autoptimize_ccss_cron_api_generate_body', $body );

// Body must be json and log it.
$body = json_encode( $body );
autoptimizeCriticalCSSCore::ao_ccss_log( 'criticalcss.com: POST generate request body is ' . $body, 3 );
Expand Down
9 changes: 6 additions & 3 deletions classes/autoptimizeCriticalCSSEnqueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public static function ao_ccss_enqueue( $hash ) {
}

// Match for types in rules if no path rule matches and if we're not enforcing paths.
if ( ! $job_qualify && ( ! $ao_ccss_forcepath || ! in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) ) ) {
if ( ! $job_qualify && ( ! $ao_ccss_forcepath || ! in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) || ! apply_filters( 'autoptimize_filter_ccss_coreenqueue_ignorealltypes', false ) ) ) {
foreach ( $ao_ccss_rules['types'] as $type => $props ) {

// Prepare rule target and log.
Expand Down Expand Up @@ -103,7 +103,7 @@ public static function ao_ccss_enqueue( $hash ) {
// Should we switch to path-base AUTO-rules? Conditions:
// 1. forcepath option has to be enabled (off by default)
// 2. request type should be (by default, but filterable) one of is_page (removed for now: woo_is_product or woo_is_product_category).
if ( $ao_ccss_forcepath && in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) ) {
if ( ( $ao_ccss_forcepath && in_array( $req_type, apply_filters( 'autoptimize_filter_ccss_coreenqueue_forcepathfortype', array( 'is_page' ) ) ) ) || apply_filters( 'autoptimize_filter_ccss_coreenqueue_ignorealltypes', false ) ) {
if ( '/' !== $req_path ) {
$target_rule = 'paths|' . $req_path;
} else {
Expand Down Expand Up @@ -195,7 +195,10 @@ public function ao_ccss_get_type() {

// Iterates over the array to match a type.
foreach ( $ao_ccss_types as $type ) {
if ( strpos( $type, 'custom_post_' ) !== false ) {
if ( is_404() ) {
$page_type = 'is_404';
break;
} elseif ( strpos( $type, 'custom_post_' ) !== false ) {
// Match custom post types.
if ( get_post_type( get_the_ID() ) === substr( $type, 12 ) ) {
$page_type = $type;
Expand Down
2 changes: 1 addition & 1 deletion classes/autoptimizeImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ public function lazyload_bgimg_callback( $matches ) {
// replace background-image URL with SVG placeholder.
$out = str_replace( $matches[2], $placeholder, $matches[0] );
// add data-bg attribute with real background-image URL for lazyload to pick up.
$out = str_replace( $matches[1], $matches[1] . ' data-bg="' . trim( str_replace( "\r\n", '', $matches[2] ) ) . '"', $out );
$out = str_replace( $matches[1], $matches[1] . ' data-bg="' . trim( str_replace( array( "\r\n", '"' ), '', $matches[2] ) ) . '"', $out );
// add lazyload class to tag.
$out = $this->inject_classes_in_tag( $out, "$lazyload_class " );
return $out;
Expand Down
30 changes: 18 additions & 12 deletions classes/autoptimizeMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,17 +334,6 @@ public static function should_buffer( $doing_tests = false )
}
}

// also honor PageSpeed=off parameter as used by mod_pagespeed, in use by some pagebuilders,
// see https://www.modpagespeed.com/doc/experiment#ModPagespeed for info on that.
if ( false === $ao_noptimize && array_key_exists( 'PageSpeed', $_GET ) && 'off' === $_GET['PageSpeed'] ) {
$ao_noptimize = true;
}

// and make sure Thrive editor doesn't get optimized HTML.
if ( false === $ao_noptimize && array_key_exists( 'tve', $_GET ) && 'true' === $_GET['tve'] ) {
$ao_noptimize = true;
}

// If setting says not to optimize logged in user and user is logged in...
if ( false === $ao_noptimize && 'on' !== autoptimizeOptionWrapper::get_option( 'autoptimize_optimize_logged', 'on' ) && is_user_logged_in() && current_user_can( 'edit_posts' ) ) {
$ao_noptimize = true;
Expand All @@ -361,7 +350,24 @@ public static function should_buffer( $doing_tests = false )
}
}

// Allows blocking of autoptimization on your own terms regardless of above decisions.
// And make sure pagebuilder previews don't get optimized HTML/ JS/ CSS/ ...
if ( false === $ao_noptimize ) {
$_qs_pagebuilders = array( 'tve', 'elementor-preview', 'fl_builder', 'vc_action', 'et_fb', 'bt-beaverbuildertheme', 'ct_builder', 'fb-edit', 'siteorigin_panels_live_editor' );
foreach ( $_qs_pagebuilders as $_pagebuilder ) {
if ( array_key_exists( $_pagebuilder, $_GET ) ) {
$ao_noptimize = true;
break;
}
}
}

// Also honor PageSpeed=off parameter as used by mod_pagespeed, in use by some pagebuilders,
// see https://www.modpagespeed.com/doc/experiment#ModPagespeed for info on that.
if ( false === $ao_noptimize && array_key_exists( 'PageSpeed', $_GET ) && 'off' === $_GET['PageSpeed'] ) {
$ao_noptimize = true;
}

// And finally allows blocking of autoptimization on your own terms regardless of above decisions.
$ao_noptimize = (bool) apply_filters( 'autoptimize_filter_noptimize', $ao_noptimize );

// Check for site being previewed in the Customizer (available since WP 4.0).
Expand Down
2 changes: 1 addition & 1 deletion classes/autoptimizeStyles.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public function read( $options )
private function optionally_defer_excluded( $tag, $url = '' )
{
// Defer single CSS if "inline & defer" is ON and there is inline CSS.
if ( ! empty( $tag ) && $this->defer && ! empty( $this->defer_inline ) && apply_filters( 'autoptimize_filter_css_defer_excluded', true, $tag ) ) {
if ( ! empty( $tag ) && false === strpos( $tag, ' onload=' ) && $this->defer && ! empty( $this->defer_inline ) && apply_filters( 'autoptimize_filter_css_defer_excluded', true, $tag ) ) {
// Get/ set (via filter) the JS to be triggers onload of the preloaded CSS.
$_preload_onload = apply_filters(
'autoptimize_filter_css_preload_onload',
Expand Down
2 changes: 1 addition & 1 deletion classes/critcss-inc/admin_settings_key.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function ao_ccss_render_key( $key, $status, $status_msg, $message, $color ) {
<td>
<textarea id="autoptimize_ccss_key" name="autoptimize_ccss_key" rows='3' style="width:100%;" placeholder="<?php _e( 'Please enter your criticalcss.com API key here.', 'autoptimize' ); ?>"><?php echo trim( $key ); ?></textarea>
<p class="notes">
<?php _e( 'Enter your <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> API key above. The key is revalidated every time a new job is sent to it.<br />To obtain your API key, go to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> > Account > API Keys.<br />Requests to generate a critical CSS via the API are priced at £5 per domain per month.<br /><strong>Not sure yet? With the <a href="https://criticalcss.com/faq/?aff=1#trial" target="_blank">30 day free trial</a>, you have nothing to lose!</strong>', 'autoptimize' ); ?>
<?php _e( 'Enter your <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> API key above. The key is revalidated every time a new job is sent to it.<br />To obtain your API key, go to <a href="https://criticalcss.com/account/api-keys?aff=1" target="_blank">criticalcss.com</a> > Account > API Keys.<br />Requests to generate a critical CSS via the API are priced at £5 per domain per month.<br /><strong>Not sure yet? With the <a href="https://criticalcss.com/faq/?aff=1#trial" target="_blank">30 day money back guarantee</a>, you have nothing to lose!</strong>', 'autoptimize' ); ?>
</p>
</td>
</tr>
Expand Down
8 changes: 4 additions & 4 deletions classes/critcss-inc/admin_settings_queue.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,12 @@ function delJob(queue, jid, jpath) {
height: 180,
modal: true,
buttons: {
<?php _e( 'Delete', 'autoptimize' ); ?>: function() {
"<?php _e( 'Delete', 'autoptimize' ); ?>": function() {
delete queue[jpath];
updateQueue(queue);
jQuery(this).dialog('close' );
},
<?php _e( 'Cancel', 'autoptimize' ); ?>: function() {
"<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
jQuery(this).dialog('close' );
}
}
Expand Down Expand Up @@ -172,7 +172,7 @@ function retryJob(queue, jid, jpath) {
height: 180,
modal: true,
buttons: {
<?php _e( 'Retry', 'autoptimize' ); ?>: function() {
"<?php _e( 'Retry', 'autoptimize' ); ?>": function() {
<?php
if ( $ao_ccss_debug ) {
echo "console.log( 'SHOULD retry job:', jid[0], jpath );\n";
Expand All @@ -187,7 +187,7 @@ function retryJob(queue, jid, jpath) {
updateQueue(queue);
jQuery(this).dialog('close' );
},
<?php _e( 'Cancel', 'autoptimize' ); ?>: function() {
"<?php _e( 'Cancel', 'autoptimize' ); ?>": function() {
jQuery(this).dialog('close' );
}
}
Expand Down
7 changes: 6 additions & 1 deletion classes/critcss-inc/admin_settings_rules.js.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ function drawTable(critCssArray) {
rmark = '';
}
}
jQuery("#rules-list").append("<tr class='rule "+k+"Rule'><td class='type'><span class='badge " + typeClass + "'>" + type + "</span>" + rmark + "</td><td class='target'>" + i.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'') + "</td><td class='file'>" + file + "</td><td class='btn edit'><span class=\"button-secondary\" id=\"" + nodeId + "_edit\"><?php _e( 'Edit', 'autoptimize' ); ?></span></td><td class='btn delete'><span class=\"button-secondary\" id=\"" + nodeId + "_remove\"><?php _e( 'Remove', 'autoptimize' ); ?></span></td></tr>");
if ( k == "paths" ) {
target = '<a href="<?php echo AUTOPTIMIZE_WP_SITE_URL; ?>' + i + '" target="_blank">' + i + '</a>';
} else {
target = i.replace(/(woo_|template_|custom_post_|edd_|bp_|bbp_)/,'');
}
jQuery("#rules-list").append("<tr class='rule "+k+"Rule'><td class='type'><span class='badge " + typeClass + "'>" + type + "</span>" + rmark + "</td><td class='target'>" + target + "</td><td class='file'>" + file + "</td><td class='btn edit'><span class=\"button-secondary\" id=\"" + nodeId + "_edit\"><?php _e( 'Edit', 'autoptimize' ); ?></span></td><td class='btn delete'><span class=\"button-secondary\" id=\"" + nodeId + "_remove\"><?php _e( 'Remove', 'autoptimize' ); ?></span></td></tr>");
jQuery("#" + nodeId + "_edit").click(function(){addEditRow(this.id);});
jQuery("#" + nodeId + "_remove").click(function(){confirmRemove(this.id);});
})
Expand Down
11 changes: 10 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Donate link: http://blog.futtta.be/2013/10/21/do-not-donate-to-me/
Requires at least: 4.9
Tested up to: 5.4
Requires PHP: 5.6
Stable tag: 2.7.1
Stable tag: 2.7.2

Autoptimize speeds up your website by optimizing JS, CSS, images (incl. lazy-load), HTML and Google Fonts, asyncing JS, removing emoji cruft and more.

Expand Down Expand Up @@ -295,6 +295,15 @@ Just [fork Autoptimize on Github](https://github.com/futtta/autoptimize) and cod

== Changelog ==

= 2.7.2 =
* Critical CSS: fix settings page issues with certain translation strings
* Critical CSS: fix "inline & defer" not being "seen" on multisite network settings
* Critical CSS: add links on path-based rules
* Critical CSS: fix for non-asci URL's not matching rules
* Improvement: auto-disable autoptimize on misc. page builder URL's
* Improvement: don't change non-aggregated CSS if it already has an onload attribute
* Image lazyload improvement: remove `&quot;` from around background images

= 2.7.1 =
* A couple of small bugfixes, see the [GitHub commit log](https://github.com/futtta/autoptimize/commits/beta).

Expand Down

0 comments on commit ff22b73

Please sign in to comment.