Skip to content

Commit

Permalink
Merge pull request #269 from wp-media/branch-2.9.1
Browse files Browse the repository at this point in the history
2.9.1
  • Loading branch information
GeekPress authored Dec 27, 2016
2 parents 0cbd725 + 4e5150c commit d5dc4ea
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 103 deletions.
2 changes: 2 additions & 0 deletions inc/3rd-party/3rd-party.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
require( WP_ROCKET_3RD_PARTY_PATH . 'age-verify.php' );
require( WP_ROCKET_3RD_PARTY_PATH . 'autoptimize.php' );
require( WP_ROCKET_3RD_PARTY_PATH . 'eu-cookie-law.php' );
require( WP_ROCKET_3RD_PARTY_PATH . 'weepie-cookie-allow.php' );
require( WP_ROCKET_3RD_PARTY_PATH . 'kk-star-ratings.php' );
require( WP_ROCKET_3RD_PARTY_PATH . 'wp-postratings.php' );
require( WP_ROCKET_3RD_PARTY_PATH . 'wp-print.php' );
Expand All @@ -42,5 +43,6 @@
require( WP_ROCKET_3RD_PARTY_PATH . 'page-builder/visual-composer.php' );
require( WP_ROCKET_3RD_PARTY_PATH . 'security/secupress.php' );
require( WP_ROCKET_3RD_PARTY_PATH . 'simple-custom-css.php' );
require( WP_ROCKET_3RD_PARTY_PATH . 'wp-retina-2x.php' );

require( WP_ROCKET_3RD_PARTY_PATH . 'themes/divi.php' );
2 changes: 1 addition & 1 deletion inc/3rd-party/simple-custom-css.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );

if ( defined( 'SCCSS_FILE' ) ) :
add_action( 'wp_enqueue_scripts', 'rocket_cache_sccss', 1 );
add_action( 'wp_enqueue_scripts', 'rocket_cache_sccss', 98 );
add_action( 'update_option_sccss_settings', 'rocket_delete_sccss_cache_file' );
add_filter( 'rocket_cache_busting_filename', 'rocket_sccss_cache_busting_filename' );
endif;
Expand Down
67 changes: 67 additions & 0 deletions inc/3rd-party/weepie-cookie-allow.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
defined( 'ABSPATH' ) or die( 'Cheatin\' uh?' );

/**
* Compatibility with WeePie Cookie Allow
*
* @since 2.9
*/
if ( class_exists( 'WpieCookieAllow' ) ) :
/*
* Update .htaccess & config files when the "Enabled" and "Autoblock" options are turned on
*
*/
add_filter( 'rocket_cache_mandatory_cookies' , 'rocket_add_weepie_cookie_allow_mandatory_cookie' );
add_action( 'update_option_wpca_settings_general', 'rocket_after_update_wp_cookie_allow_options', 10, 2 );
function rocket_after_update_wp_cookie_allow_options( $old_value, $value ) {
if ( ( isset( $old_value['general_plugin_status'], $value['general_plugin_status'] ) && ( $old_value['general_plugin_status'] == $value['general_plugin_status'] ) ) && isset( $old_value['general_cookies_before_consent'], $value['general_cookies_before_consent'] ) && $old_value['general_cookies_before_consent'] == $value['general_cookies_before_consent'] ) {
return;
}

// Update the WP Rocket rules on the .htaccess file
flush_rocket_htaccess();

// Update the config file
rocket_generate_config_file();
}

// Don't add the WP Rocket rewrite rules to avoid issues
add_filter( 'rocket_htaccess_mod_rewrite', '__return_false' );
endif;

// Add cookies when we activate the plugin
add_action( 'activate_wp-cookie-allow/wp-cookie-allow.php', 'rocket_activate_wp_cookie_allow', 11 );
function rocket_activate_wp_cookie_allow() {
add_filter( 'rocket_htaccess_mod_rewrite' , '__return_false' );
add_filter( 'rocket_cache_mandatory_cookies' , 'rocket_add_weepie_cookie_allow_mandatory_cookie' );

// Update the WP Rocket rules on the .htaccess file
flush_rocket_htaccess();

// Regenerate the config file
rocket_generate_config_file();
}

