| | |
| | | namespace JVBase\forms; |
| | | |
| | | use JVBase\managers\Cache; |
| | | use JVBase\managers\Roles; |
| | | use WP_REST_Request; |
| | | use WP_REST_Response; |
| | | use WP_Query; |
| | |
| | | public function __construct(string $post_type, array $config = []) |
| | | { |
| | | $this->post_type = $post_type; |
| | | $this->cache = Cache::for(jvbNoBase($post_type), WEEK_IN_SECONDS)->connect('post', true); |
| | | $this->cache = Cache::for(jvbNoBase($post_type), 'post',WEEK_IN_SECONDS); |
| | | |
| | | $this->config = wp_parse_args($config, [ |
| | | 'multiple' => true, |
| | |
| | | } |
| | | |
| | | // 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); |
| | | } |
| | |
| | | ]; |
| | | |
| | | // 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); |
| | | } |
| | |
| | | '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' => [ |