et rules of the .htaccess file. flush_rocket_htaccess(); // Add WP_CACHE constant in wp-config.php. $wp_cache->set_wp_cache_constant( true ); } // Create the cache folders (wp-rocket & min). rocket_init_cache_dir(); // Create the config folder (wp-rocket-config). rocket_init_config_dir(); // Create advanced-cache.php file. rocket_generate_advanced_cache_file( new AdvancedCache( WP_ROCKET_PATH . 'views/cache/', $filesystem ) ); /** * WP Rocket activation. * * @since 3.1.5 * @author Grégory Viguier */ do_action( 'rocket_activation' ); // Update customer key & licence. wp_remote_get( WP_ROCKET_WEB_API . 'activate-licence.php', [ 'blocking' => false, ] ); wp_remote_get( home_url(), [ 'timeout' => 0.01, 'blocking' => false, 'user-agent' => 'WP Rocket/Homepage Preload', 'sslverify' => apply_filters( 'https_local_ssl_verify', false ), // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound ] ); } /** * Excludes Divi's Salvatorre script from JS minification * * Exclude it to prevent an error after minification/concatenation * * @since 3.6.3 deprecated * @since 2.9 * @author Remy Perona * * @param Array $excluded_js An array of JS paths to be excluded. * @return Array the updated array of paths */ function rocket_exclude_js_divi( $excluded_js ) { _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\ThirdParty\Themes\Divi::exclude_js' ); if ( defined( 'ET_BUILDER_URI' ) ) { $excluded_js[] = str_replace( home_url(), '', ET_BUILDER_URI ) . '/scripts/salvattore.min.js'; } return $excluded_js; } /** * Changes the text on the Varnish one-click block. * * @since 3.1 * * @param array $settings Field settings data. * * @return array modified field settings data. */ function rocket_o2switch_varnish_field( $settings ) { _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\ThirdParty\Hostings\O2Switch::varnish_addon_title' ); // Translators: %s = Hosting name. $settings['varnish_auto_purge']['title'] = sprintf( __( 'Your site is hosted on %s, we have enabled Varnish auto-purge for compatibility.', 'rocket' ), 'o2switch' ); return $settings; } /** * Purge all the domain. * * @since 3.1 * * @param string $root The path of home cache file. * @param string $lang The current lang to purge. * @param string $url The home url. */ function rocket_o2switch_varnish_clean_domain( $root, $lang, $url ) { _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\ThirdParty\Hostings\O2Switch::varnish_clean_domain' ); rocket_o2switch_varnish_http_purge( trailingslashit( $url ) . '?vregex' ); } /** * Purge a specific page. * * @since 3.1 * * @param string $url The url to purge. */ function rocket_o2switch_varnish_clean_file( $url ) { _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\ThirdParty\Hostings\O2Switch::varnish_clean_file' ); rocket_o2switch_varnish_http_purge( trailingslashit( $url ) . '?vregex' ); } /** * Purge the homepage and its pagination. * * @since 3.1 * * @param string $root The path of home cache file. * @param string $lang The current lang to purge. */ function rocket_o2switch_varnish_clean_home( $root, $lang ) { _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\ThirdParty\Hostings\O2Switch::varnish_clean_home' ); $home_url = trailingslashit( get_rocket_i18n_home_url( $lang ) ); $home_pagination_url = $home_url . trailingslashit( $GLOBALS['wp_rewrite']->pagination_base ) . '?vregex'; rocket_o2switch_varnish_http_purge( $home_url ); rocket_o2switch_varnish_http_purge( $home_pagination_url ); } /** * Send data to Varnish. * * @since 3.1 * * @param string $url The URL to purge. */ function rocket_o2switch_varnish_http_purge( $url ) { _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\ThirdParty\Hostings\O2Switch::varnish_http_purge' ); $parse_url = get_rocket_parse_url( $url ); // This filter is documented in inc/functions/varnish.php. $headers = apply_filters( 'rocket_varnish_purge_headers', [ /** * Filters the host value passed in the request headers * * @since 2.8.15 * @param string The host */ 'host' => apply_filters( 'rocket_varnish_purge_request_host', $parse_url['host'] ), 'X-VC-Purge-Key' => O2SWITCH_VARNISH_PURGE_KEY, ] ); if ( 'vregex' === $parse_url['query'] ) { $headers['X-Purge-Regex'] = '.*'; } /** * Filter the Varnish IP to call * * @since 2.6.8 * * @param string The Varnish IP */ $varnish_ip = apply_filters( 'rocket_varnish_ip', [] ); if ( defined( 'WP_ROCKET_VARNISH_IP' ) && ! $varnish_ip ) { $varnish_ip = WP_ROCKET_VARNISH_IP; } /** * Filter the HTTP protocol (scheme) * * @since 2.7.3 * * @param string The HTTP protocol */ $scheme = apply_filters( 'rocket_varnish_http_purge_scheme', $parse_url['scheme'] ); $parse_url['host'] = ( $varnish_ip ) ? $varnish_ip : $parse_url['host']; $purgeme = $scheme . '://' . $parse_url['host'] . $parse_url['path']; wp_remote_request( $purgeme, [ 'method' => 'PURGE', 'blocking' => false, 'redirection' => 0, 'headers' => $headers, ] ); } /** * Remove expiration on HTML to prevent issue with Varnish cache. * * @since 3.1 * * @param string $rules htaccess rules. * * @return string Updated htaccess rules. */ function rocket_o2switch_remove_html_expire( $rules ) { _deprecated_function( __FUNCTION__ . '()', '3.6.3', '\WP_Rocket\ThirdParty\Hostings\O2Switch::remove_html_expire' ); $rules = preg_replace( '@\s*#\s*Your document html@', '', $rules ); $rules = preg_replace( '@\s*ExpiresByType text/html\s*"access plus \d+ (seconds|minutes|hour|week|month|year)"@', '', $rules ); return $rules; }