tag in the document head, and expect WordPress to * provide it for us. */ add_theme_support( 'title-tag' ); /* * Enable support for Post Thumbnails on posts and pages. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/ */ add_theme_support( 'post-thumbnails' ); // This theme uses wp_nav_menu() in one location. register_nav_menus( array( 'header-menu' => esc_html__( 'Header Menu', 'easydita_knowledge_portal' ), ) ); /* * Switch default core markup for search form, comment form, and comments * to output valid HTML5. */ add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list', 'gallery', 'caption', ) ); /* * Enable support for Post Formats. * See https://developer.wordpress.org/themes/functionality/post-formats/ */ add_theme_support( 'post-formats', array( 'aside', 'image', 'video', 'quote', 'link', ) ); // Set up the WordPress core custom background feature. add_theme_support( 'custom-background', apply_filters( 'easydita_knowledge_portal_custom_background_args', array( 'default-color' => 'ffffff', 'default-image' => '', ) ) ); } endif; // easydita_knowledge_portal_setup add_action( 'after_setup_theme', 'easydita_knowledge_portal_setup' ); /** * Set the content width in pixels, based on the theme's design and stylesheet. * Priority 0 to make it available to lower priority callbacks. * * @global int $content_width */ function easydita_knowledge_portal_content_width() { $GLOBALS['content_width'] = apply_filters( 'easydita_knowledge_portal_content_width', 640 ); } add_action( 'after_setup_theme', 'easydita_knowledge_portal_content_width', 0 ); /** * Register widget area. * * @link https://developer.wordpress.org/themes/functionality/sidebars/#registering-a-sidebar */ function easydita_knowledge_portal_widgets_init() { register_sidebar( array( 'name' => esc_html__( 'Sidebar', 'easydita_knowledge_portal' ), 'id' => 'sidebar-1', 'description' => '', 'before_widget' => '
', 'before_title' => '

', 'after_title' => '

