| @@ -27,8 +27,9 @@ | ||
| 27 | 27 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Basic\FAQ; |
| 28 | 28 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Reactions; |
| 29 | 29 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Navigation; |
| 30 | 30 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\CodeSnippet; |
| 31 | +use WPDeveloper\BetterDocs\Editors\Elementor\Widget\CodeSnippetTab; | |
| 31 | 32 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\ArchiveList; |
| 32 | 33 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\PrintButton; |
| 33 | 34 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\Breadcrumbs; |
| 34 | 35 | use WPDeveloper\BetterDocs\Editors\Elementor\Widget\ReadingTime; |
| @@ -407,8 +408,21 @@ | ||
| 407 | 408 | 'nested_subcategory' => 'true' |
| 408 | 409 | ] |
| 409 | 410 | ] |
| 410 | 411 | ); |
| 412 | + | |
| 413 | + $wb->add_control( | |
| 414 | + 'lazy_load', | |
| 415 | + [ | |
| 416 | + 'label' => __( 'Lazy Load Docs & Subcategories', 'betterdocs' ), | |
| 417 | + 'description' => __( 'Render only the active category upfront; fetch the rest on click. Recommended for large knowledge bases when this widget is used as a sidebar.', 'betterdocs' ), | |
| 418 | + 'type' => Controls_Manager::SWITCHER, | |
| 419 | + 'label_on' => __( 'Yes', 'betterdocs' ), | |
| 420 | + 'label_off' => __( 'No', 'betterdocs' ), | |
| 421 | + 'return_value' => 'true', | |
| 422 | + 'default' => '' | |
| 423 | + ] | |
| 424 | + ); | |
| 411 | 425 | } |
| 412 | 426 | |
| 413 | 427 | if ( $wb->get_name() === 'betterdocs-category-box' ) { |
| 414 | 428 | $wb->add_control( |
| @@ -456,8 +470,21 @@ | ||
| 456 | 470 | 'return_value' => 'true', |
| 457 | 471 | 'default' => ( $this->settings->get( 'archive_nested_subcategory' ) == 1 ) ? 'true' : '' |
| 458 | 472 | ] |
| 459 | 473 | ); |
| 474 | + | |
| 475 | + $wb->add_control( | |
| 476 | + 'lazy_load', | |
| 477 | + [ | |
| 478 | + 'label' => __( 'Lazy Load Docs & Subcategories', 'betterdocs' ), | |
| 479 | + 'description' => __( 'Render only the active category upfront; fetch the rest on click (or on scroll for the Memphis sidebar layout).', 'betterdocs' ), | |
| 480 | + 'type' => Controls_Manager::SWITCHER, | |
| 481 | + 'label_on' => __( 'Yes', 'betterdocs' ), | |
| 482 | + 'label_off' => __( 'No', 'betterdocs' ), | |
| 483 | + 'return_value' => 'true', | |
| 484 | + 'default' => ( $this->settings->get( 'archive_lazy_load_descendants' ) == 1 ) ? 'true' : '' | |
| 485 | + ] | |
| 486 | + ); | |
| 460 | 487 | } |
| 461 | 488 | |
| 462 | 489 | if ( $wb->get_name() === 'betterdocs-tab-view-list' ) { |
| 463 | 490 | $wb->add_control( |
| @@ -595,17 +622,25 @@ | ||
| 595 | 622 | return ''; |
| 596 | 623 | } |
| 597 | 624 | |
| 598 | 625 | public function get_kb_terms( $prettify = false, $term_id = true ) { |
| 599 | - $args = [ | |
| 600 | - 'taxonomy' => 'knowledge_base', | |
| 601 | - 'hide_empty' => true, | |
| 602 | - 'parent' => 0 | |
| 603 | - ]; | |
| 626 | + // This list populates the widget "Knowledge Bases" selector — an admin-side | |
| 627 | + // config picker, not a front-end listing. It must show EVERY KB regardless of | |
| 628 | + // whether it currently has content or is access-restricted for the editing | |
| 629 | + // user's role. Previously it ran through terms_query()/get_terms(), so on a | |
| 630 | + // regular page the Pro access-control terms_clauses filter + hide_empty pruned | |
| 631 | + // the list to a subset, while the theme-builder context showed them all. | |
| 632 | + // hide_empty:false keeps empty KBs; suppress_filters:true signals AccessControl | |
| 633 | + // (get_terms_args) to skip its role-based terms_clauses filter, so the picker is | |
| 634 | + // consistent everywhere. | |
| 635 | + $terms = get_terms( [ | |
| 636 | + 'taxonomy' => 'knowledge_base', | |
| 637 | + 'hide_empty' => false, | |
| 638 | + 'parent' => 0, | |
| 639 | + 'orderby' => 'name', | |
| 640 | + 'suppress_filters' => true, | |
| 641 | + ] ); | |
| 604 | 642 | |
| 605 | - $terms_query_args = betterdocs()->query->terms_query( $args ); | |
| 606 | - $terms = betterdocs()->query->get_terms( $terms_query_args ); | |
| 607 | - | |
| 608 | 643 | if ( is_wp_error( $terms ) ) { |
| 609 | 644 | return []; |
| 610 | 645 | } |
| 611 | 646 | |
| @@ -612,9 +647,11 @@ | ||
| 612 | 647 | if ( $prettify ) { |
| 613 | 648 | $pretty_taxonomies = []; |
| 614 | 649 | |
| 615 | 650 | foreach ( $terms as $term ) { |
| 616 | - $pretty_taxonomies[$term_id ? $term->term_id : $term->slug] = $term->name; | |
| 651 | + // Decode HTML entities (e.g. "&" → "&") so the select2 control | |
| 652 | + // shows the real KB name instead of the escaped entity. | |
| 653 | + $pretty_taxonomies[$term_id ? $term->term_id : $term->slug] = wp_specialchars_decode( $term->name, ENT_QUOTES ); | |
| 617 | 654 | } |
| 618 | 655 | |
| 619 | 656 | return $pretty_taxonomies; |
| 620 | 657 | } |
| @@ -661,9 +698,10 @@ | ||
| 661 | 698 | 'betterdocs-elementor-category-grid' => CategoryGrid::class, |
| 662 | 699 | 'betterdocs-elementor-category-box' => CategoryBox::class, |
| 663 | 700 | 'betterdocs-elementor-category-slate' => CategorySlateLayout::class, |
| 664 | 701 | 'betterdocs-faq-widget' => FAQ::class, |
| 665 | - 'betterdocs-code-snippet' => CodeSnippet::class | |
| 702 | + 'betterdocs-code-snippet' => CodeSnippet::class, | |
| 703 | + 'betterdocs-code-snippet-tab' => CodeSnippetTab::class | |
| 666 | 704 | ]; |
| 667 | 705 | |
| 668 | 706 | return $widget_arr; |
| 669 | 707 | } |
| @@ -724,8 +762,9 @@ | ||
| 724 | 762 | $assets->register( 'betterdocs-el-category-box', 'elementor/css/category-box.css' ); |
| 725 | 763 | $assets->register( 'betterdocs-el-articles-list', 'elementor/css/articles-list.css' ); |
| 726 | 764 | $assets->register( 'betterdocs-el-navigation', 'elementor/css/navigation.css' ); |
| 727 | 765 | $assets->register( 'betterdocs-code-snippet', 'public/css/code-snippet.css' ); |
| 766 | + $assets->register( 'betterdocs-code-snippet-tab', 'public/css/code-snippet-tab.css' ); | |
| 728 | 767 | |
| 729 | 768 | /** |
| 730 | 769 | * Widget's JS |
| 731 | 770 | */ |
| @@ -730,14 +769,22 @@ | ||
| 730 | 769 | * Widget's JS |
| 731 | 770 | */ |
| 732 | 771 | $assets->register( 'betterdocs-el-category-grid', 'elementor/js/category-grid.js', ['jquery', 'betterdocs-category-toggler'] ); |
| 733 | 772 | $assets->register( 'betterdocs-code-snippet', 'public/js/code-snippet.js', ['jquery'] ); |
| 773 | + $assets->register( 'betterdocs-code-snippet-tab', 'public/js/code-snippet-tab.js', ['jquery'] ); | |
| 734 | 774 | |
| 735 | 775 | /** |
| 736 | 776 | * Localize This In Order To Know If This Block Is Arriving From Betterdocs Templates Or Not |
| 737 | 777 | */ |
| 738 | 778 | betterdocs()->assets->localize( 'betterdocs-el-category-grid', 'betterdocsCategoryGridConfig', [ |
| 739 | - 'is_betterdocs_templates' => betterdocs()->helper->is_templates() ? true : false | |
| 779 | + 'is_betterdocs_templates' => betterdocs()->helper->is_templates() ? true : false, | |
| 780 | + // Must also carry the lazy-load endpoint. wp_localize_script concatenates | |
| 781 | + // every `var betterdocsCategoryGridConfig = …` for this object name and the | |
| 782 | + // last assignment wins; shipping only is_betterdocs_templates here clobbered | |
| 783 | + // Scripts.php's full config on Elementor pages, leaving ajax_url undefined so | |
| 784 | + // loadLazyBody() bailed and sidebar lazy-load never fired. | |
| 785 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 786 | + 'lazy_load_action' => 'betterdocs_lazy_category_body', | |
| 740 | 787 | ] ); |
| 741 | 788 | |
| 742 | 789 | if ( betterdocs()->helper->is_el_templates() == true ) { |
| 743 | 790 | $assets->enqueue( 'betterdocs-elementor-editor', 'elementor/css/betterdocs-el-edit.css' ); |