PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 2.5.5
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v2.5.5
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 3.5.2 All 199 releases
betterdocs / includes / Shortcodes / CategoryGrid.php

CategoryGrid.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 2.5.5, at includes/Shortcodes/CategoryGrid.php

184 lines 6.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace WPDeveloper\BetterDocs\Shortcodes;
4
5 use WPDeveloper\BetterDocs\Utils\Helper;
6 use WPDeveloper\BetterDocs\Core\Shortcode;
7
8 class CategoryGrid extends Shortcode {
9 protected $layout_class = 'layout-1';
10
11 /**
12 * A list of deprecated attributes.
13 * @var array<string, string>
14 */
15 protected $deprecated_attributes = [
16 'category' => 'taxonomy',
17 'posts_per_grid' => 'posts_per_page',
18 'icon' => 'show_icon',
19 'post_counter' => 'show_count'
20 ];
21
22 public function get_name() {
23 return 'betterdocs_category_grid';
24 }
25
26 public function get_style_depends() {
27 return ['betterdocs-category-grid'];
28 }
29
30 public function get_script_depends() {
31 return ['betterdocs-category-grid'];
32 }
33
34 /**
35 * Summary of default_attributes
36 * @return array
37 */
38 public function default_attributes() {
39 return [
40 'sidebar_list' => false,
41 'taxonomy' => 'doc_category',
42 'show_icon' => true,
43 'masonry' => false,
44 'posts_per_page' => $this->settings->get( 'posts_number', 0 ),
45 'orderby' => $this->settings->get( 'alphabetically_order_post', 'betterdocs_order' ),
46 'order' => $this->settings->get( 'docs_order', 'ASC' ),
47 'show_count' => $this->settings->get( 'post_count' ),
48 'column' => $this->settings->get( 'column_number' ),
49 'nested_subcategory' => $this->settings->get( 'nested_subcategory' ),
50 'terms' => '',
51 'terms_orderby' => '',
52 'terms_order' => '',
53 'terms_include' => '',
54 'terms_exclude' => '',
55 'terms_offset' => '',
56 'kb_slug' => '',
57 'multiple_knowledge_base' => false,
58 'disable_customizer_style' => false,
59 'title_tag' => 'h2'
60 ];
61 }
62
63 public function generate_attributes() {
64 $attributes = [
65 'class' => [
66 'betterdocs-category-grid-inner-wrapper',
67 $this->layout_class
68 ]
69 ];
70
71 $masonry = (bool) $this->settings->get( 'masonry_layout', false );
72 if ( $this->has( 'masonry' ) ) {
73 $masonry = (bool) $this->attributes['masonry'];
74 }
75
76 if ( ! is_singular( 'docs' ) && ! is_tax( 'doc_category' ) && ! is_tax( 'doc_tag' ) ) {
77 if ( $this->attributes['sidebar_list'] == true ) {
78 $attributes['class'][] = 'layout-flex';
79 } elseif ( $masonry == true ) {
80 wp_enqueue_script( 'masonry' );
81 $attributes['class'][] = 'masonry';
82 } else {
83 $attributes['class'][] = 'layout-flex';
84 }
85 if ( $this->attributes['sidebar_list'] == true ) {
86 $_column_val = 1;
87 } elseif ( $this->isset( 'column' ) ) {
88 $_column_val = $this->attributes['column'];
89 } else {
90 $_column_val = $this->settings->get( 'column_number' );
91 }
92
93 $attributes['class'][] = 'docs-col-' . $_column_val;
94 $attributes['data-column_desktop'] = esc_html( $_column_val );
95 $attributes['style'] = "--column: $_column_val;";
96
97 if ( $this->isset( 'disable_customizer_style', false ) ) {
98 $attributes['class'][] = 'single-kb';
99 }
100 }
101
102
103 return $attributes;
104 }
105
106 public function header_layout_sequence( $sequence, $layout, $widget_type, $args ) {
107 return ['category_icon', 'category_title', 'category_counts', 'collapse_icon'];
108 }
109
110 public function render( $atts, $content = null ) {
111 if ( (bool) $this->attributes['sidebar_list'] ) {
112 add_filter( 'betterdocs_header_layout_sequence', [$this, 'header_layout_sequence'], 10, 4 );
113 }
114
115 $this->views( 'layouts/base' );
116
117 if ( (bool) $this->attributes['sidebar_list'] ) {
118 remove_filter( 'betterdocs_header_layout_sequence', [$this, 'header_layout_sequence'], 10 );
119 }
120 }
121
122 public function view_params() {
123 $exploremore_btn = $this->settings->get( 'exploremore_btn' );
124 $button_text = $this->settings->get( 'exploremore_btn_txt' );
125
126 $show_button = false;
127 if ( $this->attributes['posts_per_page'] == -1 ) {
128 $show_button = false;
129 } elseif ( $exploremore_btn && ! is_singular( 'docs' ) && Helper::get_tax() != 'doc_category' && ! is_tax( 'doc_tag' ) ) {
130 $show_button = true;
131 }
132
133 $terms_query = $this->query->terms_query( [
134 'taxonomy' => $this->attributes['taxonomy'],
135 'multiple_kb' => $this->attributes['multiple_knowledge_base'],
136 'kb_slug' => $this->attributes['kb_slug'],
137 'terms' => $this->attributes['terms'],
138 'order' => $this->attributes['terms_order'],
139 'orderby' => $this->attributes['terms_orderby'],
140 'nested_subcategory' => $this->attributes['nested_subcategory']
141 ] );
142
143 if ( $this->attributes['terms_include'] ) {
144 $terms_query['include'] = $this->attributes['terms_include'];
145 }
146
147 if ( $this->attributes['terms_exclude'] ) {
148 $terms_query['exclude'] = $this->attributes['terms_exclude'];
149 }
150
151 if ( $this->attributes['terms_offset'] ) {
152 $terms_query['offset'] = (int) $this->attributes['terms_offset'];
153 }
154
155 $inner_wrapper_attr = $this->generate_attributes();
156
157 $docs_query = [
158 'orderby' => $this->attributes['orderby'],
159 'order' => $this->attributes['order'],
160 'posts_per_page' => $this->attributes['posts_per_page']
161 ];
162
163 return [
164 'wrapper_attr' => ['class' => ['betterdocs-category-grid-wrapper']],
165 'inner_wrapper_attr' => $inner_wrapper_attr,
166 'layout' => 'default',
167 'widget_type' => 'category-grid',
168
169 'terms_query_args' => $terms_query,
170 'docs_query_args' => $docs_query,
171 'nested_docs_query_args' => $docs_query,
172
173 'show_header' => true,
174 'show_list' => true,
175 'show_title' => true,
176 'show_button' => $show_button,
177 'button_text' => $button_text,
178 'show_button_icon' => true,
179 'button_icon_position' => true,
180 'button_icon' => true
181 ];
182 }
183 }
184