Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
20.00% |
4 / 20 |
|
0.00% |
0 / 4 |
CRAP | n/a |
0 / 0 |
|
| jetpack_boost_delete_cache | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| jetpack_boost_delete_cache_for_home | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
12 | |||
| jetpack_boost_delete_cache_for_url | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| jetpack_boost_delete_cache_by_post_id | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * This file contains all the public actions for the Page Cache module. |
| 4 | * This file is loaded before WordPress is fully initialized. |
| 5 | */ |
| 6 | |
| 7 | use Automattic\Jetpack_Boost\Modules\Optimizations\Page_Cache\Pre_WordPress\Boost_Cache; |
| 8 | use Automattic\Jetpack_Boost\Modules\Optimizations\Page_Cache\Pre_WordPress\Logger; |
| 9 | |
| 10 | /** |
| 11 | * Delete all cache. |
| 12 | * |
| 13 | * Allow third-party plugins to clear all cache. |
| 14 | */ |
| 15 | add_action( 'jetpack_boost_clear_page_cache_all', 'jetpack_boost_delete_cache' ); |
| 16 | |
| 17 | /** |
| 18 | * Delete cache for homepage and paged archives. |
| 19 | * |
| 20 | * Allow third-party plugins to clear front-page cache. |
| 21 | */ |
| 22 | add_action( 'jetpack_boost_clear_page_cache_home', 'jetpack_boost_delete_cache_for_home' ); |
| 23 | |
| 24 | /** |
| 25 | * Delete cache for a specific URL. |
| 26 | * |
| 27 | * Allow third-party plugins to clear the cache for a specific URL. |
| 28 | * |
| 29 | * @param string $url - The URL to delete the cache for. |
| 30 | */ |
| 31 | add_action( 'jetpack_boost_clear_page_cache_url', 'jetpack_boost_delete_cache_for_url' ); |
| 32 | |
| 33 | /** |
| 34 | * Delete cache for a specific post. |
| 35 | * |
| 36 | * Allow third-party plugins to clear the cache for a specific post. |
| 37 | * |
| 38 | * @param int $post_id - The ID of the post to delete the cache for. |
| 39 | */ |
| 40 | add_action( 'jetpack_boost_clear_page_cache_post', 'jetpack_boost_delete_cache_by_post_id' ); |
| 41 | |
| 42 | /** |
| 43 | * Delete all cache files. |
| 44 | */ |
| 45 | function jetpack_boost_delete_cache() { |
| 46 | $boost_cache = new Boost_Cache(); |
| 47 | $boost_cache->delete_recursive( home_url() ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Delete cache for homepage and paged archives. |
| 52 | */ |
| 53 | function jetpack_boost_delete_cache_for_home() { |
| 54 | $boost_cache = new Boost_Cache(); |
| 55 | $boost_cache->delete_page( home_url() ); |
| 56 | |
| 57 | Logger::debug( 'jetpack_boost_delete_cache_for_home: deleting front page cache' ); |
| 58 | if ( get_option( 'show_on_front' ) === 'page' ) { |
| 59 | $posts_page_id = get_option( 'page_for_posts' ); // posts page |
| 60 | if ( $posts_page_id ) { |
| 61 | $boost_cache->delete_recursive( get_permalink( $posts_page_id ) ); |
| 62 | Logger::debug( 'jetpack_boost_delete_cache_for_home: deleting posts page cache' ); |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Delete cache for a specific URL. |
| 69 | * |
| 70 | * @param string $url - The URL to delete the cache for. |
| 71 | */ |
| 72 | function jetpack_boost_delete_cache_for_url( $url ) { |
| 73 | $boost_cache = new Boost_Cache(); |
| 74 | $boost_cache->delete_recursive( $url ); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Delete cache for a specific post. |
| 79 | * |
| 80 | * @param int $post_id - The ID of the post to delete the cache for. |
| 81 | */ |
| 82 | function jetpack_boost_delete_cache_by_post_id( $post_id ) { |
| 83 | $post = get_post( (int) $post_id ); |
| 84 | |
| 85 | Logger::debug( 'invalidate_cache_for_post: ' . $post->ID ); |
| 86 | |
| 87 | $boost_cache = new Boost_Cache(); |
| 88 | $boost_cache->delete_post_cache( $post ); |
| 89 | } |