// Remove cookies when we deactivate the plugin
add_action( 'deactivate_wp-cookie-allow/wp-cookie-allow.php', 'rocket_deactivate_wp_cookie_allow', 11 );
function rocket_deactivate_wp_cookie_allow() {
remove_filter( 'rocket_htaccess_mod_rewrite' , '__return_false' );
remove_filter( 'rocket_cache_mandatory_cookies', 'rocket_add_weepie_cookie_allow_mandatory_cookie' );

// Update the WP Rocket rules on the .htaccess file
flush_rocket_htaccess();

// Regenerate the config file
rocket_generate_config_file();
}

// Add the WeePie Cookie Allow cookie to the list of mandatory cookies before generating caching files
function rocket_add_weepie_cookie_allow_mandatory_cookie( $cookies ) {
$options = get_option( 'wpca_settings_general' );

if ( 1 === (int) $options['general_plugin_status'] && 1 === (int) $options['general_cookies_before_consent'] ) {
$cookies['weepie-cookie-allow'] = 'wpca_consent';
}

return $cookies;
}
30 changes: 30 additions & 0 deletions inc/3rd-party/wp-retina-2x.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

if ( class_exists( 'WR2X_Admin' ) ) :
add_filter( 'wr2x_img_retina_url', 'rocket_cdn_on_images_from_wp_retina_x2' );
add_filter( 'wr2x_img_url', 'rocket_cdn_on_images_from_wp_retina_x2' );
/**
* Conflict with WP Retina x2: Apply CDN on srcset attribute.
*
* @since 2.9.1 Use global $wr2x_admin
* @since 2.5.5
*
* @param string $url URL of the image.
* @return string Updated URL with CDN
*/
function rocket_cdn_on_images_from_wp_retina_x2( $url ) {
global $wr2x_admin;

if ( ! method_exists( $wr2x_admin, 'is_pro' ) || ! $wr2x_admin->is_pro() ) {
return $url;
}

$cdn_domain = get_option( 'wr2x_cdn_domain' );

if ( ! empty( $cdn_domain ) ) {
return $url;
}

return get_rocket_cdn_url( $url, array( 'all', 'images' ) );
}
endif;
6 changes: 4 additions & 2 deletions inc/domain-mapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
function rocket_parse_url_domain_mapping( $url ) {
$original_siteurl_host = parse_url( get_original_url( 'siteurl' ), PHP_URL_HOST );
$domain_mapping_siteurl_host = parse_url( domain_mapping_siteurl( false ), PHP_URL_HOST );

$url[0] = str_replace( $original_siteurl_host, $domain_mapping_siteurl_host, $url[0] );

if ( false === strpos( $domain_mapping_siteurl_host, $original_siteurl_host ) ) {
$url[0] = str_replace( $original_siteurl_host, $domain_mapping_siteurl_host, $url[0] );
}

return $url;
}
Expand Down
2 changes: 1 addition & 1 deletion inc/front/cdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ function rocket_cdn_custom_files( $html ) {
$filetypes = apply_filters( 'rocket_cdn_custom_filetypes', array( 'mp3', 'ogg', 'mp4', 'm4v', 'avi', 'mov', 'flv', 'swf', 'webm', 'pdf', 'doc', 'docx', 'txt', 'zip', 'tar', 'bz2', 'tgz', 'rar' ) );
$filetypes = implode( '|', $filetypes );

preg_match_all( '#<a[^>]+?href=[\'"]?(.*\.(?:' . $filetypes . '))[\'"]?[^>]*>#i', $html, $matches );
preg_match_all( '#<a[^>]+?href=[\'"]?([^"\'>]+\.(?:' . $filetypes . '))[\'"]?[^>]*>#i', $html, $matches );
if ( ( bool ) $matches ) {
$i = 0;
Expand Down
25 changes: 19 additions & 6 deletions inc/front/enqueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function rocket_browser_cache_busting( $src, $current_filter = '' ) {
$hosts = get_rocket_cnames_host( array( 'all', 'css_and_js', $extension ) );
$hosts[] = parse_url( home_url(), PHP_URL_HOST );
$hosts_index = array_flip( $hosts );
list( $file_host, $relative_src_path ) = get_rocket_parse_url( $full_src );
list( $file_host, $relative_src_path, $scheme, $query ) = get_rocket_parse_url( $full_src );

if ( $file_host == '' ) {
$full_src = home_url() . $src;
Expand All @@ -74,7 +74,7 @@ function rocket_browser_cache_busting( $src, $current_filter = '' ) {
return $src;
}

$relative_src_path = ltrim( $relative_src_path, '/' );
$relative_src_path = ltrim( $relative_src_path . '?' . $query, '/' );
$full_src_path = ABSPATH . dirname( $relative_src_path );
/*
* Filters the cache busting filename
Expand Down Expand Up @@ -140,7 +140,9 @@ function rocket_cache_dynamic_resource( $src ) {

$full_src = ( substr( $src, 0, 2 ) === '//' ) ? rocket_add_url_protocol( $src ) : $src;

switch ( current_filter() ) {
$current_filter = current_filter();

switch ( $current_filter ) {
case 'script_loader_src':
$extension = '.js';
break;
Expand All @@ -152,7 +154,7 @@ function rocket_cache_dynamic_resource( $src ) {
$hosts = get_rocket_cnames_host( array( 'all', 'css_and_js', $extension ) );
$hosts[] = parse_url( home_url(), PHP_URL_HOST );
$hosts_index = array_flip( $hosts );
list( $file_host, $relative_src_path ) = get_rocket_parse_url( $full_src );
list( $file_host, $relative_src_path, $scheme, $query ) = get_rocket_parse_url( $full_src );

if ( $file_host == '' ) {
$full_src = home_url() . $src;
Expand All @@ -162,7 +164,8 @@ function rocket_cache_dynamic_resource( $src ) {
return $src;
}

$relative_src_path = ltrim( $relative_src_path, '/' );
$relative_src_path = ltrim( $relative_src_path . '?' . $query, '/' );
$full_src_path = ABSPATH . dirname( $relative_src_path );
/*
* Filters the dynamic resource cache filename
*
Expand All @@ -184,11 +187,21 @@ function rocket_cache_dynamic_resource( $src ) {
return $src;
}

if ( 'style_loader_src' === $current_filter ) {
if ( ! class_exists( 'Minify_CSS_UriRewriter' ) ) {
require( WP_ROCKET_PATH . 'min/lib/Minify/CSS/UriRewriter.php' );
}
// Rewrite import/url in CSS content to add the absolute path to the file
$file_content = Minify_CSS_UriRewriter::rewrite( $response['body'], $full_src_path );
} else {
$file_content = $response['body'];
}

if ( ! is_dir( $cache_busting_paths['bustingpath'] ) ) {
rocket_mkdir_p( $cache_busting_paths['bustingpath'] );
}

rocket_put_content( $cache_busting_paths['filepath'], $response['body'] );
rocket_put_content( $cache_busting_paths['filepath'], $file_content );

return $cache_busting_paths['url'];
}
19 changes: 0 additions & 19 deletions inc/front/plugin-compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,25 +157,6 @@ function __rocket_cdn_on_sliders_with_lazyload() {
}
}

/**
* Conflict with WP Retina x2: Apply CDN on srcset attribute.
*
* @since 2.5.5
*/
add_filter( 'wr2x_img_retina_url', '__rocket_cdn_on_images_from_wp_retina_x2' );
add_filter( 'wr2x_img_url', '__rocket_cdn_on_images_from_wp_retina_x2' );
function __rocket_cdn_on_images_from_wp_retina_x2( $url ) {
if ( wr2x_is_pro() ) {
$cdn_domain = wr2x_getoption( "cdn_domain", "wr2x_advanced", "" );
}

if ( empty( $cdn_domain ) ) {
return get_rocket_cdn_url( $url, array( 'all', 'images' ) );
}

return $url;
}

/**
* Conflict with MailChimp List Subscribe Form: Enqueue style without lack of performance, grrrr!!!
*
Expand Down
Binary file modified languages/rocket-pt_BR.mo
Binary file not shown.
Loading

0 comments on commit d5dc4ea

Please sign in to comment.