Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 3
CRAP
n/a
0 / 0
Automattic\Jetpack_Boost\Compatibility\Super_Cache\add_bypass_query_param
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
Automattic\Jetpack_Boost\Compatibility\Super_Cache\critical_css_bypass_super_cache
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
Automattic\Jetpack_Boost\Compatibility\Super_Cache\clear_cache
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2/**
3 * Super Cache compatibility for Boost
4 *
5 * @package automattic/jetpack-boost
6 */
7
8namespace Automattic\Jetpack_Boost\Compatibility\Super_Cache;
9
10/**
11 * Add WP Super Cache bypass query param to the URL.
12 *
13 * @param string $url The URL.
14 */
15function add_bypass_query_param( $url ) {
16    global $cache_page_secret;
17
18    return add_query_arg( 'donotcachepage', $cache_page_secret, $url );
19}
20
21/**
22 * Add WP Super Cache bypass query params to Critical CSS URLs.
23 *
24 * @param array $urls list of URLs to generate Critical CSS for.
25 */
26function critical_css_bypass_super_cache( $urls ) {
27    return array_map( __NAMESPACE__ . '\add_bypass_query_param', $urls );
28}
29add_filter( 'jetpack_boost_critical_css_urls', __NAMESPACE__ . '\critical_css_bypass_super_cache' );
30
31/**
32 * Clear Super Cache's cache. Called when Critical CSS finishes generating, or
33 * when a module is enabled or disabled.
34 */
35function clear_cache() {
36    global $wpdb;
37
38    if ( function_exists( 'wp_cache_clear_cache' ) ) {
39        wp_cache_clear_cache( $wpdb->blogid );
40    }
41
42    // Remove the action so it doesn't run again during the same request.
43    remove_action( 'jetpack_boost_page_output_changed', __NAMESPACE__ . '\clear_cache' );
44}
45add_action( 'jetpack_boost_page_output_changed', __NAMESPACE__ . '\clear_cache' );