Exemplo n.º 1
0
 /**
  * Expand known postmeta macros in the content
  *
  * Very literal, it will treat all the macros as postmeta macros.
  *
  * @param  string $content Content to expand macros in
  * @param  mixed $post Post to fetch metas for
  * @return string Expanded content
  */
 public function expand_all($content, $post)
 {
     if (empty($content)) {
         return $content;
     }
     if (empty($post)) {
         return $content;
     }
     $tags = $this->get_tags($content);
     if (empty($tags)) {
         return $content;
     }
     $post_id = false;
     if (!is_object($post) && is_numeric($post)) {
         $post_id = $post;
         $post = get_post($post_id);
     } else {
         $post_id = !empty($post->ID) ? $post->ID : false;
     }
     $metadata = Upfront_PostmetaModel::get_post_meta_fields($post_id, $tags);
     foreach ($metadata as $item) {
         if (empty($item['meta_key'])) {
             continue;
         }
         $key = $item['meta_key'];
         $value = $this->get_extracted_value($item, $post_id);
         $content = $this->expand($content, $key, $value);
     }
     // Re-iterate through tags and null out empty replacement macros.
     foreach ($tags as $tag) {
         $content = $this->expand($content, $tag, '');
     }
     return $content;
 }