PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.19.3
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.19.3
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / classes / WordPress / Invalidations.php
nitropack / classes / WordPress Last commit date
Notifications 3 months ago Settings 3 months ago Admin.php 3 months ago CLI.php 6 months ago Config.php 1 year ago ConflictingPlugins.php 10 months ago Cron.php 1 year ago Invalidations.php 4 months ago NitroPack.php 4 months ago Settings.php 4 months ago
Invalidations.php
76 lines
1 <?php
2
3 namespace NitroPack\WordPress;
4
5 use WC_Product;
6
7 /**
8 * Post invalidations on specific events
9 */
10 class Invalidations {
11 private static $instance = null;
12 public static function getInstance() {
13 if ( null === self::$instance ) {
14 self::$instance = new self();
15 }
16 return self::$instance;
17 }
18
19 public function __construct() {
20 add_action( 'woocommerce_update_product', [ $this, 'invalidate_product_on_update' ], 10, 2 );
21 add_action( 'set_object_terms', [ $this, 'nitropack_sot' ], 10, 6 );
22 }
23 /**
24 * Fires after a single post taxonomy (categories, tags etc) has been updated -> assigned or removed.
25 * @param int $object_id
26 * @param array $terms
27 * @param array $tt_ids
28 * @param string $taxonomy
29 * @param bool $append
30 * @param array $old_tt_ids
31 * @return void
32 */
33 public function nitropack_sot( $object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids ) {
34 if ( ! get_option( "nitropack-autoCachePurge", 1 ) ) {
35 return;
36 }
37
38 $post = get_post( $object_id );
39 $post_status = $post->post_status;
40
41 if ( $post_status === 'auto-draft' || $post_status === 'draft' ) {
42 return;
43 }
44
45 if ( ! defined( 'NITROPACK_PURGE_CACHE' ) ) {
46 $purgeCache = ! nitropack_compare_posts( $tt_ids, $old_tt_ids );
47 $cleanCache = $purgeCache ? "YES" : "NO";
48 if ( $purgeCache ) {
49 \NitroPack\WordPress\NitroPack::$np_loggedWarmups[] = get_permalink( $post );
50 nitropack_clean_post_cache( $post );
51 define( 'NITROPACK_PURGE_CACHE', true );
52 }
53 }
54 }
55 /**
56 * Invalidate product on update, including REST-API updates.
57 * Mainly used for REST-API, since the nitropack_handle_post_transition() does not cover that.
58 * @param int $id
59 * @param WC_Product $product
60 * @return void
61 */
62 public function invalidate_product_on_update( $id, $product ) {
63 if ( ! get_option( "nitropack-autoCachePurge", 1 ) ) {
64 return;
65 }
66 if ( ! defined( 'NITROPACK_PURGE_CACHE' ) ) {
67 try {
68 $post = get_post( $id );
69 nitropack_detect_changes_and_clean_post_cache( $post );
70 define( 'NITROPACK_PURGE_CACHE', true );
71 } catch (\Exception $e) {
72
73 }
74 }
75 }
76 }