PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.5.6
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.5.6
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 / CategoryBox.php

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

127 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 // phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- ordering by user-assigned meta is required UX.
3 namespace WPDeveloper\BetterDocs\Shortcodes;
4
5 if ( ! defined( 'ABSPATH' ) ) {
6 exit;
7 }
8
9
10 use WPDeveloper\BetterDocs\Core\Shortcode;
11
12 class CategoryBox extends Shortcode {
13 protected $layout_class = 'layout-1';
14 protected $deprecated_attributes = [
15 'category' => 'taxonomy',
16 'icon' => 'show_icon'
17 ];
18
19 public function get_name() {
20 return 'betterdocs_category_box';
21 }
22
23 public function get_style_depends() {
24 return [ 'betterdocs-category-box' ];
25 }
26
27 public function default_attributes() {
28 return [
29 'taxonomy' => 'doc_category',
30 'parent' => 0,
31 'meta_key' => '',
32 'layout' => '',
33 'column' => $this->settings->get( 'column_number', 3 ),
34 'orderby' => $this->settings->get( 'alphabetically_order_post', 'title' ),
35 'nested_subcategory' => (bool) $this->settings->get( 'nested_subcategory', false ),
36 'terms' => '',
37 'terms_order' => $this->settings->get( 'terms_order', 'ASC' ),
38 'terms_orderby' => $this->settings->get( 'terms_orderby', 'betterdocs_order' ),
39 'show_icon' => true,
40 'kb_slug' => '',
41 'title_tag' => 'h2',
42 'multiple_knowledge_base' => false,
43 'disable_customizer_style' => false,
44 'border_bottom' => false,
45 'show_description' => (bool) $this->customizer->get( 'betterdocs_doc_page_cat_desc', false )
46 ];
47 }
48
49 public function header_sequence( $_layout_sequence, $layout, $widget_type, $_defined_vars ) {
50 return [ 'category_icon', 'category_title', 'category_description', 'category_counts' ];
51 }
52
53 public function render( $atts, $content = null ) {
54 add_filter( 'betterdocs_header_layout_sequence', [ $this, 'header_sequence' ], 10, 4 );
55
56 $this->views( 'layouts/base' );
57
58 remove_filter( 'betterdocs_header_layout_sequence', [ $this, 'header_sequence' ], 10 );
59 }
60
61 public function view_params() {
62 $classes = [ 'betterdocs-category-box-inner-wrapper', $this->layout_class, ( $this->layout_class != 'layout-4' ? 'layout-flex ash-bg' : '' ) ];
63 $styles = '';
64
65 if ( $this->isset( 'column' ) ) {
66 $_c = intval( $this->attributes['column'] );
67 $classes[] = 'docs-col-' . $_c;
68 $styles .= "--column: $_c;";
69 }
70
71 if ( $this->isset( 'border_bottom', true ) ) {
72 $classes[] = 'border-bottom';
73 }
74
75 if ( $this->isset( 'disable_customizer_style', false ) ) {
76 $classes[] = 'single-kb';
77 }
78
79 $_query_args = [
80 'terms' => $this->attributes['terms'],
81 'order' => $this->attributes['terms_order'],
82 'orderby' => $this->attributes['terms_orderby'],
83 'multiple_kb' => $this->attributes['multiple_knowledge_base'],
84 'kb_slug' => $this->attributes['kb_slug'],
85 'nested_subcategory' => (bool) $this->attributes['nested_subcategory']
86 ];
87
88 if ( $this->isset( 'taxonomy' ) ) {
89 $_query_args['taxonomy'] = $this->attributes['taxonomy'];
90 }
91
92 // if ( $this->isset( 'parent', 0 ) ) {
93 // $_query_args['parent'] = $this->attributes['parent'];
94 // }
95
96 if ( $this->isset( 'meta_key' ) ) {
97 $_query_args['meta_key'] = $this->attributes['meta_key'];
98 }
99
100 $terms_query = $this->query->terms_query( $_query_args );
101
102 $show_count = (bool) $this->settings->get( 'post_count', false );
103 $singular_text = $this->settings->get( 'count_text_singular' );
104 $plural_text = $this->settings->get( 'count_text' );
105
106 $inner_wrapper_attr = [
107 'class' => $classes,
108 'style' => $styles,
109 ];
110
111 return [
112 'wrapper_attr' => [ 'class' => [ 'betterdocs-category-box-wrapper' ] ],
113 'inner_wrapper_attr' => $inner_wrapper_attr,
114 'layout' => 'default',
115 'widget_type' => 'category-box',
116
117 'terms_query_args' => $terms_query,
118
119 'show_title' => true,
120 'show_count' => $show_count,
121 'count_suffix_singular' => $singular_text,
122 'count_suffix' => $plural_text,
123 'title_tag' => $this->attributes['title_tag']
124 ];
125 }
126 }
127