diff --git a/.gitattributes b/.gitattributes index 3361aa2e40..0d7c7157c8 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,7 @@ # PHPUnit files .travis.yml export-ignore bin export-ignore -tests/bootstrap.php export-ignore -tests/test-sample.php export-ignore -tests/inc export-ignore +tests export-ignore phpunit.xml export-ignore README.md export-ignore .gitattributes export-ignore diff --git a/inc/3rd-party/hosting/wpengine.php b/inc/3rd-party/hosting/wpengine.php index dd6f3d3403..91524583ab 100644 --- a/inc/3rd-party/hosting/wpengine.php +++ b/inc/3rd-party/hosting/wpengine.php @@ -41,44 +41,6 @@ function rocket_run_rocket_bot_after_wpengine() { } add_action( 'admin_init', 'rocket_run_rocket_bot_after_wpengine' ); - /** - * Activate the CDN option if WPEngine CDN is active - * - * @since 2.7 - * - * @param bool $value WP Rocket CDN option value. - * @return bool true if there is a CDN domain, default value otherwise - */ - function rocket_auto_activate_cdn_on_wpengine( $value ) { - $cdn_domain = rocket_get_wp_engine_cdn_domain(); - - if ( ! empty( $cdn_domain ) ) { - $value = true; - } - - return $value; - } - add_filter( 'get_rocket_option_cdn', 'rocket_auto_activate_cdn_on_wpengine' ); - - /** - * Add WP Engine CDN CNAMES to the list of allowed CNAMES - * - * @since 2.7 - * - * @param array $hosts WP Rocket CDN cnames. - * @return array Updated WP Rocket CDN cnames values - */ - function rocket_add_wpengine_cdn_cnames( $hosts ) { - $cdn_domain = rocket_get_wp_engine_cdn_domain(); - - if ( ! empty( $cdn_domain ) ) { - $hosts[] = $cdn_domain; - } - - return $hosts; - } - add_filter( 'rocket_cdn_cnames', 'rocket_add_wpengine_cdn_cnames' ); - /** * Call the cache server to purge the cache with WP Engine hosting. * diff --git a/inc/3rd-party/jetpack.php b/inc/3rd-party/jetpack.php index 2beaa4925d..e991d53bf9 100644 --- a/inc/3rd-party/jetpack.php +++ b/inc/3rd-party/jetpack.php @@ -1,15 +1,25 @@ 'sitemap_preload', 'type' => 'checkbox', - 'label' => __( 'Jetpack XML Sitemaps', 'rocket' ), - 'label_for' => 'jetpack_xml_sitemap', - 'label_screen' => sprintf( __( 'Preload the sitemap from the %s plugin', 'rocket' ), 'Jetpack' ), - 'default' => 0, + 'label' => __( 'Jetpack XML Sitemaps', 'rocket' ), + 'label_for' => 'jetpack_xml_sitemap', + 'label_screen' => sprintf( __( 'Preload the sitemap from the Jetpack plugin', 'rocket' ), 'Jetpack' ), + 'default' => 0, ); $options[] = array( 'parent' => 'sitemap_preload', - 'type' => 'helper_description', - 'name' => 'jetpack_xml_sitemap_desc', + 'type' => 'helper_description', + 'name' => 'jetpack_xml_sitemap_desc', + // translators: %s = plugin name, e.g. Yoast SEO. 'description' => sprintf( __( 'We automatically detected the sitemap generated by the %s plugin. You can check the option to preload it.', 'rocket' ), 'Jetpack' ), ); return $options; } add_filter( 'rocket_sitemap_preload_options', 'rocket_sitemap_preload_jetpack_option' ); - } -endif; + } // End if(). + + /** + * Support Jetpack's EU Cookie Law Widget. + * + * @see https://jetpack.com/support/extra-sidebar-widgets/eu-cookie-law-widget/ + * + * @since 2.10.1 + * @author Jeremy Herve + */ + if ( Jetpack::is_module_active( 'widgets' ) ) : + + /** + * Add the EU Cookie Law to the list of mandatory cookies before generating caching files. + * + * @since 2.10.1 + * @author Jeremy Herve + * + * @param array $cookies List of mandatory cookies. + */ + function rocket_add_jetpack_cookie_law_mandatory_cookie( $cookies ) { + $cookies['jetpack-eu-cookie-law'] = 'eucookielaw'; + + return $cookies; + } + add_filter( 'rocket_cache_mandatory_cookies' , 'rocket_add_jetpack_cookie_law_mandatory_cookie' ); + + // Don't add the WP Rocket rewrite rules to avoid issues. + add_filter( 'rocket_htaccess_mod_rewrite', '__return_false' ); + + /** + * Add Jetpack cookie when: + * - Jetpack is active. + * - Jetpack's Extra Sidebar Widgets module is active. + * - The widget is active. + * - the rocket_jetpack_eu_cookie_widget option is empty or not set. + * + * @since 2.10.1 + * @author Jeremy Herve + */ + function rocket_activate_jetpack_cookie_law() { + $rocket_jp_eu_cookie_widget = get_option( 'rocket_jetpack_eu_cookie_widget' ); + + if ( + is_active_widget( false, false, 'eu_cookie_law_widget' ) + && empty( $rocket_jp_eu_cookie_widget ) + ) { + add_filter( 'rocket_htaccess_mod_rewrite' , '__return_false' ); + add_filter( 'rocket_cache_mandatory_cookies' , 'rocket_add_jetpack_cookie_law_mandatory_cookie' ); + + // Update the WP Rocket rules on the .htaccess file. + flush_rocket_htaccess(); + + // Regenerate the config file. + rocket_generate_config_file(); + + // Set the option, so this is not triggered again. + update_option( 'rocket_jetpack_eu_cookie_widget', 1, true ); + } + } + add_action( 'admin_init', 'rocket_activate_jetpack_cookie_law' ); + + endif; // End if Widgets module is active check. + +endif; // End if Jetpack is active check. + +/** + * Remove cookies if Jetpack gets deactivated. + * + * @since 2.10.1 + * @author Jeremy Herve + */ +function rocket_remove_jetpack_cookie_law_mandatory_cookie() { + remove_filter( 'rocket_htaccess_mod_rewrite' , '__return_false' ); + remove_filter( 'rocket_cache_mandatory_cookies', '_rocket_add_eu_cookie_law_mandatory_cookie' ); + + // Update the WP Rocket rules on the .htaccess file. + flush_rocket_htaccess(); + + // Regenerate the config file. + rocket_generate_config_file(); + + // Delete our option. + delete_option( 'rocket_jetpack_eu_cookie_widget' ); +} +add_action( 'deactivate_jetpack/jetpack.php', 'rocket_remove_jetpack_cookie_law_mandatory_cookie', 11 ); diff --git a/uninstall.php b/uninstall.php index 7762efa813..30e8105b47 100755 --- a/uninstall.php +++ b/uninstall.php @@ -10,7 +10,10 @@ // Delete WP Rocket options. delete_option( 'wp_rocket_settings' ); -// Delete all user meta related to WP Rocket. +// Delete Compatibility options. +delete_option( 'rocket_jetpack_eu_cookie_widget' ); + +// Delete all user meta related to WP Rocket delete_metadata( 'user', '', 'rocket_boxes', '', true ); // Clear scheduled WP Rocket Cron. diff --git a/wp-rocket.php b/wp-rocket.php index 5c88082976..061cfcbeb4 100755 --- a/wp-rocket.php +++ b/wp-rocket.php @@ -3,7 +3,7 @@ * Plugin Name: WP Rocket * Plugin URI: https://wp-rocket.me * Description: The best WordPress performance plugin. - * Version: 2.10 + * Version: 2.10.1 * Code Name: Endor * Author: WP Media * Contributors: Jonathan Buttigieg, Julio Potier, Remy Perona @@ -19,7 +19,7 @@ defined( 'ABSPATH' ) or die( 'Cheatin’ uh?' ); // Rocket defines. -define( 'WP_ROCKET_VERSION' , '2.10' ); +define( 'WP_ROCKET_VERSION' , '2.10.1' ); define( 'WP_ROCKET_PRIVATE_KEY' , false ); define( 'WP_ROCKET_SLUG' , 'wp_rocket_settings' ); define( 'WP_ROCKET_WEB_MAIN' , false ); @@ -269,7 +269,6 @@ function rocket_activation() { require( WP_ROCKET_FUNCTIONS_PATH . 'plugins.php' ); require( WP_ROCKET_FUNCTIONS_PATH . 'i18n.php' ); require( WP_ROCKET_FUNCTIONS_PATH . 'htaccess.php' ); - require( WP_ROCKET_3RD_PARTY_PATH . 'hosting/godaddy.php' ); if ( version_compare( phpversion(), '5.3.0', '>=' ) ) { require( WP_ROCKET_3RD_PARTY_PATH . 'hosting/godaddy.php' );