cache = Cache::for('timelines', WEEK_IN_SECONDS)->connect('post'); if (JVB_TESTING){ $this->cache->flush(); } add_action('init', [ $this, 'registerBlock' ]); add_action('wp_footer', 'jvbRenderGallery'); } public function registerBlock() { register_block_type($this->path, [ 'render_callback' => [ $this, 'render' ] ]); } public function render(array $attributes, string $content, WP_Block $block) { global $post; $registrar = Registrar::getInstance($post->post_type); if (!$post || !$registrar || !$registrar->hasFeature('is_timeline') ) { return ''; } $this->parentID = $post->ID; $cache = $this->cache->get($this->parentID); if ($cache) { return $cache; } $this->content = jvbNoBase($post->post_type); $this->children = get_children([ 'post_parent' => $this->parentID, 'post_status' => 'publish', 'orderby' => 'date', 'order' => 'ASC', 'fields' => 'ids' ]); $this->total = count($this->children); ob_start(); $this->renderBlock(); $content = ob_get_clean(); $this->cache->set($this->parentID, $content); return $content; } protected function renderBlock():void { $this->renderHeader(); $this->renderTimeline(); } protected function get_field(string $fieldName, array $fields) { if (array_key_exists($fieldName, $fields)) { return $fields[$fieldName]; } return ''; } protected function renderHeader():void { $meta = Meta::forPost($this->parentID); $sharedFields = JVB()->routes('content')->getTimelineSharedFields($this->content); $fields = $meta->getAll($sharedFields); $extra = $meta->getAll(); ?>

Before and After Laser Tattoo Removal:get_field('post_title', $extra)?>

Before

parentID), 'tiny', 'large', false) ?>
children)) :?>

After total?> Treatmenttotal > 1 ? 's' : '' ?>

children[count($this->children)-1]), 'tiny', 'large', false) ?>
get_field('post_content', $extra); if ($content !== '') { echo $this->formatContent($content); } ?>
'; } $out .= wptexturize(wp_kses_post( wpautop($content))); if ($wrap) { $out .= ''; } return $out; } protected function renderTimeline():void { $all = $this->children; array_unshift($all, $this->parentID); $uniqueFields = JVB()->routes('content')->getTimelineUniqueFields($this->content); foreach ($all as $i => $ID) { $meta = Meta::forPost($ID); $fields = $meta->getAll($uniqueFields); $plural = ($i>1) ? 's': ''; $title = ($i === 0) ? 'Before Laser Tattoo Removal' : 'After '.$i.' Treatment'.$plural; $title = ($i > 0 && !str_contains('Treatment', $fields['post_title'])) ? $fields['post_title'] : $title; ?>
get_field('post_thumbnail', $fields); if (is_int($img)) { echo jvbFormatImage($img); } ?>

get_field('post_date', $fields); if ($date !== '') { echo ''; } echo $this->outputTimelineTax($ID); $content = $this->get_field('post_content', $fields); if ($i > 0 && $content !== '') { echo $this->formatContent($this->get_field('post_content', $fields)); } ?>
'; $registrar = Registrar::getInstance('timeline'); foreach ($timeline as $term) { $link = get_term_link($term->term_id, BASE.'timeline'); $out .= '
  • after the treatment
  • '; } $out .=''; return $out; } }