PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.4
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.4
4.9.4 4.9.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 All 202 releases
betterdocs / views / layouts / base.php

base.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 4.9.4, at views/layouts/base.php

189 lines 6.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- view template receives variables via extract(); prefixing is impractical.
3
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7 if ( $terms_query_args == false ) {
8 return;
9 }
10 $terms = get_terms( apply_filters( 'betterdocs_base_terms_args', $terms_query_args ) );
11 /**
12 * Base Layout Before Wrapper
13 */
14 do_action_ref_array( 'betterdocs_base_layout_wrapper_before', [ & $terms ] );
15 ?>
16
17 <div
18 <?php echo $wrapper_attr; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
19 <?php
20 /**
21 * Base Layout Before Inner Wrapper
22 */
23 do_action_ref_array( 'betterdocs_base_layout_inner_wrapper_before', [ & $terms ] );
24 ?>
25 <div
26 <?php echo $inner_wrapper_attr; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
27 <?php
28 $_defined_vars = get_defined_vars();
29 $_params = isset( $_defined_vars['params'] ) ? $_defined_vars['params'] : [];
30
31 $nested_subcategory = isset( $nested_subcategory ) ? $nested_subcategory : false;
32
33 $_current_queried_object_id = null;
34 $_current_queried_object = get_queried_object();
35
36 if ( $_current_queried_object instanceof \WP_Post ) {
37 $_current_terms = get_the_terms( $_current_queried_object->ID, 'doc_category' );
38 $_current_queried_object_id = isset( $_current_terms[0]->term_id ) ? $_current_terms[0]->term_id : null;
39 } elseif ( $_current_queried_object instanceof \WP_Term ) {
40 $_current_queried_object_id = $_current_queried_object->term_id;
41 }
42
43 $ancestors = [];
44
45 if ( is_single() && ! empty( $_current_queried_object_id ) ) {
46 $_category_ids = wp_get_post_terms( get_the_ID(), 'doc_category', [ 'fields' => 'ids' ] );
47 if ( ! is_wp_error( $_category_ids ) && ! empty( $_category_ids ) ) {
48 $ancestors = get_ancestors( $_category_ids[0], 'doc_category' );
49 }
50 }
51
52 if ( ! is_wp_error( $terms ) ) {
53 do_action_ref_array( 'betterdocs_layout_base_loop_start', [ & $terms, &$_defined_vars ] );
54
55 $_docs_query_args = [
56 'posts_per_page' => isset( $_params['posts_per_page'] ) ? $_params['posts_per_page'] : 0,
57 'multiple_kb' => isset( $_params['multiple_knowledge_base'] ) ? $_params['multiple_knowledge_base'] : false,
58 'kb_slug' => isset( $_params['kb_slug'] ) ? $_params['kb_slug'] : ''
59 ];
60
61 $docs_query_args = ! isset( $docs_query_args ) ? $_docs_query_args : wp_parse_args( $docs_query_args, $_docs_query_args );
62
63 $terms_count = count( $terms );
64 $terms_number = 1;
65
66 $_term_ids = wp_list_pluck( $terms, 'term_id' );
67 if ( ! empty( $_term_ids ) ) {
68 update_termmeta_cache( $_term_ids );
69 }
70
71 foreach ( $terms as $term ) {
72 $_counts = betterdocs()->query->get_docs_count(
73 $term,
74 $nested_subcategory,
75 [
76 'multiple_knowledge_base' => isset( $_params['multiple_knowledge_base'] ) ? $_params['multiple_knowledge_base'] : false,
77 'kb_slug' => isset( $_params['kb_slug'] ) ? $_params['kb_slug'] : ''
78 ]
79 );
80
81 if ( $_counts <= 0 ) {
82 continue;
83 }
84
85 if ( $widget_type == 'category-box' || ( $widget_type == 'category-grid' && $layout == 'layout-2' ) ) {
86 $_counts = [
87 'counts' => $_counts,
88 'prefix' => ! empty( $count_prefix ) ? $count_prefix : '',
89 'suffix' => ! empty( $count_suffix ) ? $count_suffix : '',
90 'suffix_singular' => ! empty( $count_suffix_singular ) ? $count_suffix_singular : ''
91 ];
92 }
93
94 // Count Sub Terms
95 $sub_terms_count = 0;
96 if ( isset( $_params['taxonomy'] ) && $_params['taxonomy'] == 'doc_category' ) {
97 $sub_terms_count = count( betterdocs()->query->get_all_child_term_ids( $_params['taxonomy'], $term->term_id ) );
98 } elseif ( isset( $_params['taxonomy'] ) && $_params['taxonomy'] == 'knowledge_base' ) {
99 $count_doc_categories = betterdocs()->query->count_doc_categories_for_knowledge_base( $term->slug );
100 $sub_terms_count = $count_doc_categories;
101 }
102
103
104 $permalink = apply_filters(
105 'betterdocs_term_permalink',
106 get_term_link( $term->term_id, $term->taxonomy ),
107 $term,
108 'doc_category',
109 $_params
110 );
111
112 $docs_query_args['term_id'] = $term->term_id;
113 $docs_query_args['term_slug'] = $term->slug;
114 $docs_query_args['nested_subcategory'] = $nested_subcategory;
115
116 $_params = wp_parse_args(
117 [
118 'permalink' => $permalink,
119 'wrapper_class' => [ $layout ],
120 'term' => $term,
121 'counts' => $_counts,
122 'terms_count' => $terms_count,
123 'terms_number' => $terms_number,
124 'sub_terms_count' => $sub_terms_count,
125 'queried_object' => $_current_queried_object,
126 'current_queried_object_id' => $_current_queried_object_id,
127 'ancestors' => $ancestors,
128 'query_args' => betterdocs()->query->docs_query_args( $docs_query_args )
129 ],
130 $_params
131 );
132
133 $template_params = apply_filters( 'betterdocs_template_params', $_params, $layout, $term, $widget_type );
134 $layout_filename = apply_filters( 'betterdocs_layout_filename', $layout, $layout, $widget_type );
135 $layout_filename = sanitize_file_name( $layout_filename );
136
137 betterdocs()->views->get( 'layouts/' . $widget_type . '/' . $layout_filename, $template_params );
138 ++$terms_number;
139 --$terms_count;
140 }
141
142 do_action_ref_array( 'betterdocs_layout_base_loop_end', [ & $terms, &$_defined_vars ] );
143 } else {
144 betterdocs()->views->get( 'layout-parts/no-content' );
145 }
146
147 wp_reset_postdata();
148 ?>
149 </div>
150 <?php
151 /**
152 * Base Layout After Inner Wrapper
153 */
154 do_action_ref_array( 'betterdocs_base_layout_inner_wrapper_after', [ & $terms ] );
155 ?>
156 <div class="clearfix"></div>
157 <?php if ( isset( $is_edit_mode ) && $is_edit_mode && $widget_type == 'category-grid' ) : ?>
158 <script>
159 /**
160 * TODO: Not working in Elementor Editor on first Load.
161 */
162 jQuery(document).ready(function($) {
163 $('.betterdocs-category-grid').each(function() {
164 let $grid = $(this),
165 $layout_mode = $grid.data('layout-mode'),
166 $column = $grid.data('column'),
167 $column_space = $grid.data('column_space');
168 if ($layout_mode === 'masonry') {
169 let masonryItem = $(".betterdocs-single-category-wrapper", $grid);
170 let total_margin = ($column - 1) * $column_space;
171 masonryItem.css("width", "calc((100% - " + total_margin + "px) / " + parseInt($column) + ")");
172 $grid.masonry({
173 itemSelector: ".betterdocs-single-category-wrapper",
174 percentPosition: true,
175 gutter: $column_space
176 });
177 }
178 });
179 });
180 </script>
181 <?php endif; ?>
182 </div>
183 <?php
184 /**
185 * Base Layout After Wrapper
186 */
187 do_action_ref_array( 'betterdocs_base_layout_wrapper_after', [ & $terms ] );
188 ?>
189