PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 2.5.2
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v2.5.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 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.2, at includes/Shortcodes/CategoryGrid.php

169 lines 6.3 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 'kb_slug' => '',
54 'multiple_knowledge_base' => false,
55 'disable_customizer_style' => false,
56 'title_tag' => 'h2'
57 ];
58 }
59
60 public function generate_attributes() {
61 $attributes = [
62 'class' => [
63 'betterdocs-category-grid-inner-wrapper',
64 $this->layout_class
65 ]
66 ];
67
68 $masonry = (bool) $this->settings->get( 'masonry_layout', false );
69 if ( $this->has( 'masonry' ) ) {
70 $masonry = (bool) $this->attributes['masonry'];
71 }
72
73 if ( ! is_singular( 'docs' ) && ! is_tax( 'doc_category' ) && ! is_tax( 'doc_tag' ) ) {
74 if ( $this->attributes['sidebar_list'] == true ) {
75 $attributes['class'][] = 'layout-flex';
76 } elseif ( $masonry == true ) {
77 wp_enqueue_script( 'masonry' );
78 $attributes['class'][] = 'masonry';
79 } else {
80 $attributes['class'][] = 'layout-flex';
81 }
82 if ( $this->attributes['sidebar_list'] == true ) {
83 $_column_val = 1;
84 } elseif ( $this->isset( 'column' ) ) {
85 $_column_val = $this->attributes['column'];
86 } else {
87 $_column_val = $this->settings->get( 'column_number' );
88 }
89
90 $attributes['class'][] = 'docs-col-' . $_column_val;
91 $attributes['data-column_desktop'] = esc_html( $_column_val );
92 $attributes['style'] = "--column: $_column_val;";
93
94 if ( $this->isset( 'disable_customizer_style', false ) ) {
95 $attributes['class'][] = 'single-kb';
96 }
97 }
98
99
100 return $attributes;
101 }
102
103 public function header_layout_sequence( $sequence, $layout, $widget_type, $args ) {
104 return ['category_icon', 'category_title', 'category_counts', 'collapse_icon'];
105 }
106
107 public function render( $atts, $content = null ) {
108 if ( (bool) $this->attributes['sidebar_list'] ) {
109 add_filter( 'betterdocs_header_layout_sequence', [$this, 'header_layout_sequence'], 10, 4 );
110 }
111
112 $this->views( 'layouts/base' );
113
114 if ( (bool) $this->attributes['sidebar_list'] ) {
115 remove_filter( 'betterdocs_header_layout_sequence', [$this, 'header_layout_sequence'], 10 );
116 }
117 }
118
119 public function view_params() {
120 $exploremore_btn = $this->settings->get( 'exploremore_btn' );
121 $button_text = $this->settings->get( 'exploremore_btn_txt' );
122
123 $show_button = false;
124 if ( $this->attributes['posts_per_page'] == -1 ) {
125 $show_button = false;
126 } elseif ( $exploremore_btn && ! is_singular( 'docs' ) && Helper::get_tax() != 'doc_category' && ! is_tax( 'doc_tag' ) ) {
127 $show_button = true;
128 }
129
130 $terms_query = $this->query->terms_query( [
131 'taxonomy' => $this->attributes['taxonomy'],
132 'multiple_kb' => $this->attributes['multiple_knowledge_base'],
133 'kb_slug' => $this->attributes['kb_slug'],
134 'terms' => $this->attributes['terms'],
135 'order' => $this->attributes['terms_order'],
136 'orderby' => $this->attributes['terms_orderby'],
137 'nested_subcategory' => $this->attributes['nested_subcategory']
138 ] );
139
140 $inner_wrapper_attr = $this->generate_attributes();
141
142 $docs_query = [
143 'orderby' => $this->attributes['orderby'],
144 'order' => $this->attributes['order'],
145 'posts_per_page' => $this->attributes['posts_per_page']
146 ];
147
148 return [
149 'wrapper_attr' => ['class' => ['betterdocs-category-grid-wrapper']],
150 'inner_wrapper_attr' => $inner_wrapper_attr,
151 'layout' => 'default',
152 'widget_type' => 'category-grid',
153
154 'terms_query_args' => $terms_query,
155 'docs_query_args' => $docs_query,
156 'nested_docs_query_args' => $docs_query,
157
158 'show_header' => true,
159 'show_list' => true,
160 'show_title' => true,
161 'show_button' => $show_button,
162 'button_text' => $button_text,
163 'show_button_icon' => true,
164 'button_icon_position' => true,
165 'button_icon' => true
166 ];
167 }
168 }
169