/** * Singleton * * @param string $class */ public static function get_instance($class = '') { if (empty($class)) { $class = get_called_class(); } if (!class_exists($class)) { wp_die(sprintf(__('Class "%s" not found.', 'boilerplate'), $class)); } if (!isset(static::$instances[$class])) { static::$instances[$class] = new $class(); if (!empty(static::$instances[$class]->obj_type)) { $all = \boilerplate\Objects\All::get_instance(); $all::$post_types[static::$instances[$class]->obj_type] = static::$instances[$class]; } } return static::$instances[$class]; }
public function archive_link($link, $post_type) { /** Emulate Polylang's "cached" collection */ if (isset($this->_links[$link])) { return $this->_links[$link]; } if (isset(static::$post_types[$post_type])) { $obj_inst = static::$post_types[$post_type]; if ($obj_inst->obj_page) { $link = get_permalink(pll_get_post($obj_inst->obj_page)); $this->_links[$link] = $link; } } return $link; } /** * Retrieve the title for a post type archive. */ public function archive_title($title, $post_type) { if (isset(static::$post_types[$post_type])) { $obj_inst = static::$post_types[$post_type]; if ($obj_inst->obj_page) { $title = get_the_title(pll_get_post($obj_inst->obj_page)); } } return $title; } } All::get_instance();