cache = Cache::for('menu', WEEK_IN_SECONDS)->connectTo('post', 'menu_item');
add_action('init', [ $this, 'registerBlock' ]);
}
public function registerBlock()
{
register_block_type($this->path, [
'render_callback' => [ $this, 'render' ]
]);
}
protected function buildParams():void
{
if (is_post_type_archive(BASE.'menu_item')) {
$this->params = ['all'];
} elseif (is_tax(BASE.'section')) {
jvbDump(get_queried_object());
$this->params = [];
} else {
$this->params = [];
}
}
public function render(array $attributes, string $content, WP_Block $block)
{
$this->buildParams();
if (empty($this->params)) {
return '';
}
$key = $this->cache->generateKey($this->params);
return $this->cache->remember(
$key,
function() {
ob_start();
$this->renderBlock();
return ob_get_clean();
}
);
}
protected function renderBlock():void
{
$this->renderHeader();
$this->renderMenu();
$this->renderOnThisPage();
}
protected function renderHeader():void
{
$title = 'Our Menu';
if(!in_array('all', $this->params)) {
$title = ''.$title.'';
}
?>
=$title?>