ACF.php
1 year ago
AdvancedMathCaptcha.php
1 year ago
AeliaCurrencySwitcher.php
11 months ago
BeaverBuilder.php
1 year ago
CF_Helper.php
1 year ago
CURCY_MultiCurrency.php
1 year ago
Cloudflare.php
1 year ago
CommonHelpers.php
1 year ago
CookieNotice.php
1 year ago
DownloadManager.php
1 year ago
Elementor.php
1 year ago
Ezoic.php
1 year ago
FusionBuilder.php
1 year ago
GeoTargetingWP.php
1 year ago
GravityForms.php
1 year ago
JetPackNP.php
1 year ago
MPG.php
11 months ago
NginxHelper.php
1 year ago
RC.php
11 months ago
RankMathNP.php
1 year ago
ShortPixel.php
1 year ago
SquirrlySEO.php
1 year ago
TheEventsCalendar.php
1 year ago
ThriveTheme.php
1 year ago
WCML.php
1 year ago
WPBakeryNP.php
1 year ago
WPCacheHelper.php
1 year ago
WPForms.php
1 year ago
WPML.php
1 year ago
WPRocket.php
1 year ago
WooCommerce.php
11 months ago
WoocommerceCacheHandler.php
1 year ago
YoastSEO.php
1 year ago
ACF.php
53 lines
| 1 | <?php |
| 2 | |
| 3 | namespace NitroPack\Integration\Plugin; |
| 4 | |
| 5 | class ACF { |
| 6 | const STAGE = "late"; |
| 7 | |
| 8 | public static function isActive() { |
| 9 | return class_exists(\ACF::class); |
| 10 | } |
| 11 | |
| 12 | public function init($stage) { |
| 13 | if (!self::isActive()) return; |
| 14 | |
| 15 | /* By using 5 priority the function is called before the ACF save_post action, 10 is after */ |
| 16 | add_action('acf/save_post', [$this, 'invalidate_post_due_to_acf_change'], 5); |
| 17 | |
| 18 | } |
| 19 | |
| 20 | public function invalidate_post_due_to_acf_change($post_id) { |
| 21 | if (!get_option("nitropack-autoCachePurge", 1)) return; |
| 22 | |
| 23 | $allowed_cpts = get_option('nitropack-cacheableObjectTypes'); |
| 24 | |
| 25 | //refresh option if not set when activating already connected NitroPack |
| 26 | if (!is_array($allowed_cpts)) update_option("nitropack-cacheableObjectTypes", nitropack_get_default_cacheable_object_types()); |
| 27 | |
| 28 | if (!in_array(get_post_type($post_id), $allowed_cpts)) return; |
| 29 | |
| 30 | //acf update check |
| 31 | if (!isset($_POST['acf'])) return; |
| 32 | |
| 33 | //get old meta |
| 34 | $metaBefore = []; |
| 35 | $field_objects = get_field_objects($post_id, false); |
| 36 | foreach ($field_objects as $field_object) { |
| 37 | $metaBefore[$field_object['key']] = $field_object['value']; |
| 38 | } |
| 39 | // Get submitted new values. |
| 40 | $metaAfter = $_POST['acf']; |
| 41 | |
| 42 | //comapre meta before and after and update |
| 43 | $metaIsEqual = nitropack_compare_posts($metaAfter, $metaBefore); |
| 44 | if (!$metaIsEqual) { |
| 45 | $post = get_post($post_id); |
| 46 | if ($post->post_status === 'publish' && !defined('NITROPACK_PURGE_CACHE')) { |
| 47 | nitropack_clean_post_cache($post, null, true, sprintf("Invalidate related pages due to modifying ACF fields in %s '%s'", $post->post_type, $post->post_title)); |
| 48 | define('NITROPACK_PURGE_CACHE', true); |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 |