| | |
| | | <?php |
| | | namespace JVBase\managers\SEO; |
| | | |
| | | use JVBase\managers\CacheManager; |
| | | use JVBase\managers\Cache; |
| | | use JVBase\utility\Features; |
| | | use WP_Post; |
| | | use WP_Term; |
| | |
| | | */ |
| | | class BreadcrumbManager |
| | | { |
| | | private CacheManager $cache; |
| | | private Cache $cache; |
| | | private static ?self $instance = null; |
| | | |
| | | private function __construct() |
| | | { |
| | | $this->cache = CacheManager::for('breadcrumbs', MONTH_IN_SECONDS)->connectTo('all'); |
| | | $this->cache = Cache::for('breadcrumbs', MONTH_IN_SECONDS)->connect('post')->connect('taxonomy')->connect('user'); |
| | | if (JVB_TESTING) { |
| | | $this->cache->clear(); |
| | | $this->cache->flush(); |
| | | } |
| | | } |
| | | |
| | |
| | | break; |
| | | } |
| | | |
| | | $crumbs = $this->cache->get($key); |
| | | if ($crumbs !== false) { |
| | | return $crumbs; |
| | | } |
| | | |
| | | $crumbs = $this->buildCrumbs(); |
| | | $crumbs = apply_filters('jvbBreadcrumbs',$crumbs); |
| | | $this->cache->set($key, $crumbs); |
| | | |
| | | return $crumbs; |
| | | return $this->cache->remember( |
| | | $key, |
| | | function() { |
| | | $crumbs = $this->buildCrumbs(); |
| | | return apply_filters('jvbBreadcrumbs',$crumbs); |
| | | } |
| | | ); |
| | | } |
| | | |
| | | /** |
| | |
| | | { |
| | | $url = get_term_link($term->term_id); |
| | | array_unshift($crumbs, [ |
| | | 'name' => $term->name, |
| | | 'name' => html_entity_decode($term->name), |
| | | 'url' => $url, |
| | | 'id' => $term->term_id, |
| | | ]); |
| | |
| | | public function invalidateCache(?int $objectId = null): void |
| | | { |
| | | if ($objectId) { |
| | | $this->cache->delete($objectId); |
| | | $this->cache->forget($objectId); |
| | | } else { |
| | | $this->cache->clear(); |
| | | $this->cache->flush(); |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | } |
| | | $crumbs[] = [ |
| | | 'name' => $term->name, |
| | | 'name' => html_entity_decode($term->name), |
| | | 'url' => get_term_link($term, $taxonomy) |
| | | ]; |
| | | } |