[$this, 'render'], ] ); } /** * Render callback * * @param array $attributes Block attributes * @param string $content Block content * @param WP_Block $block Block instance * @return string Rendered block HTML */ public function render(array $attributes, string $content, WP_Block $block):string { $menu_id = $attributes['menuId'] ?? ''; $collapsed = $attributes['collapsed'] ?? true; // You'd populate this from options, a filter, or however you store menu data $menu_items = apply_filters('jvbDrawerItems', [], $menu_id); if (empty($menu_items) || empty($menu_id)) { return '
Please configure the drawer menu in block settings.
'; } $cache = Cache::for('drawer'); if (JVB_TESTING) { $cache->flush(); } if (!is_front_page()) { $menu_items[] = [ 'text' => 'Home', 'url' => home_url(), 'icon' => 'house-simple', ]; } $items = array_map(function($item) { return $item['text'];}, $menu_items); $key = $cache->generateKey($items); $menu = $cache->remember($key, function () use ($menu_items, $menu_id, $collapsed) { $menu = new Navigation($menu_id); $menu->asDrawer($collapsed)->populateFromArray($menu_items); return $menu->render(); }); global $wp; $current = home_url($wp->request.'/'); return str_replace($current.'"', $current.'" class="current" aria-current="page"', $menu); } }