Jake Vanderwerf
2026-02-04 2127b1bdd73ecd2423e443992da4b442f5a3c1a3
inc/registry/PostTypeRegistrar.php
@@ -5,8 +5,7 @@
use JVBase\managers\CRUD;
use JVBase\utility\Features;
use WP_Post;
use JVBase\meta\MetaRegistry;
use JVBase\managers\CacheManager;
use JVBase\meta\Registry;
if (!defined('ABSPATH')) {
   exit;
}
@@ -80,11 +79,10 @@
      if ($this->config['is_timeline']??false) {
      }
      register_post_type($this->post_type, $args);
      if (!empty($this->fields)) {
         $meta_registry = new MetaRegistry($this->fields, $this->slug, 'post');
         $meta_registry = new Registry($this->fields, $this->slug, 'post');
         $meta_registry->registerMetaFields();
      }
   }
@@ -130,45 +128,6 @@
         add_action('post_type_link', [$this, 'rewriteTaxonomySingle'], 15, 2);
         add_filter('post_type_archive_link', [$this, 'rewriteTaxonomyArchive'], 15, 2);
      }
      $postType = $this->post_type;
      add_action("save_post_{$this->post_type}", function($post_id, $post, $update) use ($postType) {
         if (jvbNoSaveIt($post_id, $post)) {
            return;
         }
         $this->invalidatePostCache($postType, $post, $update ? 'update' : 'create');
      }, 10, 3);
      add_action("delete_post", function($post_id, $post) use ($postType) {
         $post = get_post($post_id);
         if ($post && $post->post_type === $postType) {
            $this->invalidatePostCache($postType, $post, 'delete');
         }
      }, 10, 2);
      add_action("transition_post_status", function($new_status, $old_status, $post) use ($postType) {
         if ($post->post_type === $postType && $new_status !== $old_status) {
            $this->invalidatePostCache($postType, $post, 'status_change');
         }
      }, 10, 3);
   }
   protected function invalidatePostCache(string $type, $post, string $action) {
      error_log('Clearing Cache for '.print_r($type, true));
      $cache = CacheManager::for(jvbNoBase($type))->invalidate();
      // Clear related caches (taxonomies attached to this post)
      $taxonomies = get_object_taxonomies($post->post_type);
      foreach ($taxonomies as $taxonomy) {
         $terms = wp_get_post_terms($post->ID, $taxonomy, ['fields' => 'ids']);
         if (!empty($terms)) {
            CacheManager::for(jvbNoBase($taxonomy))->invalidate();
         }
      }
      // Trigger custom action for additional handling
      do_action("jvb_cache_invalidated_{$type}", $post, $action);
   }
   public function hideFromPublic(bool $is_viewable): bool