PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.2
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.2
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 3.5.0 3.5.1 All 200 releases
betterdocs / includes / Shortcodes / CategoryBoxThree.php

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

118 lines 3.2 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\Shortcodes\CategoryBox;
6
7 class CategoryBoxThree extends CategoryBox {
8 protected $layout_class = 'layout-4';
9
10 /**
11 * Summary of get_id
12 * @return string
13 */
14 public function get_name() {
15 return 'betterdocs_category_box_3';
16 }
17
18 /**
19 * Summary of default_attributes
20 * @return array
21 */
22 public function default_attributes() {
23 return [
24 'taxonomy' => 'doc_category',
25 'column' => $this->settings->get( 'column_number', 4 ),
26 'nested_subcategory' => $this->settings->get( 'nested_subcategory', false ),
27 'terms' => '',
28 'terms_order' => $this->settings->get( 'terms_order', 'ASC' ),
29 'terms_orderby' => $this->settings->get( 'terms_orderby', 'betterdocs_order' ),
30 'kb_slug' => '',
31 'multiple_knowledge_base' => false,
32 'disable_customizer_style' => false,
33 'title_tag' => 'h2',
34 'show_description' => false,
35 'show_icon' => true,
36 'category_icon' => 'folder',
37 'last_update' => '',
38 ];
39 }
40
41 public function header_sequence( $_layout_sequence, $layout, $widget_type, $_defined_vars ) {
42 $_new_layout_sequence = [
43 'category_icon',
44 [
45 'class' => 'betterdocs-category-title-counts',
46 'sequence' => [ 'category_title', 'category_description', 'sub_category_counts', 'last_update' ]
47 ]
48 ];
49
50 return $_new_layout_sequence;
51 }
52
53 /**
54 * Summary of render
55 *
56 * @param mixed $atts
57 * @param mixed $content
58 * @return mixed
59 */
60 public function render( $atts, $content = null ) {
61 parent::render( $atts, $content );
62 }
63
64 public function view_params() {
65 $parent_params = parent::view_params();
66 $query_arg = $parent_params['terms_query_args'];
67
68 // get_terms() returns a WP_Error for an invalid taxonomy, and the taxonomy
69 // is a shortcode attribute the author controls — [betterdocs_category_box_3
70 // taxonomy=nope] reached count(WP_Error), which is a TypeError on PHP 8 and
71 // takes the whole page down with a 500 for anonymous visitors.
72 $_terms = get_terms( $query_arg );
73 $term_count = is_wp_error( $_terms ) ? 0 : count( $_terms );
74 $styles = '';
75
76 if ( $this->isset( 'column' ) ) {
77 $_c = intval( $this->attributes['column'] );
78 } else {
79 $_c = 4;
80 }
81
82 if ( is_tax( 'doc_category' ) && ! $this->isset( 'column' ) ) {
83 $_c = 3;
84 }
85
86 $styles .= "--column: $_c;";
87 $styles .= "--count: $term_count;";
88 $reminder = $term_count % $_c;
89 $styles .= "--reminder: $reminder;";
90
91 $classes = [ 'betterdocs-categories-folder', $this->layout_class ];
92
93 if ( $this->isset( 'border_bottom', true ) ) {
94 $classes[] = 'border-bottom';
95 }
96
97 if ( $this->isset( 'disable_customizer_style', false ) ) {
98 $classes[] = 'single-kb';
99 }
100
101 $inner_wrapper_attr = [
102 'class' => $classes,
103 'style' => $styles,
104 ];
105
106 $_view_params = [
107 'layout' => 'layout-4',
108 'reminder' => $reminder,
109 'column' => $_c,
110 'total_terms' => $term_count,
111 'inner_wrapper_attr' => $inner_wrapper_attr,
112 'show_icon' => $this->attributes['show_icon']
113 ];
114
115 return $this->merge( $parent_params, $_view_params );
116 }
117 }
118