PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 3.5.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v3.5.3
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 +106 -231 4.5.63.5.3 View file →
@@ -1,12 +1,7 @@
1 1 <?php
2 +
2 3 namespace WPDeveloper\BetterDocs\FrontEnd;
3 -
4 -if ( ! defined( 'ABSPATH' ) ) {
5 - exit;
6 -}
7 -
8 -
9 4 use WPDeveloper\BetterDocs\Utils\Base;
10 5 use WPDeveloper\BetterDocs\Utils\Views;
11 6 use WPDeveloper\BetterDocs\Utils\Database;
12 7 use WPDeveloper\BetterDocs\Dependencies\DI\Container;
@@ -11,253 +6,133 @@
11 6 use WPDeveloper\BetterDocs\Utils\Database;
12 7 use WPDeveloper\BetterDocs\Dependencies\DI\Container;
13 8
14 9 class TemplateLoader extends Base {
15 - public $is_fse_theme = false;
16 - private $templates_dir;
17 - private $block_templates_dir;
18 - private $container;
19 - private $database;
20 - private $views;
10 + public $is_fse_theme = false;
11 + private $templates_dir;
12 + private $block_templates_dir;
13 + private $container;
14 + private $database;
15 + private $views;
21 16
22 - public function __construct( Container $container ) {
23 - $this->container = $container;
24 - $this->database = $this->container->get( Database::class );
25 - $this->views = $this->container->get( Views::class );
26 - }
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 + }
27 22
28 - public function init() {
29 - $this->is_fse_theme = $this->is_fse_theme();
23 + public function init() {
24 + $this->is_fse_theme = $this->is_fse_theme();
30 25
31 - if ( $this->is_fse_theme ) {
32 - // Block themes have no PHP template-hierarchy hook for the glossaries
33 - // (encyclopedia) taxonomy, so single glossary entries fall through to the
34 - // theme's default block template and render the generic docs/archive
35 - // output instead of the BetterDocs glossary template (fbs-79870). Force
36 - // the glossary template via template_include, which runs after
37 - // locate_block_template() so it wins over the block-template fallback.
38 - add_filter( 'template_include', [ $this, 'fse_glossaries_template' ], 99 );
39 - }
26 + if ( $this->is_fse_theme ) {
27 + // @todo: for FSE theme
28 + }
40 29
41 - if ( ! $this->is_fse_theme ) {
42 - add_filter( 'archive_template', [ $this, 'archive_template' ] );
43 - add_filter( 'single_template', [ $this, 'single_template' ] );
44 - }
45 - }
30 + if ( ! $this->is_fse_theme ) {
31 + add_filter( 'archive_template', [$this, 'archive_template'] );
32 + add_filter( 'single_template', [$this, 'single_template'] );
33 + }
34 + }
46 35
47 - /**
48 - * Load the BetterDocs glossary template for single glossary (encyclopedia)
49 - * taxonomy pages under block (FSE) themes. Mirrors the glossaries branch of
50 - * archive_template() used for classic themes. Runs late on template_include
51 - * so it overrides the block-template fallback that would otherwise render the
52 - * generic docs archive. (fbs-79870)
53 - *
54 - * @param string $template The template path resolved so far.
55 - * @return string
56 - */
57 - public function fse_glossaries_template( $template ) {
58 - if ( ! is_tax( 'glossaries' ) ) {
59 - return $template;
60 - }
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 + }
61 44
62 - $_default_template = 'templates/single/layout-1';
63 - $layout = 'templates/single/layout-7';
64 - $eligible_template = $this->views->path( $layout, $_default_template );
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 + }
65 53
66 - if ( file_exists( $eligible_template ) ) {
67 - $template = $eligible_template;
68 - }
54 + public function archive_template( $template ) {
55 + if ( get_post_type() !== 'docs' ) {
56 + return $template;
57 + }
69 58
70 - return apply_filters( 'betterdocs_archives_template', $template, $layout, $_default_template, $this->views );
71 - }
59 + if ( is_embed() ) {
60 + return $template;
61 + }
72 62
73 - /**
74 - * Render Thrive Header Markup
75 - *
76 - * Outputs the header section and starts the main container for the page content.
77 - *
78 - * @return void
79 - */
80 - public function render_thrive_header() {
81 - // Retrieve and sanitize the header content allowing limited HTML
82 - $header_content = thrive_template()->render_theme_hf_section( THRIVE_HEADER_SECTION );
83 - echo '<div id="wrapper">' . wp_kses_post( $header_content ) . '<div id="content"><div class="main-container">';
84 - }
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;
85 66
86 - /**
87 - * Render Thrive Footer Markup
88 - *
89 - * Outputs the footer section and closes the main content container.
90 - *
91 - * @return void
92 - */
93 - public function render_thrive_footer() {
94 - // Retrieve and sanitize the footer content allowing limited HTML
95 - $footer_content = thrive_template()->render_theme_hf_section( THRIVE_FOOTER_SECTION );
96 - echo '</div></div>' . wp_kses_post( $footer_content ) . '</div>';
97 - }
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 + }
98 74
75 + $eligible_template = $this->views->path( $_template, $_default_template );
99 76
100 - /**
101 - * Returns the archive template for the 'docs' custom post type.
102 - * If the post type is not 'docs' or it's an embed request, returns the original template.
103 - * If custom archive templates are found in the theme, returns the appropriate template.
104 - * Otherwise, returns the default archive template based on the selected layout.
105 - * @param string $template The original template.
106 - * @return string The archive template.
107 - */
108 - public function archive_template( $template ) {
109 - if( is_tax('doc_category') ) {
110 - // If 'archive-doc_category.php' exists in the theme, return it
111 - $theme_template = locate_template( 'archive-doc_category.php' );
112 - if ( $theme_template ) {
113 - return $theme_template;
114 - }
115 - }
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 + }
116 81
117 - if ( is_tax( 'glossaries' ) ) {
118 - // Use a custom taxonomy template for your custom taxonomy
82 + if ( file_exists( $eligible_template ) ) {
83 + $template = &$eligible_template;
84 + }
119 85
120 - $_default_template = 'templates/single/layout-1';
121 - $layout = 'templates/single/layout-7';
86 + return apply_filters( 'betterdocs_archives_template', $template, $layout, $_default_template, $this->views );
87 + }
122 88
123 - $eligible_template = $this->views->path( $layout, $_default_template );
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 + }
124 98
125 - if ( file_exists( $eligible_template ) ) {
126 - $template = &$eligible_template;
127 - }
99 + public function single_template( $template ) {
100 + if ( ! is_singular( 'docs' ) ) {
101 + return $template;
102 + }
128 103
129 - return apply_filters( 'betterdocs_archives_template', $template, $layout, $_default_template, $this->views );
130 - }
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 + }
131 108
132 - if ( get_post_type() !== 'docs' && ! is_tax('doc_category') && ! is_tax( 'doc_tag' ) && ! is_tax( 'knowledge_base' ) ) {
133 - return $template;
134 - }
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;
135 112
136 - if ( is_embed() ) {
137 - return $template;
138 - }
113 + $eligible_template = $this->views->path( $layout, $_default_template );
139 114
140 - if ( $this->locate_archives() ) {
141 - return $this->locate_archives();
142 - }
115 + if ( file_exists( $eligible_template ) ) {
116 + $template = &$eligible_template;
117 + }
143 118
144 - $_default_template = 'templates/archives/layout-1';
145 - $layout = $this->database->get_theme_mod( 'betterdocs_docs_layout_select', 'layout-7' );
146 - $_template = 'templates/archives/' . $layout;
147 -
148 - if ( is_tax( 'doc_category' ) ) {
149 - $category_layout = $this->database->get_theme_mod( 'betterdocs_archive_layout_select', 'layout-7' );
150 - if ( $category_layout == 'layout-7' || $category_layout == 'layout-8' ) {
151 - $_template = 'templates/archives/categories/' . $category_layout;
152 - } else {
153 - $_template = 'templates/taxonomy-doc_category';
154 - }
155 - $_default_template = $_template;
156 - } elseif ( is_tax( 'doc_tag' ) ) {
157 - $_template = 'templates/taxonomy-doc_tag';
158 - $_default_template = $_template;
159 - }
119 + return apply_filters( 'betterdocs_single_template', $template, $layout, $_default_template, $this->views );
120 + }
160 121
161 - $eligible_template = $this->views->path( $_template, $_default_template );
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 + }
162 135
163 - //Render The Header Footer When Thrive Builder Theme Is Activated
164 - if ( wp_get_theme() == 'Thrive Theme Builder' ) {
165 - $this->render_thrive_header_footer();
166 - }
167 -
168 - if ( file_exists( $eligible_template ) ) {
169 - $template = &$eligible_template;
170 - }
171 -
172 - return apply_filters( 'betterdocs_archives_template', $template, $layout, $_default_template, $this->views );
173 - }
174 -
175 - /**
176 - * Locates custom archive templates from the theme.
177 - * Checks for 'archive-docs.php', 'taxonomy-doc_category.php', 'taxonomy-doc_tag.php', and 'taxonomy-knowledge_base.php'.
178 - * Returns the template path if found, otherwise returns false.
179 - * @return string|false The template path or false if not found.
180 - */
181 - public function locate_archives() {
182 - $archive_docs = locate_template( 'archive-docs.php' );
183 - $doc_category = locate_template( 'taxonomy-doc_category.php' );
184 - $doc_tag = locate_template( 'taxonomy-doc_tag.php' );
185 - $knowledge_base = locate_template( 'taxonomy-knowledge_base.php' );
186 -
187 - if ( is_post_type_archive( 'docs' ) && $archive_docs ) {
188 - return $archive_docs;
189 - } elseif ( is_tax( 'doc_category' ) && $doc_category ) {
190 - return $doc_category;
191 - } elseif ( is_tax( 'doc_tag' ) && $doc_tag ) {
192 - return $doc_tag;
193 - } elseif ( is_tax( 'knowledge_base' ) && $archive_docs ) {
194 - return $knowledge_base;
195 - }
196 -
197 - return false;
198 - }
199 -
200 - /**
201 - * Render Thriver Header Footer When Thrive Theme Is Activated
202 - *
203 - * @return void
204 - */
205 - public function render_thrive_header_footer() {
206 - add_action( 'get_header', [ $this, 'render_thrive_header' ], 10 );
207 - add_action( 'get_footer', [ $this, 'render_thrive_footer' ], 10 );
208 - }
209 -
210 - /**
211 - * Returns the template for single 'docs' custom post type.
212 - * If the current post type is not 'docs', returns the original template.
213 - * If 'single-docs.php' exists in the theme, returns it.
214 - * Otherwise, returns the default single template based on the selected layout.
215 - * @param string $template The original template.
216 - * @return string The single template.
217 - */
218 - public function single_template( $template ) {
219 - if ( ! is_singular( 'docs' ) ) {
220 - return $template;
221 - }
222 -
223 - // If 'single-docs.php' exists in the theme, return it
224 - $theme_template = locate_template( 'single-docs.php' );
225 - if ( $theme_template ) {
226 - return $theme_template;
227 - }
228 -
229 - //Render The Header Footer When Thrive Builder Theme Is Activated
230 - if ( wp_get_theme() == 'Thrive Theme Builder' ) {
231 - $this->render_thrive_header_footer();
232 - }
233 -
234 - $_default_template = 'templates/single/layout-1';
235 - $layout = $this->database->get_theme_mod( 'betterdocs_single_layout_select', 'layout-8' );
236 - $layout = 'templates/single/' . $layout;
237 -
238 - $eligible_template = $this->views->path( $layout, $_default_template );
239 -
240 - if ( file_exists( $eligible_template ) ) {
241 - $template = &$eligible_template;
242 - }
243 -
244 - return apply_filters( 'betterdocs_single_template', $template, $layout, $_default_template, $this->views );
245 - }
246 -
247 - /**
248 - * Summary of is_fse_theme
249 - * @return bool
250 - *
251 - * @suppress PHP0417
252 - */
253 - private function is_fse_theme() {
254 - if ( function_exists( 'wp_is_block_theme' ) ) {
255 - return (bool) wp_is_block_theme();
256 - }
257 - if ( function_exists( 'gutenberg_is_fse_theme' ) ) {
258 - return (bool) gutenberg_is_fse_theme();
259 - }
260 -
261 - return false;
262 - }
136 + return false;
137 + }
263 138 }