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

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

107 lines 3.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\Core\Shortcode;
6
7 class FaqList extends Shortcode {
8 protected $layout = 'modern';
9 protected $icon_hook = 'betterdocs_faq_post_after';
10
11 public $icon_position = 'after';
12
13 public function get_name() {
14 return 'betterdocs_faq_list_modern';
15 }
16
17 public function get_style_depends() {
18 return [ 'betterdocs-faq' ];
19 }
20
21 public function get_script_depends() {
22 return [ 'betterdocs-faq' ];
23 }
24
25 protected $map_view_vars = [
26 'class' => 'faq_heading_class'
27 ];
28
29 /**
30 * Summary of default_attributes
31 * @return array
32 */
33 public function default_attributes() {
34 return [
35 'groups' => '',
36 'class' => '',
37 'group_exclude' => '',
38 'faq_heading' => __( 'Frequently Asked Questions', 'betterdocs' ),
39 'faq_section_title_tag' => 'h2',
40 'faq_group_title_tag' => 'h3',
41 'faq_schema' => false,
42 'faq_layout' => 'layout-1',
43 'faq_section_title_color' => null,
44 'include_faq_group' => '',
45 'exclude_faq_group' => '',
46 'faq_group_title_color' => null,
47 'faq_group_title_hover_color' => null,
48 'faq_list_color' => null,
49 'faq_content_color' => null,
50 'faq_icon_color' => null,
51 'faq_group_title_typography' => null,
52 'faq_per_page' => 9,
53 'show_button_icon' => true,
54 'button_icon_position' => 'after',
55 'button_color' => '#528ffe',
56 'is_gutenberg' => false
57 ];
58 }
59
60 public function icons( $faq_toggle ) {
61 $faq_markup = '<svg class="betterdocs-faq-iconminus" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"' .($faq_toggle ? " style='display:inline;'" : ""). 'stroke-width="2"><g fill="none" stroke="' . esc_attr( $this->attributes['button_color'] ) . '" stroke-linecap="round" stroke-miterlimit="10" stroke-linejoin="round"><path d="M17 12H7"></path><circle cx="12" cy="12" r="11"></circle></g></svg>';
62 $faq_markup .= '<svg class="betterdocs-faq-iconplus" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"'.($faq_toggle ? " style='display:none;'" : "").'><g stroke-width="2" fill="none" stroke="' . esc_attr( $this->attributes['button_color'] ) . '" stroke-linecap="square" stroke-miterlimit="10"><path d="M12 7v10M17 12H7"></path><circle cx="12" cy="12" r="11"></circle></g></svg>';
63
64 echo $faq_markup; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
65 }
66
67 public function render( $atts, $content = null ) {
68
69 $this->icon_position = isset( $this->atts['button_icon_position'] ) ? $this->atts['button_icon_position'] : '';
70
71 if ( $this->attributes['is_gutenberg'] && $this->attributes['button_icon_position'] == 'before' && $this->attributes['show_button_icon'] ) {
72 add_action( 'betterdocs_faq_post_before', [ $this, 'icons' ] );
73 } elseif ( $this->attributes['is_gutenberg'] && $this->attributes['button_icon_position'] == 'after' && $this->attributes['show_button_icon'] ) {
74 add_action( 'betterdocs_faq_post_after', [ $this, 'icons' ] );
75 } else {
76 add_action( $this->icon_hook, [ $this, 'icons' ] );
77 }
78
79 $this->views( 'shortcodes/faq' );
80
81 remove_action( $this->icon_hook, [ $this, 'icons' ] );
82 }
83
84 public function view_params() {
85 $terms_query = $this->query->faq_terms_query_args( $this->attributes['groups'], $this->attributes['group_exclude'] );
86
87 $wrapper_attr = [
88 'class' => [
89 'betterdocs-faq-wrapper',
90 'layout-' . $this->layout,
91 'icon-' . $this->attributes['button_icon_position'],
92 $this->attributes['class']
93 ]
94 ];
95
96 return wp_parse_args(
97 [
98 'wrapper_attr' => $wrapper_attr,
99 'widget' => $this,
100 'layout' => 'list',
101 'terms_query_args' => $terms_query,
102 'faq_schema' => $this->attributes['faq_schema']
103 ]
104 );
105 }
106 }
107