/** * routing to interpret our custom URLs * @param string $template the template being passed * @return string the template found (or not found) */ static function template_chooser($template) { if (is_admin()) { return $template; } // if url doesn't include our slug, return if (strpos($_SERVER['REQUEST_URI'], sprintf('/%s/', Kanban::$slug)) === FALSE) { return $template; } // allow for additional pages self::$page_slugs = apply_filters(sprintf('%s_template_pages', Kanban::get_instance()->settings->basename), self::$page_slugs); foreach (self::$page_slugs as $slug => $data) { if (strpos(strtok($_SERVER["REQUEST_URI"], '?'), sprintf('%s/%s', Kanban::$slug, $slug)) !== FALSE) { $template = Kanban_Template::find_template($slug); if (!empty($template)) { self::get_instance()->slug = $slug; if (isset($data['style'])) { foreach ($data['style'] as $handle => $path) { if (!isset(self::get_instance()->style) || !is_array(self::get_instance()->style)) { self::get_instance()->style = array(); } if (strpos($path, '%s') !== FALSE) { $path = sprintf($path, Kanban::get_instance()->settings->uri); } self::get_instance()->style[$handle] = $path; } } if (isset($data['script'])) { foreach ($data['script'] as $handle => $path) { if (!isset(self::get_instance()->script) || !is_array(self::get_instance()->script)) { self::get_instance()->script = array(); } if (strpos($path, '%s') !== FALSE) { $path = sprintf($path, Kanban::get_instance()->settings->uri); } self::get_instance()->script[$handle] = $path; } } } } } self::get_instance()->template = $template; // page found. set the header status_header(200); // allow additional templates return apply_filters(sprintf('%s_after_template_chooser', Kanban::get_instance()->settings->basename), $template); }
static function init() { self::$page_slugs = apply_filters('kanban_template_init_slugs', self::$page_slugs); add_action('init', array(__CLASS__, 'protect_slug')); add_filter('template_include', array(__CLASS__, 'template_chooser'), 99); }