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
← All changes | views/layouts/base.php +159 -116 3.3.4 → 4.9.4 View file →
@@ -1,145 +1,188 @@
1 1 <?php
2 - //var_dump($terms_query_args);
3 - $terms = get_terms( apply_filters( 'betterdocs_base_terms_args', $terms_query_args ) );
4 - /**
5 - * Base Layout Before Wrapper
6 - */
7 - do_action_ref_array( 'betterdocs_base_layout_wrapper_before', [ & $terms] );
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 ] );
8 15 ?>
9 16
10 17 <div
11 - <?php echo $wrapper_attr; ?>>
18 + <?php echo $wrapper_attr; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>>
12 19 <?php
13 - /**
14 - * Base Layout Before Inner Wrapper
15 - */
16 - do_action_ref_array( 'betterdocs_base_layout_inner_wrapper_before', [ & $terms] );
20 + /**
21 + * Base Layout Before Inner Wrapper
22 + */
23 + do_action_ref_array( 'betterdocs_base_layout_inner_wrapper_before', [ & $terms ] );
17 24 ?>
18 25 <div
19 - <?php echo $inner_wrapper_attr; ?>>
20 - <?php
21 - $_defined_vars = get_defined_vars();
22 - $_params = isset( $_defined_vars['params'] ) ? $_defined_vars['params'] : [];
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'] : [];
23 30
24 - $nested_subcategory = isset( $nested_subcategory ) ? $nested_subcategory : false;
31 + $nested_subcategory = isset( $nested_subcategory ) ? $nested_subcategory : false;
25 32
26 - $_current_queried_object_id = null;
27 - $_current_queried_object = get_queried_object();
33 + $_current_queried_object_id = null;
34 + $_current_queried_object = get_queried_object();
28 35
29 - if ( $_current_queried_object instanceof \WP_Post ) {
30 - $_current_terms = get_the_terms( $_current_queried_object->ID, 'doc_category' );
31 - $_current_queried_object_id = isset( $_current_terms[0]->term_id ) ? $_current_terms[0]->term_id : null;
32 - } elseif ( $_current_queried_object instanceof \WP_Term ) {
33 - $_current_queried_object_id = $_current_queried_object->term_id;
34 - }
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 + }
35 42
36 - $ancestors = [];
43 + $ancestors = [];
37 44
38 - if ( is_single() && ! empty( $_current_queried_object_id ) ) {
39 - $_category_ids = wp_get_post_terms( get_the_ID(), 'doc_category', ["fields" => "ids"] );
40 - $ancestors = get_ancestors( $_category_ids[0], 'doc_category' );
41 - }
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 + }
42 51
43 - if ( ! is_wp_error( $terms ) ) {
44 - do_action_ref_array( 'betterdocs_layout_base_loop_start', [ & $terms, &$_defined_vars] );
52 + if ( ! is_wp_error( $terms ) ) {
53 + do_action_ref_array( 'betterdocs_layout_base_loop_start', [ & $terms, &$_defined_vars ] );
45 54
46 - $_docs_query_args = [
47 - 'posts_per_page' => isset( $_params['posts_per_page'] ) ? $_params['posts_per_page'] : 0,
48 - 'multiple_kb' => isset( $_params['multiple_knowledge_base'] ) ? $_params['multiple_knowledge_base'] : false,
49 - 'kb_slug' => isset( $_params['kb_slug'] ) ? $_params['kb_slug'] : ''
50 - ];
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 + ];
51 60
52 - $docs_query_args = ! isset( $docs_query_args ) ? $_docs_query_args : wp_parse_args( $docs_query_args, $_docs_query_args );
61 + $docs_query_args = ! isset( $docs_query_args ) ? $_docs_query_args : wp_parse_args( $docs_query_args, $_docs_query_args );
53 62
54 - foreach ( $terms as $term ) {
55 - $_counts = betterdocs()->query->get_docs_count( $term, $nested_subcategory, [
56 - 'multiple_knowledge_base' => isset( $_params['multiple_knowledge_base'] ) ? $_params['multiple_knowledge_base'] : false,
57 - 'kb_slug' => isset( $_params['kb_slug'] ) ? $_params['kb_slug'] : ''
58 - ] );
63 + $terms_count = count( $terms );
64 + $terms_number = 1;
59 65
60 - if ( $_counts <= 0 ) {
61 - continue;
62 - }
66 + $_term_ids = wp_list_pluck( $terms, 'term_id' );
67 + if ( ! empty( $_term_ids ) ) {
68 + update_termmeta_cache( $_term_ids );
69 + }
63 70
64 - if ( $widget_type == 'category-box' ) {
65 - $_counts = [
66 - 'counts' => $_counts,
67 - 'prefix' => ! empty( $count_prefix ) ? $count_prefix : '',
68 - 'suffix' => ! empty( $count_suffix ) ? $count_suffix : '',
69 - 'suffix_singular' => ! empty( $count_suffix_singular ) ? $count_suffix_singular : ''
70 - ];
71 - }
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 + );
72 80
73 - $permalink = apply_filters(
74 - 'betterdocs_term_permalink',
75 - get_term_link( $term->term_id, $term->taxonomy ), $term, 'doc_category', $_params
76 - );
81 + if ( $_counts <= 0 ) {
82 + continue;
83 + }
77 84
78 - $docs_query_args['term_id'] = $term->term_id;
79 - $docs_query_args['term_slug'] = $term->slug;
80 - $docs_query_args['nested_subcategory'] = $nested_subcategory;
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 + }
81 93
82 - $_params = wp_parse_args( [
83 - 'permalink' => $permalink,
84 - 'wrapper_class' => [$layout],
85 - 'term' => $term,
86 - 'counts' => $_counts,
87 - 'queried_object' => $_current_queried_object,
88 - 'current_queried_object_id' => $_current_queried_object_id,
89 - 'ancestors' => $ancestors,
90 - 'query_args' => betterdocs()->query->docs_query_args( $docs_query_args )
91 - ], $_params );
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 + }
92 102
93 - $template_params = apply_filters( 'betterdocs_template_params', $_params, $layout, $term, $widget_type );
94 - $layout_filename = apply_filters( 'betterdocs_layout_filename', $layout, $layout, $widget_type );
95 103
96 - betterdocs()->views->get( 'layouts/' . $widget_type . '/' . $layout_filename, $template_params );
97 - }
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 + );
98 111
99 - do_action_ref_array( 'betterdocs_layout_base_loop_end', [ & $terms, &$_defined_vars] );
100 - } else {
101 - betterdocs()->views->get( 'layout-parts/no-content' );
102 - }
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;
103 115
104 - wp_reset_postdata();
105 - ?>
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 + ?>
106 149 </div>
107 - <?php
108 - /**
109 - * Base Layout After Inner Wrapper
110 - */
111 - do_action_ref_array( 'betterdocs_base_layout_inner_wrapper_after', [ & $terms] );
112 - ?>
113 - <div class="clearfix"></div>
114 - <?php if ( isset( $is_edit_mode ) && $is_edit_mode && $widget_type == 'category-grid' ): ?>
115 - <script>
116 - /**
117 - * TODO: Not working in Elementor Editor on first Load.
118 - */
119 - jQuery(document).ready(function($) {
120 - $('.betterdocs-category-grid').each(function() {
121 - let $grid = $(this),
122 - $layout_mode = $grid.data('layout-mode'),
123 - $column = $grid.data('column'),
124 - $column_space = $grid.data('column_space');
125 - if ($layout_mode === 'masonry') {
126 - let masonryItem = $(".betterdocs-single-category-wrapper", $grid);
127 - let total_margin = ($column - 1) * $column_space;
128 - masonryItem.css("width", "calc((100% - " + total_margin + "px) / " + parseInt($column) + ")");
129 - $grid.masonry({
130 - itemSelector: ".betterdocs-single-category-wrapper",
131 - percentPosition: true,
132 - gutter: $column_space
133 - });
134 - }
135 - });
136 - });
137 - </script>
138 - <?php endif;?>
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; ?>
139 182 </div>
140 183 <?php
141 - /**
142 - * Base Layout After Wrapper
143 - */
144 - do_action_ref_array( 'betterdocs_base_layout_wrapper_after', [ & $terms] );
184 + /**
185 + * Base Layout After Wrapper
186 + */
187 + do_action_ref_array( 'betterdocs_base_layout_wrapper_after', [ & $terms ] );
145 188 ?>