Jake Vanderwerf
2026-08-28 a9654f00c8fbc9934289d761843ddd071025013f
inc/forms/PostSelector.php
@@ -1,7 +1,8 @@
<?php
namespace JVBase\forms;
use JVBase\managers\CacheManager;
use JVBase\managers\Cache;
use JVBase\managers\Roles;
use WP_REST_Request;
use WP_REST_Response;
use WP_Query;
@@ -18,12 +19,12 @@
{
   protected string $post_type;
   protected array $config;
   protected CacheManager $cache;
   protected Cache $cache;
   public function __construct(string $post_type, array $config = [])
   {
      $this->post_type = $post_type;
      $this->cache = new CacheManager('posts');
      $this->cache = Cache::for(jvbNoBase($post_type), 'post',WEEK_IN_SECONDS);
      $this->config = wp_parse_args($config, [
         'multiple' => true,
@@ -48,9 +49,6 @@
    */
   public function render(array $selected = [], string $containerId = ''): string
   {
      // Mark that selectors are present for footer output
      TaxonomySelector::markSelectorsPresent();
      // Process selected posts
      $processedSelected = $this->processSelectedPosts($selected);
@@ -187,8 +185,8 @@
      }
      // Check cache
      $cache_key = $this->cache->generateKey($args);
      $cached_result = $this->cache->get($cache_key);
      $cached_result = $this->cache->get($args);
      if ($cached_result) {
         return new WP_REST_Response($cached_result);
      }
@@ -226,7 +224,7 @@
      ];
      // Cache the result
      $this->cache->set($cache_key, $result, 300); // 5 minute cache
      $this->cache->set($args, $result, 300); // 5 minute cache
      return new WP_REST_Response($result);
   }
@@ -240,7 +238,7 @@
         'methods' => 'GET',
         'callback' => [new self('post'), 'searchPosts'],
         'permission_callback' => function($request) {
            return JVB()->roles()->checkRole(get_current_user(), $request->get_param('post_type'));
            return Roles::getInstance()()->checkRole(get_current_user(), $request->get_param('post_type'));
         },
         'args' => [
            'post_type' => [
@@ -267,7 +265,7 @@
   }
   /**
    * Render post selector field for MetaForm integration
    * Render post selector field for Meta's Form integration
    *
    * @param string $name Field name
    * @param mixed $value Current value