PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 2.0.14
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v2.0.14
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 / elementor / class-betterdocs-elementor.php

class-betterdocs-elementor.php in BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot 2.0.14, at includes/elementor/class-betterdocs-elementor.php

942 lines 31.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 use Elementor\Controls_Manager;
3 use ElementorPro\Plugin;
4 use ElementorPro\Modules\ThemeBuilder as ThemeBuilder;
5
6 /**
7 * Working with elementor plugin
8 *
9 *
10 * @since 1.3.0
11 * @package BetterDocs
12 * @subpackage BetterDocs/elementor
13 * @author WPDeveloper <support@wpdeveloper.com>
14 */
15 class BetterDocs_Elementor
16 {
17 public static $pro_active;
18
19 /**
20 * Short Description. (use period)
21 *
22 * Long Description.
23 *
24 * @since 1.3.0
25 */
26 public static function init()
27 {
28 self::$pro_active = is_plugin_active('betterdocs-pro/betterdocs-pro.php');
29 add_action('elementor/editor/before_enqueue_scripts', [__CLASS__, 'editor_enqueue_scripts']);
30 if (is_plugin_active('betterdocs/betterdocs.php')) {
31 add_action('elementor/documents/register', [__CLASS__, 'register_singel_documents_page']);
32 add_action('elementor/documents/register', [__CLASS__, 'register_doc_category_archive']);
33 add_filter('elementor/theme/need_override_location', [__CLASS__, 'theme_template_include'], 10, 2);
34 add_action('betterdocs/elementor/widgets/query', [__CLASS__, 'betterdocs_query'], 10, 2);
35 add_action('elementor/widgets/register', [__CLASS__, 'register_basic_widgets']);
36 add_action('elementor/elements/categories_registered', [__CLASS__, 'register_widget_categories']);
37 add_filter('elementor/editor/localize_settings', [__CLASS__, 'promote_pro_elements']);
38 add_action('wp_enqueue_scripts', [__CLASS__, 'editor_load_asset']);
39 add_action('elementor/init', [__CLASS__, 'load_basic_widgets']);
40 if (is_plugin_active('elementor-pro/elementor-pro.php')) {
41 add_action('elementor/widgets/widgets_registered', [__CLASS__, 'register_theme_builder_widgets']);
42 add_action('elementor/init', [__CLASS__, 'load_theme_builder_widgets']);
43 add_action('elementor/theme/register_conditions', [__CLASS__, 'register_conditions']);
44 }
45 }
46
47 add_action('init', [__CLASS__, '_betterdocs_init'], -999);
48 }
49
50 /**
51 *
52 * Mange all widget for single docs
53 *
54 * @return string[]
55 * @since 1.3.0
56 */
57 public static function get_basic_widget_list()
58 {
59 $widget_arr = [
60 'betterdocs-elementor-search-form' => 'BetterDocs_Elementor_Search_Form',
61 'betterdocs-elementor-category-grid' => 'BetterDocs_Elementor_Category_Grid',
62 'betterdocs-elementor-category-box' => 'BetterDocs_Elementor_Category_Box'
63 ];
64
65 return $widget_arr;
66 }
67
68 /**
69 *
70 * Mange all widget for single docs
71 *
72 * @return string[]
73 * @since 1.3.0
74 */
75 public static function get_theme_builder_widget_list()
76 {
77 $widget_arr = [
78 'betterdocs-elementor-breadcrumbs' => 'BetterDocs_Elementor_Breadcrumbs',
79 'betterdocs-elementor-title' => 'BetterDocs_Elementor_Title',
80 'betterdocs-elementor-content' => 'BetterDocs_Elementor_Content',
81 'betterdocs-elementor-sidebar' => 'BetterDocs_Elementor_Sidebar',
82 'betterdocs-elementor-navigation' => 'BetterDocs_Elementor_Navigation',
83 'betterdocs-elementor-doc-share' => 'BetterDocs_Elementor_Doc_Share',
84 'betterdocs-elementor-feedback' => 'BetterDocs_Elementor_Feedback',
85 'betterdocs-elementor-doc-date' => 'BetterDocs_Elementor_Doc_Date',
86 'betterdocs-elementor-toc' => 'BetterDocs_Elementor_Toc',
87 'betterdocs-elementor-category-archive-list' => 'BetterDocs_Category_Archive_List'
88 ];
89
90 return $widget_arr;
91 }
92
93 /**
94 *
95 * Load asset for elementor icon
96 *
97 * @since 1.3.0
98 */
99 public static function editor_enqueue_scripts()
100 {
101 wp_enqueue_style(
102 'betterdocs-el-icon',
103 BETTERDOCS_ADMIN_URL . 'assets/css/betterdocs-el-icon.css',
104 false,
105 BETTERDOCS_VERSION
106 );
107 }
108
109 public static function editor_load_asset()
110 {
111 if (BetterDocs_Helper::is_templates() == true) {
112 wp_enqueue_style(
113 'betterdocs-el-edit',
114 BETTERDOCS_ADMIN_URL . 'assets/css/betterdocs-el-edit.css',
115 false,
116 BETTERDOCS_VERSION
117 );
118
119 if (!self::$pro_active) {
120 wp_enqueue_script(
121 'betterdocs-el-editor',
122 BETTERDOCS_ADMIN_URL . 'assets/js/betterdocs-el-editor.js',
123 ['jquery'],
124 BETTERDOCS_VERSION,
125 true
126 );
127 }
128 }
129 }
130
131 public static function load_basic_widgets()
132 {
133 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/template-query.php';
134
135 // load widget file
136 foreach (self::get_basic_widget_list() as $key => $value) {
137 require_once BETTERDOCS_DIR_PATH . "includes/elementor/widgets/basic/$key.php";
138 }
139 }
140
141 public static function load_theme_builder_widgets()
142 {
143 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/template-query.php';
144 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/betterdocs-single-docs.php';
145 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/betterdocs-doc-archive.php';
146 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/betterdocs-archive-condition.php';
147 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/docs-page.php';
148 self::_register_tag();
149
150 //load widget file
151 foreach (self::get_theme_builder_widget_list() as $key => $value) {
152 require_once BETTERDOCS_DIR_PATH . "includes/elementor/widgets/$key.php";
153 }
154 }
155
156 public static function register_singel_documents_page($documents_manager)
157 {
158 if (class_exists('BetterDocs_Single_Docs')) {
159 $documents_manager->register_document_type('docs', BetterDocs_Single_Docs::get_class_full_name());
160 }
161 }
162
163 public static function register_doc_category_archive($documents_manager)
164 {
165 if (class_exists('Betterdocs_Doc_Archive')) {
166 $documents_manager->register_document_type('doc-archive', Betterdocs_Doc_Archive::get_class_full_name());
167 }
168 }
169
170 /**
171 * @param Conditions_Manager $conditions_manager
172 */
173 public static function register_conditions($conditions_manager)
174 {
175 $betterdocs_condition = new Betterdocs_Archive_Condition();
176
177 $conditions_manager->get_condition('general')->register_sub_condition($betterdocs_condition);
178 }
179
180 public static function theme_template_include($need_override_location, $location)
181 {
182 if (is_singular(['docs']) && 'single' === $location) {
183 $need_override_location = true;
184 }
185
186 return $need_override_location;
187 }
188
189 public static function register_basic_widgets($widgets_manager)
190 {
191 foreach (self::get_basic_widget_list() as $value) {
192 if (class_exists($value)) {
193 //error_log( print_r(self::get_basic_widget_list(), TRUE) );
194 $widgets_manager->register_widget_type(new $value);
195 }
196 }
197 }
198
199 public static function register_widget_categories($elements_manager)
200 {
201 $elements_manager->add_category(
202 'betterdocs-elements',
203 [
204 'title' => __('BetterDocs', 'betterdocs'),
205 'icon' => 'font',
206 ], 1);
207 }
208
209 public static function register_theme_builder_widgets($widgets_manager)
210 {
211 foreach (self::get_theme_builder_widget_list() as $value) {
212 if (class_exists($value)) {
213 $widgets_manager->register_widget_type(new $value);
214 }
215 }
216 }
217
218 public static function _register_tag()
219 {
220 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/widgets/betterdocs-elementor-title-tag.php';
221
222 $module = Plugin::elementor()->dynamic_tags;
223 $module->register_tag(new BetterDocs_Elementor_Title_Tag());
224 }
225
226 public static function promote_pro_elements($config)
227 {
228 if (is_plugin_active('betterdocs-pro/betterdocs-pro.php')) {
229 return $config;
230 }
231
232 $promotion_widgets = [];
233
234 if (isset($config['promotionWidgets'])) {
235 $promotion_widgets = $config['promotionWidgets'];
236 }
237
238 $combine_array = array_merge($promotion_widgets, [
239 [
240 'name' => 'betterdocs-elementor-reactions',
241 'title' => __('Doc Reactions', 'betterdocs'),
242 'icon' => 'betterdocs-icon-Reactions',
243 'categories' => '["betterdocs-elements"]',
244 ],
245 [
246 'name' => 'betterdocs-multiple-kb',
247 'title' => __('BetterDocs Multiple KB', 'betterdocs'),
248 'icon' => 'betterdocs-icon-category-box',
249 'categories' => '["docs-archive"]',
250 ],
251 ]);
252
253 $config['promotionWidgets'] = $combine_array;
254
255 return $config;
256 }
257
258 public static function _betterdocs_init()
259 {
260 add_action('elementor/init', array(__CLASS__, 'register_bd_template_instance'), 20);
261 if (defined('Elementor\Api::LIBRARY_OPTION_KEY')) {
262 add_filter('option_' . Elementor\Api::LIBRARY_OPTION_KEY, array(__CLASS__, 'prepend_categories'));
263 }
264 add_action('elementor/ajax/register_actions', array(__CLASS__, 'modified_ajax_action'), 20);
265
266 if ( defined( 'ELEMENTOR_VERSION' ) && version_compare( ELEMENTOR_VERSION, '3.5.0', '>=' ) ) {
267 add_filter( 'option_' . Elementor\Api::LIBRARY_OPTION_KEY, array( __CLASS__, 'added_bd_template' ) );
268 }
269 }
270
271 public static function register_bd_template_instance()
272 {
273 require_once BETTERDOCS_DIR_PATH . 'includes/elementor/betterdocs-template-source.php';
274
275 $elementor = Elementor\Plugin::instance();
276 $elementor->templates_manager->register_source('BetterDocs_Template_Source');
277 }
278
279 public static function modified_ajax_action($ajax)
280 {
281 if (!isset($_REQUEST['actions'])) {
282 return;
283 }
284
285 $actions = json_decode(stripslashes($_REQUEST['actions']), true);
286 $data = false;
287
288 foreach ($actions as $id => $action_data) {
289 if (!isset($action_data['get_template_data'])) {
290 $data = $action_data;
291 }
292 }
293
294
295 if (!$data) {
296 return;
297 }
298
299 if (!isset($data['data'])) {
300 return;
301 }
302
303 $data = $data['data'];
304
305 if (empty($data['template_id'])) {
306 return;
307 }
308
309 if (false === strpos($data['template_id'], 'betterdocs_')) {
310 return;
311 }
312 $ajax->register_ajax_action('get_template_data', array(__CLASS__, 'get_bd_template_data'));
313 }
314
315 public static function prepend_categories($library_data)
316 {
317 $categories = self::get_template_categories();
318 if (!empty($categories)) {
319 $library_data['types_data']['block']['categories'] = array_merge($categories, $library_data['types_data']['block']['categories']);
320 }
321 return $library_data;
322 }
323
324 public static function get_template_categories()
325 {
326 return [
327 'Single Docs', 'Docs Archive'
328 ];
329 }
330
331 public static function get_bd_template_data($args)
332 {
333 $source = Elementor\Plugin::instance()->templates_manager->get_source('betterdocs-templates');
334
335 return $source->get_data($args);
336 }
337
338 /**
339 * Added BetterDocs template with Elementor core templates list
340 *
341 * added_template
342 *
343 * @param $templates_list array elementor template list
344 *
345 * @return array
346 * @since 2.0.7
347 *
348 */
349 public static function added_bd_template( array $templates_list ) {
350 $templates = self::get_bd_templates();
351
352 if ( ! empty( $templates ) ) {
353 $templates_list['templates'] = array_merge( $templates_list['templates'], $templates );
354 }
355
356 return $templates_list;
357 }
358
359 /**
360 * get_bd_templates
361 *
362 * Get Better docs template list and cache this list
363 *
364 * @return array|mixed
365 * @since 2.0.0
366 */
367 public static function get_bd_templates() {
368
369 $bd_template_cache_key = 'bd_templates';
370 $templates = get_transient( $bd_template_cache_key );
371
372 if ( ! $templates ) {
373 $source = Elementor\Plugin::instance()->templates_manager->get_source( 'betterdocs-templates' );
374
375 if( !$source ){
376 return $templates;
377 }
378
379 $templates = $source->get_items();
380
381 if ( ! empty( $templates ) ) {
382
383 $templates = array_map( function ( $template ) {
384
385 $template['id'] = $template['template_id'];
386 $template['tmpl_created'] = $template['date'];
387 $template['tags'] = json_encode( $template['tags'] );
388 $template['is_pro'] = $template['isPro'];
389 $template['access_level'] = $template['accessLevel'];
390 $template['popularity_index'] = $template['popularityIndex'];
391 $template['trend_index'] = $template['trendIndex'];
392 $template['has_page_settings'] = $template['hasPageSettings'];
393
394 return $template;
395 }, $templates );
396
397 set_transient( $bd_template_cache_key, $templates, WEEK_IN_SECONDS );
398
399 } else {
400 $templates = array();
401 }
402 }
403
404 return $templates;
405 }
406
407 /**
408 * Include a file with variables
409 *
410 * @param $file_path
411 * @param $variables
412 *
413 * @return string
414 * @since 4.2.2
415 */
416 public static function include_with_variable( $file_path, $variables = [])
417 {
418 if (file_exists($file_path)) {
419 extract($variables);
420
421 ob_start();
422
423 include $file_path;
424
425 return ob_get_clean();
426 }
427
428 return '';
429 }
430
431 public static function get_multiple_kb_terms($prettify = false, $term_id = true)
432 {
433 $args = [
434 'taxonomy' => 'knowledge_base',
435 'hide_empty' => true,
436 'parent' => 0,
437 ];
438
439 $terms = get_terms($args);
440
441 if (is_wp_error($terms)) {
442 return [];
443 }
444
445 if ($prettify) {
446 $pretty_taxonomies = [];
447
448 foreach ($terms as $term) {
449 $pretty_taxonomies[$term_id ? $term->term_id : $term->slug] = $term->name;
450 }
451
452 return $pretty_taxonomies;
453 }
454
455 return $terms;
456 }
457
458 public static function get_betterdocs_multiple_kb_status()
459 {
460 if (\BetterDocs_DB::get_settings('multiple_kb') == 1) {
461 return 'true';
462 }
463
464 return '';
465 }
466
467 /**
468 * POst Orderby Options
469 *
470 * @return array
471 */
472 public static function get_post_orderby_options()
473 {
474 $orderby = array(
475 'ID' => 'Post ID',
476 'author' => 'Post Author',
477 'title' => 'Title',
478 'date' => 'Date',
479 'modified' => 'Last Modified Date',
480 'parent' => 'Parent Id',
481 'rand' => 'Random',
482 'comment_count' => 'Comment Count',
483 'menu_order' => 'Menu Order',
484 'betterdocs_order' => 'BetterDocs Order',
485 );
486
487 return $orderby;
488 }
489
490 /**
491 * Get Post Categories
492 *
493 * @return array
494 */
495 public static function get_terms_list($taxonomy = 'category', $key = 'term_id')
496 {
497 $options = [];
498 $terms = get_terms([
499 'taxonomy' => $taxonomy,
500 'hide_empty' => true,
501 ]);
502
503 if (!empty($terms) && !is_wp_error($terms)) {
504 foreach ($terms as $term) {
505 $options[$term->{$key}] = $term->name;
506 }
507 }
508
509 return $options;
510 }
511
512 /**
513 * Query Controls
514 *
515 */
516 public static function betterdocs_query($wb, $taxonomy)
517 {
518 $wb->start_controls_section(
519 'eael_section_post__filters',
520 [
521 'label' => __('Query', 'betterdocs'),
522 ]
523 );
524
525 $default_multiple_kb = self::get_betterdocs_multiple_kb_status();
526
527 if ($default_multiple_kb && $taxonomy != 'knowledge_base') {
528 $multiple_kb_terms = self::get_multiple_kb_terms(true, false);
529 $default_slug = count($multiple_kb_terms) > 0 ? array_keys($multiple_kb_terms)[0] : '';
530
531 $wb->add_control(
532 'selected_knowledge_base',
533 [
534 'label' => __('Knowledge Bases', 'betterdocs'),
535 'label_block' => true,
536 'type' => Controls_Manager::SELECT2,
537 'options' => $multiple_kb_terms,
538 'multiple' => false,
539 'default' => '',
540 'select2options' => [
541 'placeholder' => __('All Knowledge Base', 'betterdocs'),
542 'allowClear' => true,
543 ]
544 ]
545 );
546 }
547
548 if ($wb->get_name() === 'betterdocs-category-grid') {
549 $wb->add_control(
550 'grid_query_heading',
551 [
552 'label' => __('Category Grid', 'betterdocs'),
553 'type' => Controls_Manager::HEADING,
554 ]
555 );
556 }
557
558 $wb->add_control(
559 'include',
560 [
561 'label' => __('Include', 'betterdocs'),
562 'label_block' => true,
563 'type' => Controls_Manager::SELECT2,
564 'options' => self::get_terms_list($taxonomy, 'term_id'),
565 'multiple' => true,
566 'default' => [],
567 ]
568 );
569
570 $wb->add_control(
571 'exclude',
572 [
573 'label' => __('Exclude', 'betterdocs'),
574 'type' => Controls_Manager::SELECT2,
575 'options' => self::get_terms_list($taxonomy, 'term_id'),
576 'label_block' => true,
577 'post_type' => '',
578 'multiple' => true,
579 ]
580 );
581
582 if ($wb->get_name() === 'betterdocs-category-grid') {
583 $wb->add_control(
584 'grid_per_page',
585 [
586 'label' => __('Grid Per Page', 'betterdocs'),
587 'type' => Controls_Manager::NUMBER,
588 'default' => '8',
589 ]
590 );
591 } else {
592 $wb->add_control(
593 'box_per_page',
594 [
595 'label' => __('Box Per Page', 'betterdocs'),
596 'type' => Controls_Manager::NUMBER,
597 'default' => '8',
598 ]
599 );
600 }
601
602 $wb->add_control(
603 'offset',
604 [
605 'label' => __('Offset', 'betterdocs'),
606 'type' => Controls_Manager::NUMBER,
607 'default' => '0',
608 ]
609 );
610
611 $wb->add_control(
612 'orderby',
613 [
614 'label' => __('Order By', 'betterdocs'),
615 'type' => Controls_Manager::SELECT,
616 'options' => [
617 'none' => __('No order', 'betterdocs'),
618 'name' => __('Name', 'betterdocs'),
619 'slug' => __('Slug', 'betterdocs'),
620 'term_group' => __('Term Group', 'betterdocs'),
621 'term_id' => __('Term ID', 'betterdocs'),
622 'id' => __('ID', 'betterdocs'),
623 'description' => __('Description', 'betterdocs'),
624 'parent' => __('Parent', 'betterdocs'),
625 'betterdocs_order' => __('BetterDocs Order', 'betterdocs'),
626 ],
627 'default' => 'name',
628 ]
629 );
630
631 $wb->add_control(
632 'order',
633 [
634 'label' => __('Order', 'betterdocs'),
635 'type' => Controls_Manager::SELECT,
636 'options' => [
637 'ASC' => 'Ascending',
638 'DESC' => 'Descending',
639 ],
640 'default' => 'asc',
641
642 ]
643 );
644
645 if ($wb->get_name() === 'betterdocs-category-grid') {
646 $wb->add_control(
647 'grid_posts_query_heading',
648 [
649 'label' => __('Grid List Posts', 'betterdocs'),
650 'type' => Controls_Manager::HEADING,
651 'separator' => 'before',
652 ]
653 );
654
655 $wb->add_control(
656 'post_per_page',
657 [
658 'label' => __('Post Per Page', 'betterdocs'),
659 'type' => Controls_Manager::NUMBER,
660 'default' => '6',
661 ]
662 );
663
664 $wb->add_control(
665 'post_orderby',
666 [
667 'label' => __('Order By', 'betterdocs'),
668 'type' => Controls_Manager::SELECT,
669 'options' => self::get_post_orderby_options(),
670 'default' => 'date',
671 ]
672 );
673
674 $wb->add_control(
675 'post_order',
676 [
677 'label' => __('Order', 'betterdocs'),
678 'type' => Controls_Manager::SELECT,
679 'options' => [
680 'asc' => 'Ascending',
681 'desc' => 'Descending',
682 ],
683 'default' => 'desc',
684 ]
685 );
686
687 $wb->add_control(
688 'nested_subcategory',
689 [
690 'label' => __('Enable Nested Subcategory', 'betterdocs'),
691 'type' => Controls_Manager::SWITCHER,
692 'label_on' => __('Yes', 'betterdocs'),
693 'label_off' => __('No', 'betterdocs'),
694 'return_value' => 'true',
695 'default' => false,
696 ]
697 );
698
699 $wb->add_control(
700 'post_per_subcat',
701 [
702 'label' => __('Post Per Subcategory', 'betterdocs'),
703 'type' => Controls_Manager::NUMBER,
704 'default' => '6',
705 'condition' => [
706 'nested_subcategory' => 'true'
707 ]
708 ]
709 );
710 }
711
712 if ($wb->get_name() === 'betterdocs-category-box') {
713 $wb->add_control(
714 'nested_subcategory',
715 [
716 'label' => __('Nested Subcategory', 'betterdocs'),
717 'type' => Controls_Manager::SWITCHER,
718 'label_on' => __('Yes', 'betterdocs'),
719 'label_off' => __('No', 'betterdocs'),
720 'return_value' => 'true',
721 'default' => false,
722 ]
723 );
724 }
725
726 if($wb->get_name() === 'betterdocs-tab-view-list') {
727
728 $wb->add_control(
729 'tab_posts_query_heading',
730 [
731 'label' => __('Tab List Posts', 'betterdocs'),
732 'type' => Controls_Manager::HEADING,
733 'separator' => 'before',
734 ]
735 );
736
737 $wb->add_control(
738 'post_per_tab',
739 [
740 'label' => __('Posts Per Tab', 'betterdocs'),
741 'type' => Controls_Manager::NUMBER,
742 'default' => '10'
743 ]
744 );
745
746 $wb->add_control(
747 'tab_list_posts_orderby',
748 [
749 'label' => __('Posts Order By', 'betterdocs'),
750 'type' => Controls_Manager::SELECT,
751 'options' => [
752 'name' => __('Name', 'betterdocs'),
753 'slug' => __('Slug', 'betterdocs'),
754 'term_group' => __('Term Group', 'betterdocs'),
755 'term_id' => __('Term ID', 'betterdocs'),
756 'id' => __('ID', 'betterdocs'),
757 'description' => __('Description', 'betterdocs'),
758 'parent' => __('Parent', 'betterdocs'),
759 'betterdocs_order' => __('BetterDocs Order', 'betterdocs'),
760 ],
761 'default' => 'name',
762 ]
763 );
764
765 $wb->add_control(
766 'tab_list_order',
767 [
768 'label' => __('Order', 'betterdocs'),
769 'type' => Controls_Manager::SELECT,
770 'options' => [
771 'ASC' => 'Ascending',
772 'DESC' => 'Descending',
773 ],
774 'default' => 'ASC',
775
776 ]
777 );
778
779 $wb->add_control(
780 'nested_subcategory_tab_list',
781 [
782 'label' => __('Nested Subcategory', 'betterdocs'),
783 'type' => Controls_Manager::SWITCHER,
784 'label_on' => __('Yes', 'betterdocs'),
785 'label_off' => __('No', 'betterdocs'),
786 'return_value' => 'true',
787 'default' => 'true',
788 ]
789 );
790
791 $wb->add_control(
792 'nested_posts_per_page',
793 [
794 'label' => __('Posts Per Page', 'betterdocs'),
795 'type' => Controls_Manager::NUMBER,
796 'default' => '-1',
797 'condition' => [
798 'nested_subcategory_tab_list' => 'true'
799 ]
800 ]
801 );
802
803 $wb->add_control(
804 'nested_sub_cat_order',
805 [
806 'label' => __('Nested Posts Order', 'betterdocs'),
807 'type' => Controls_Manager::SELECT,
808 'options' => [
809 'ASC' => 'Ascending',
810 'DESC' => 'Descending',
811 ],
812 'default' => 'ASC',
813 'condition' => [
814 'nested_subcategory_tab_list' => 'true'
815 ]
816 ]
817 );
818
819 $wb->add_control(
820 'nested_sub_cat_orderby',
821 [
822 'label' => __('Nested Posts Order By', 'betterdocs'),
823 'type' => Controls_Manager::SELECT,
824 'options' => [
825 'none' => __('No order', 'betterdocs'),
826 'name' => __('Name', 'betterdocs'),
827 'slug' => __('Slug', 'betterdocs'),
828 'term_group' => __('Term Group', 'betterdocs'),
829 'term_id' => __('Term ID', 'betterdocs'),
830 'id' => __('ID', 'betterdocs'),
831 'description' => __('Description', 'betterdocs'),
832 'parent' => __('Parent', 'betterdocs'),
833 'betterdocs_order' => __('BetterDocs Order', 'betterdocs'),
834 ],
835 'default' => 'name',
836 'condition' => [
837 'nested_subcategory_tab_list' => 'true'
838 ]
839 ]
840 );
841 }
842
843 $wb->end_controls_section();
844 }
845
846 public function nested_subcategory($term_id, $settings, $multiple_kb) {
847 $html='';
848 $sub_categories = BetterDocs_Helper::child_taxonomy_terms($term_id, $multiple_kb, $settings['orderby'], $settings['order'], '');
849 if ($sub_categories) {
850 foreach ($sub_categories as $sub_category) {
851 $html .= '<span class="el-betterdocs-grid-sub-cat-title">';
852
853 if (isset($settings['nested_list_title_closed_icon']['value']['url']) && !empty($settings['nested_list_title_closed_icon']['value']['url'])) {
854 $html .= '<img class="toggle-arrow arrow-right" src="' . $settings['nested_list_title_closed_icon']['value']['url'] . '" />';
855 } else {
856 $html .= '<i class="' . $settings['nested_list_title_closed_icon']['value'] . ' toggle-arrow arrow-right"></i>';
857 }
858
859 if (isset($settings['nested_list_title_open_icon']['value']['url']) && !empty($settings['nested_list_title_open_icon']['value']['url'])) {
860 $html .= '<img class="toggle-arrow arrow-down" src="' . $settings['nested_list_title_open_icon']['value']['url'] . '" />';
861 } else {
862 $html .= '<i class="' . $settings['nested_list_title_open_icon']['value'] . ' toggle-arrow arrow-down"></i>';
863 }
864
865 $html .= '<a href="#">' . $sub_category->name . '</a></span>';
866 $html .= '<ul class="docs-sub-cat-list">';
867
868 $sub_args = array(
869 'post_type' => 'docs',
870 'post_status' => 'publish'
871 );
872
873 $tax_query = array(
874 array(
875 'taxonomy' => 'doc_category',
876 'field' => 'slug',
877 'terms' => $sub_category->slug,
878 'operator' => 'AND',
879 'include_children' => false
880 ),
881 );
882
883 $sub_args['posts_per_page'] = $settings['post_per_subcat'];
884
885 if( $settings['post_orderby'] != 'betterdocs_order' ) {
886 $sub_args['orderby'] = $settings['post_orderby'];
887 $sub_args['order'] = $settings['post_order'];
888 }
889 $sub_args['tax_query'] = apply_filters('betterdocs_list_tax_query_arg', $tax_query, $multiple_kb, $sub_category->slug, '');
890 $sub_args = apply_filters('betterdocs_articles_args', $sub_args, $sub_category->term_id);
891 $sub_post_query = new \WP_Query($sub_args);
892 if ($sub_post_query->have_posts()):
893 while ($sub_post_query->have_posts()): $sub_post_query->the_post();
894 $sub_attr = ['href="' . get_the_permalink() . '"'];
895 $html .= '<li class="sub-list">';
896 if (isset($settings['list_icon']['value']['url']) && !empty($settings['list_icon']['value']['url'])) {
897 $html .= '<img class="el-betterdocs-cg-post-list-icon" src="' . $settings['list_icon']['value']['url'] . '" />';
898 } else {
899 $html .= '<i class="' . $settings['list_icon']['value'] . ' el-betterdocs-cg-post-list-icon"></i>';
900 }
901 $html .= '<a ' . implode(' ', $sub_attr) . '>' . get_the_title() . '</a></li>';
902 endwhile;
903 endif;
904 wp_reset_query();
905 $html .= $this->nested_subcategory($sub_category->term_id, $settings, $multiple_kb);
906 $html .= '</ul>';
907 }
908 }
909 return $html;
910 }
911
912 const ELBD_ALLOWED_HTML_TAGS = [
913 'article',
914 'aside',
915 'div',
916 'footer',
917 'h1',
918 'h2',
919 'h3',
920 'h4',
921 'h5',
922 'h6',
923 'header',
924 'main',
925 'nav',
926 'p',
927 'section',
928 'span',
929 ];
930
931 /**
932 * elbd_validate_html_tag
933 * @param $tag
934 * @return mixed|string
935 */
936 public static function elbd_validate_html_tag( $tag ){
937 return in_array( strtolower( $tag ), self::ELBD_ALLOWED_HTML_TAGS ) ? $tag : 'div';
938 }
939 }
940
941 BetterDocs_Elementor::init();
942