/** * Add active class to menu of post type single template * * @param array $css_classes * * @return array */ public function addActive($css_classes) { $custom_post_type = PostType::get_custom_post_type(); if (\is_single() && \is_singular($custom_post_type) || \is_tax()) { // check - Post is a Custom Post Type $css_classes = \array_filter($css_classes, array($this, 'removeActiveClass')); //get all registered custom post type templates foreach ($custom_post_type as $post_type) { if ($post_type === get_post_type()) { $searching_slug = array(); $templates = PostTypeAbstract::getTemplates($post_type); if (!is_null($templates)) { $pages = Page::getPageByTemplate($templates); foreach ($pages as $page) { $slag = sanitize_title($page->post_title); $searching_slug[] = 'menu-' . $slag; } if (array_intersect($searching_slug, $css_classes)) { $css_classes[] = 'active'; } } } } } return $css_classes; }
/** * * get list of pages where page template is assigned * * @param string $post_type - post type name * * @return array * @static * @access public */ public static function getPagesByTemplates($post_type) { $pages_object = array(); $templates = PostTypeAbstract::getTemplates($post_type); $pages = self::getPageByTemplate($templates); foreach ($pages as $page) { $pages_object[] = $page; } return $pages_object; }
/** * Set relation To with post type * * @param PostTypeAbstract $post_type * * @return $this * @throws Exception * * @access public */ public function setTo(PostTypeAbstract $post_type) { if ($post_type instanceof PostTypeAbstract) { $this->settings['to'] = $post_type->getName(); } else { throw new Exception(Translate::translate('The param $post_type isn\'t instance of \\SilverWp\\PostType\\PostTypeAbstract')); } return $this; }
/** * Check the post type supports title * * @return boolean * @access public * @since 0.3 */ public function isTitle() { $is_title = \in_array('title', $this->post_type->getSupports()); return $is_title; }