Exemplo n.º 1
0
 /**
  * Prepares a collection of posts
  *
  * @param array $posts
  * @param bool $include_terms
  *
  * @return array
  */
 public function prepare_collection(array $posts = [], $include_terms = true)
 {
     $cache = apply_filters($this->filter_base . 'prepare/post/cache', true, $posts);
     if ($cache && !is_admin()) {
         $prepared_posts = $this->cache->get($this->get_cache_key($posts));
         if ($prepared_posts !== false) {
             return $prepared_posts;
         }
     }
     $prepared_posts = [];
     $meta = $this->get_meta($posts);
     if ($include_terms) {
         $terms = $this->get_terms($posts);
     } else {
         $terms = [];
     }
     foreach ($posts as $post) {
         if ($post instanceof WP_Post) {
             $prepared_posts[] = $this->prepare($post, $meta, $terms);
         }
     }
     if ($cache && !is_admin() && !empty($prepared_posts)) {
         $this->cache->add($this->get_cache_key($posts), $prepared_posts);
     }
     return $posts;
 }
Exemplo n.º 2
0
 /**
  * Maps term meta to terms
  *
  * @param $terms
  *
  * @return array
  */
 public function prepare_collection(array $terms = [])
 {
     $cache = apply_filters($this->filter_base . 'prepare/term/cache', true, $terms);
     if ($cache && !is_admin()) {
         $prepared_terms = $this->cache->get($this->get_cache_key($terms));
         if ($prepared_terms !== false) {
             return $prepared_terms;
         }
     }
     $prepared_terms = [];
     $meta = $this->get_meta($terms);
     foreach ($terms as $term) {
         if ($term instanceof WP_Term) {
             $prepared_terms[] = $this->prepare($term, $meta);
         }
     }
     if ($cache && !is_admin() && !empty($prepared_terms)) {
         $this->cache->add($this->get_cache_key($terms), $prepared_terms);
     }
     return $prepared_terms;
 }