PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.8.9
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.8.9
4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 All 200 releases
← All changes | includes/FrontEnd/TemplateLoader.php +187 -105 3.4.23.8.9 View file →
@@ -1,7 +1,8 @@
1 1 <?php
2 2
3 3 namespace WPDeveloper\BetterDocs\FrontEnd;
4 +
4 5 use WPDeveloper\BetterDocs\Utils\Base;
5 6 use WPDeveloper\BetterDocs\Utils\Views;
6 7 use WPDeveloper\BetterDocs\Utils\Database;
7 8 use WPDeveloper\BetterDocs\Dependencies\DI\Container;
@@ -6,133 +7,214 @@
6 7 use WPDeveloper\BetterDocs\Utils\Database;
7 8 use WPDeveloper\BetterDocs\Dependencies\DI\Container;
8 9
9 10 class TemplateLoader extends Base {
10 - public $is_fse_theme = false;
11 - private $templates_dir;
12 - private $block_templates_dir;
13 - private $container;
14 - private $database;
15 - private $views;
11 + public $is_fse_theme = false;
12 + private $templates_dir;
13 + private $block_templates_dir;
14 + private $container;
15 + private $database;
16 + private $views;
16 17
17 - public function __construct( Container $container ) {
18 - $this->container = $container;
19 - $this->database = $this->container->get( Database::class );
20 - $this->views = $this->container->get( Views::class );
21 - }
18 + public function __construct( Container $container ) {
19 + $this->container = $container;
20 + $this->database = $this->container->get( Database::class );
21 + $this->views = $this->container->get( Views::class );
22 + }
22 23
23 - public function init() {
24 - $this->is_fse_theme = $this->is_fse_theme();
24 + public function init() {
25 + $this->is_fse_theme = $this->is_fse_theme();
25 26
26 - if ( $this->is_fse_theme ) {
27 - // @todo: for FSE theme
28 - }
27 + if ( $this->is_fse_theme ) {
28 + // @todo: for FSE theme
29 + }
29 30
30 - if ( ! $this->is_fse_theme ) {
31 - add_filter( 'archive_template', [$this, 'archive_template'] );
32 - add_filter( 'single_template', [$this, 'single_template'] );
33 - }
34 - }
31 + if ( ! $this->is_fse_theme ) {
32 + add_filter( 'archive_template', [ $this, 'archive_template' ] );
33 + add_filter( 'single_template', [ $this, 'single_template' ] );
34 + }
35 + }
35 36
36 - /**
37 - * Render Thrive Header Markup
38 - *
39 - * @return void
40 - */
41 - public function render_thrive_header() {
42 - echo '<div id="wrapper">'.thrive_template()->render_theme_hf_section( THRIVE_HEADER_SECTION ).'<div id="content"><div class="main-container">';
43 - }
37 + /**
38 + * Render Thrive Header Markup
39 + *
40 + * Outputs the header section and starts the main container for the page content.
41 + *
42 + * @return void
43 + */
44 + public function render_thrive_header() {
45 + // Retrieve and sanitize the header content allowing limited HTML
46 + $header_content = thrive_template()->render_theme_hf_section( THRIVE_HEADER_SECTION );
47 + echo '<div id="wrapper">' . wp_kses_post( $header_content ) . '<div id="content"><div class="main-container">';
48 + }
44 49
45 - /**
46 - * Render Thrive Footer Markup
47 - *
48 - * @return void
49 - */
50 - public function render_thrive_footer() {
51 - echo '</div></div>'.thrive_template()->render_theme_hf_section( THRIVE_FOOTER_SECTION ).'</div>';
52 - }
50 + /**
51 + * Render Thrive Footer Markup
52 + *
53 + * Outputs the footer section and closes the main content container.
54 + *
55 + * @return void
56 + */
57 + public function render_thrive_footer() {
58 + // Retrieve and sanitize the footer content allowing limited HTML
59 + $footer_content = thrive_template()->render_theme_hf_section( THRIVE_FOOTER_SECTION );
60 + echo '</div></div>' . wp_kses_post( $footer_content ) . '</div>';
61 + }
53 62
54 - public function archive_template( $template ) {
55 - if ( get_post_type() !== 'docs' ) {
56 - return $template;
57 - }
58 63
59 - if ( is_embed() ) {
60 - return $template;
61 - }
64 + /**
65 + * Returns the archive template for the 'docs' custom post type.
66 + * If the post type is not 'docs' or it's an embed request, returns the original template.
67 + * If custom archive templates are found in the theme, returns the appropriate template.
68 + * Otherwise, returns the default archive template based on the selected layout.
69 + * @param string $template The original template.
70 + * @return string The archive template.
71 + */
72 + public function archive_template( $template ) {
62 73
63 - $_default_template = 'templates/archives/layout-1';
64 - $layout = $this->database->get_theme_mod( 'betterdocs_docs_layout_select', 'layout-1' );
65 - $_template = 'templates/archives/' . $layout;
74 + if ( is_tax( 'glossaries' ) ) {
75 + // Use a custom taxonomy template for your custom taxonomy
66 76
67 - if ( is_tax( 'doc_category' ) ) {
68 - $_template = 'templates/taxonomy-doc_category';
69 - $_default_template = $_template;
70 - } elseif ( is_tax( 'doc_tag' ) ) {
71 - $_template = 'templates/taxonomy-doc_tag';
72 - $_default_template = $_template;
73 - }
77 + $_default_template = 'templates/single/layout-1';
78 + $layout = 'templates/single/layout-7';
74 79
75 - $eligible_template = $this->views->path( $_template, $_default_template );
80 + $eligible_template = $this->views->path( $layout, $_default_template );
76 81
77 - //Render The Header Footer When Thrive Builder Theme Is Activated
78 - if( wp_get_theme() == 'Thrive Theme Builder' ){
79 - $this->render_thrive_header_footer();
80 - }
82 + if ( file_exists( $eligible_template ) ) {
83 + $template = &$eligible_template;
84 + }
81 85
82 - if ( file_exists( $eligible_template ) ) {
83 - $template = &$eligible_template;
84 - }
86 + return apply_filters( 'betterdocs_archives_template', $template, $layout, $_default_template, $this->views );
87 + }
85 88
86 - return apply_filters( 'betterdocs_archives_template', $template, $layout, $_default_template, $this->views );
87 - }
89 + if ( get_post_type() !== 'docs' ) {
90 + return $template;
91 + }
88 92
89 - /**
90 - * Render Thriver Header Footer When Thrive Theme Is Activated
91 - *
92 - * @return void
93 - */
94 - public function render_thrive_header_footer() {
95 - add_action( 'get_header', [$this, 'render_thrive_header'], 10 );
96 - add_action( 'get_footer', [$this, 'render_thrive_footer'], 10 );
97 - }
93 + if ( is_embed() ) {
94 + return $template;
95 + }
98 96
99 - public function single_template( $template ) {
100 - if ( ! is_singular( 'docs' ) ) {
101 - return $template;
102 - }
97 + if ( $this->locate_archives() ) {
98 + return $this->locate_archives();
99 + }
103 100
104 - //Render The Header Footer When Thrive Builder Theme Is Activated
105 - if( wp_get_theme() == 'Thrive Theme Builder' ){
106 - $this->render_thrive_header_footer();
107 - }
101 + $_default_template = 'templates/archives/layout-1';
102 + $layout = $this->database->get_theme_mod( 'betterdocs_docs_layout_select', 'layout-7' );
103 + $_template = 'templates/archives/' . $layout;
108 104
109 - $_default_template = 'templates/single/layout-1';
110 - $layout = $this->database->get_theme_mod( 'betterdocs_single_layout_select', 'layout-1' );
111 - $layout = 'templates/single/' . $layout;
105 + if ( is_tax( 'doc_category' ) ) {
106 + $category_layout = $this->database->get_theme_mod( 'betterdocs_archive_layout_select', 'layout-7' );
107 + if ( $category_layout == 'layout-7' ) {
108 + $_template = 'templates/archives/categories/' . $category_layout;
109 + } else {
110 + $_template = 'templates/taxonomy-doc_category';
111 + }
112 + $_default_template = $_template;
113 + } elseif ( is_tax( 'doc_tag' ) ) {
114 + $_template = 'templates/taxonomy-doc_tag';
115 + $_default_template = $_template;
116 + }
112 117
113 - $eligible_template = $this->views->path( $layout, $_default_template );
118 + $eligible_template = $this->views->path( $_template, $_default_template );
114 119
115 - if ( file_exists( $eligible_template ) ) {
116 - $template = &$eligible_template;
117 - }
120 + //Render The Header Footer When Thrive Builder Theme Is Activated
121 + if ( wp_get_theme() == 'Thrive Theme Builder' ) {
122 + $this->render_thrive_header_footer();
123 + }
118 124
119 - return apply_filters( 'betterdocs_single_template', $template, $layout, $_default_template, $this->views );
120 - }
125 + if ( file_exists( $eligible_template ) ) {
126 + $template = &$eligible_template;
127 + }
121 128
122 - /**
123 - * Summary of is_fse_theme
124 - * @return bool
125 - *
126 - * @suppress PHP0417
127 - */
128 - private function is_fse_theme() {
129 - if ( function_exists( 'wp_is_block_theme' ) ) {
130 - return (bool) wp_is_block_theme();
131 - }
132 - if ( function_exists( 'gutenberg_is_fse_theme' ) ) {
133 - return (bool) gutenberg_is_fse_theme();
134 - }
129 + return apply_filters( 'betterdocs_archives_template', $template, $layout, $_default_template, $this->views );
130 + }
135 131
136 - return false;
137 - }
132 + /**
133 + * Locates custom archive templates from the theme.
134 + * Checks for 'archive-docs.php', 'taxonomy-doc_category.php', 'taxonomy-doc_tag.php', and 'taxonomy-knowledge_base.php'.
135 + * Returns the template path if found, otherwise returns false.
136 + * @return string|false The template path or false if not found.
137 + */
138 + public function locate_archives() {
139 + $archive_docs = locate_template( 'archive-docs.php' );
140 + $doc_category = locate_template( 'taxonomy-doc_category.php' );
141 + $doc_tag = locate_template( 'taxonomy-doc_tag.php' );
142 + $knowledge_base = locate_template( 'taxonomy-knowledge_base.php' );
143 +
144 + if ( is_post_type_archive( 'docs' ) && $archive_docs ) {
145 + return $archive_docs;
146 + } elseif ( is_tax( 'doc_category' ) && $doc_category ) {
147 + return $doc_category;
148 + } elseif ( is_tax( 'doc_tag' ) && $doc_tag ) {
149 + return $doc_tag;
150 + } elseif ( is_tax( 'knowledge_base' ) && $archive_docs ) {
151 + return $knowledge_base;
152 + }
153 +
154 + return false;
155 + }
156 +
157 + /**
158 + * Render Thriver Header Footer When Thrive Theme Is Activated
159 + *
160 + * @return void
161 + */
162 + public function render_thrive_header_footer() {
163 + add_action( 'get_header', [ $this, 'render_thrive_header' ], 10 );
164 + add_action( 'get_footer', [ $this, 'render_thrive_footer' ], 10 );
165 + }
166 +
167 + /**
168 + * Returns the template for single 'docs' custom post type.
169 + * If the current post type is not 'docs', returns the original template.
170 + * If 'single-docs.php' exists in the theme, returns it.
171 + * Otherwise, returns the default single template based on the selected layout.
172 + * @param string $template The original template.
173 + * @return string The single template.
174 + */
175 + public function single_template( $template ) {
176 + if ( ! is_singular( 'docs' ) ) {
177 + return $template;
178 + }
179 +
180 + // If 'single-docs.php' exists in the theme, return it
181 + $theme_template = locate_template( 'single-docs.php' );
182 + if ( $theme_template ) {
183 + return $theme_template;
184 + }
185 +
186 + //Render The Header Footer When Thrive Builder Theme Is Activated
187 + if ( wp_get_theme() == 'Thrive Theme Builder' ) {
188 + $this->render_thrive_header_footer();
189 + }
190 +
191 + $_default_template = 'templates/single/layout-1';
192 + $layout = $this->database->get_theme_mod( 'betterdocs_single_layout_select', 'layout-8' );
193 + $layout = 'templates/single/' . $layout;
194 +
195 + $eligible_template = $this->views->path( $layout, $_default_template );
196 +
197 + if ( file_exists( $eligible_template ) ) {
198 + $template = &$eligible_template;
199 + }
200 +
201 + return apply_filters( 'betterdocs_single_template', $template, $layout, $_default_template, $this->views );
202 + }
203 +
204 + /**
205 + * Summary of is_fse_theme
206 + * @return bool
207 + *
208 + * @suppress PHP0417
209 + */
210 + private function is_fse_theme() {
211 + if ( function_exists( 'wp_is_block_theme' ) ) {
212 + return (bool) wp_is_block_theme();
213 + }
214 + if ( function_exists( 'gutenberg_is_fse_theme' ) ) {
215 + return (bool) gutenberg_is_fse_theme();
216 + }
217 +
218 + return false;
219 + }
138 220 }