/** * Get list of currently available archives slugs that has a template * @return array */ public static function getArchiveTemplateSlugs() { $archives = get_post_types(array('has_archive' => true), 'names'); $templates = array(); foreach ($archives as $archive) { $template = \Modularity\Helper\Wp::findCoreTemplates(array('archive-' . $archive)); if ($template) { $templates[] = $template; } else { $templates[] = 'archive'; } } array_unique($templates); return $templates; }
/** * Detects core templates * @return string Template */ public static function detectCoreTemplate($post) { if ((int) get_option('page_on_front') == (int) $post->ID) { return \Modularity\Helper\Wp::findCoreTemplates(array('front-page', 'page')); } switch ($post->post_type) { case 'post': return 'single'; break; case 'page': return 'page'; break; default: return \Modularity\Helper\Wp::findCoreTemplates(array('single-' . $post->post_type, 'single', 'page')); break; } return 'index'; }
public function isModularitySidebarActive($sidebar) { $template = \Modularity\Helper\Post::getPostTemplate(); if (!file_exists($template)) { $template = \Modularity\Helper\Wp::findCoreTemplates([$template, 'archive']); } $options = get_option('modularity-options'); if (is_home()) { $template = 'home'; } if (!isset($options['enabled-areas'][$template]) || !in_array($sidebar, $options['enabled-areas'][$template])) { return false; } return true; }
/** * Get active areas for template. * If nothing found on the specific template (eg. archive-cars), fallback to the default template (eg. archive) * @param string $template Template * @return array Active sidebars */ public function getActiveAreas($template) { $originalTemplate = $template; $options = get_option('modularity-options'); $active = isset($options['enabled-areas'][$template]) ? $options['enabled-areas'][$template] : array(); self::$isEditing['template'] = $template; // Fallback if (count($active) === 0 && !is_numeric($template) && strpos($template, 'archive-') !== false && !in_array($template, \Modularity\Options\Archives::getArchiveTemplateSlugs())) { $template = explode('-', $template, 2)[0]; self::$isEditing['template'] = $template; $active = isset($options['enabled-areas'][$template]) ? $options['enabled-areas'][$template] : array(); } if (self::$isEditing['title'] == 'archive-post') { $home = \Modularity\Helper\Wp::findCoreTemplates(array('home')); if ($home) { $active = isset($options['enabled-areas']['home']) ? $options['enabled-areas']['home'] : array(); self::$isEditing['template'] = 'home'; } } return $active; }