', ) ); } add_action( 'widgets_init', 'easydita_knowledge_portal_widgets_init' ); /** * Enqueue scripts and styles. */ function easydita_knowledge_portal_scripts() { wp_enqueue_style( 'easydita-knowledge-portal-style', get_stylesheet_uri() ); wp_enqueue_style( 'font-awesome', get_template_directory_uri() . '/lib/font-awesome-4.5.0/css/font-awesome.min.css' ); wp_enqueue_script( 'easydita-knowledge-portal-navigation', get_template_directory_uri() . '/js/navigation.js', array(), '20120206', true ); wp_enqueue_script( 'easydita-knowledge-portal-skip-link-focus-fix', get_template_directory_uri() . '/js/skip-link-focus-fix.js', array(), '20130115', true ); if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } } add_action( 'wp_enqueue_scripts', 'easydita_knowledge_portal_scripts' ); /** * Allow changing of default version number on style.css to circumvent caching * This should always be commented out in production */ function easydita_knowledge_portal_change_style_version_num($styles) { $styles -> default_version = "123"; } //add_action("wp_default_styles", "easydita_knowledge_portal_change_style_version_num"); /** * Is Versioning Enabled? **/ if (!function_exists('easydita_knowledge_portal_is_versioning_enabled')) { function easydita_knowledge_portal_is_versioning_enabled() { return get_theme_mod('versioning_enabled','no') == 'yes'; } } /*** * Hierarchy Functions ***/ // Walk the hierarchy and return an array of IDs if (!function_exists('easydita_knowledge_portal_get_hierarchy')) { function easydita_knowledge_portal_get_hierarchy() { global $post; $hierarchy = array(); if($post->ID) { $hierarchy[] = $post->ID; $parent_id = $post->post_parent; while ($parent_id) { $hierarchy[] = $parent_id; $page = get_post($parent_id); $parent_id = $page->post_parent; } return array_reverse($hierarchy); } return array(0); } } if (!function_exists('easydita_knowledge_portal_get_hierarchy_of')) { function easydita_knowledge_portal_get_hierarchy_of($post) { $hierarchy = array(); if($post->ID) { $hierarchy[] = $post->ID; $parent_id = $post->post_parent; while ($parent_id) { $hierarchy[] = $parent_id; $page = get_post($parent_id); $parent_id = $page->post_parent; } return array_reverse($hierarchy); } return array(0); } } if (!function_exists('easydita_knowledge_portal_get_root_map_id')) { function easydita_knowledge_portal_get_root_map_id() { /** get the title for the root map this is a member of **/ $hierarchy = easydita_knowledge_portal_get_hierarchy(); if (easydita_knowledge_portal_is_versioning_enabled()) { return $hierarchy[1]; } else { return $hierarchy[0]; } } } /** * Get version id of easyDITA if versioning is enabled **/ if (!function_exists('easydita_knowledge_portal_get_version_id')) { function easydita_knowledge_portal_get_version_id() { if (!easydita_knowledge_portal_is_versioning_enabled()) { return 0; } else if (isset($_GET['version'])) { $versionId = $_GET['version']; } else if (is_front_page()) { $versionId = get_pages("parent=0&post_type=page&sort_column=menu_order")[0]->ID; } else { $hierarchy = easydita_knowledge_portal_get_hierarchy(); $versionId = $hierarchy[0]; } return $versionId; } } if (!function_exists('easydita_knowledge_portal_get_version_id_of')) { function easydita_knowledge_portal_get_version_id_of($post) { if (!easydita_knowledge_portal_is_versioning_enabled()) { return 0; } else { $hierarchy = easydita_knowledge_portal_get_hierarchy_of($post); $versionId = $hierarchy[0]; return $versionId; } } } /*** * Takes content of a page and parses it to return divs with the "topic-title" class. This is used in DITA to denote a subsection of a page ***/ if (!function_exists('easydita_knowledge_portal_get_subsections')) { function easydita_knowledge_portal_get_subsections() { global $post; $content = $post->post_content; preg_match_all('#]*class="[^"]*topic-title [^"]*"[^>]*>((.*?)|(.))*?#', $content, $matches); return $matches[0]; } } /** * Takes content of a page and parses it to return just the text from a div with the "shortdesc" class. This is used in DITA as the summary of the page **/ if (!function_exists('easydita_knowledge_portal_get_the_shortdesc')) { function easydita_knowledge_portal_get_the_shortdesc() { global $post; if ($post->post_content != '') { preg_match('#]*class="[^"]*topic-shortdesc [^"]*"[^>]*>((.*?)|(.))*?#', $post->post_content, $matches); $output = preg_replace('#<[^>]*>#','',$matches[0]); echo $output; } else { $out_string = ""; $args = array( "post_type" => "page", "post_parent" => $post->ID, "orderby" => "menu_order", "order" => "ASC" ); $the_query = new WP_Query( $args ); $count = $the_query->post_count; $i = 1; while($the_query->have_posts()) { $the_query->the_post(); ?> "Default" ); if (!file_exists($root_folder)) { return $skins; } $skin_files = scandir($root_folder); foreach ($skin_files as $i => $file) { if (strlen($file) < 4 || substr($file,strlen($file)-4) != '.css') { continue; } $contents = wp_remote_get($root_url.$file)['body']; $title = preg_match("/\/\*\n\s*Skin Name:\s*(.*?)(\n|Author:)/",$contents,$matches); $version = preg_match("/\/\*(\n|.)*?Version:\s*(.*?)(\n)/",$contents,$version_matches); if ($title != "") { $skins[$file."?ver=".$version_matches[2]] = $matches[1]; }; } return $skins; } } /** * Filter search to current version **/ if (!function_exists('easydita_knowledge_portal_filter_search_versions')) { function easydita_knowledge_portal_filter_search_versions($posts, $query) { if (is_admin() || !$query->is_search()) { return $posts; } $filteredPosts = array(); $currentVersionId = easydita_knowledge_portal_get_version_id(); foreach ($posts as $post) { $pageVersionId = easydita_knowledge_portal_get_version_id_of($post); if ($pageVersionId == $currentVersionId) { $filteredPosts[] = $post; } } return $filteredPosts; } } if (easydita_knowledge_portal_is_versioning_enabled()) { add_filter('posts_results','easydita_knowledge_portal_filter_search_versions', 10, 2); } /** * Add the skin to the header if necessary **/ function easydita_knowledge_portal_add_skin_stylesheet() { $skin = get_theme_mod('skin','default'); if ($skin != 'default') { $href = get_template_directory_uri()."/skins/".$skin; echo ''; } } add_action('wp_head','easydita_knowledge_portal_add_skin_stylesheet'); /** * Add JQuery **/ wp_enqueue_script("jquery"); /** * Implement the Custom Header feature. */ require get_template_directory() . '/inc/custom-header.php'; /** * Custom template tags for this theme. */ require get_template_directory() . '/inc/template-tags.php'; /** * Customizer additions. */ require get_template_directory() . '/inc/customizer.php'; /** * Load Jetpack compatibility file. */ require get_template_directory() . '/inc/jetpack.php'; /** * Add custom PHP from skin **/ if (get_theme_mod('skin','default') != 'default') { $skinname = explode(".css",get_theme_mod('skin','default'),2)[0]; $php_path = get_template_directory() . "/skins/" . $skinname . "/" . $skinname . ".php"; if (file_exists($php_path)) { require $php_path; } }