| @@ -1,5 +1,7 @@ | ||
| 1 | 1 | <?php |
| 2 | +// phpcs:disable WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- widget settings expose user-controlled exclusion lists; matches widget UX. | |
| 3 | +// phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query,WordPress.DB.SlowDBQuery.slow_db_query_tax_query,WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- core docs widget queries; meta/tax filtering is required functionality. | |
| 2 | 4 | namespace WPDeveloper\BetterDocs\Editors\Elementor\Widget; |
| 3 | 5 | |
| 4 | 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 5 | 7 | exit; // Exit if accessed directly |
| @@ -158,10 +160,10 @@ | ||
| 158 | 160 | 'search_modal_query_term_ids', |
| 159 | 161 | [ |
| 160 | 162 | 'label' => __( "Doc Term ID's", 'betterdocs' ), |
| 161 | 163 | 'type' => Controls_Manager::TEXT, |
| 162 | - 'description' => __('Example: 8, 9'), | |
| 163 | - 'default' => "", | |
| 164 | + 'description' => __( 'Example: 8, 9', 'betterdocs' ), | |
| 165 | + 'default' => '', | |
| 164 | 166 | 'condition' => [ |
| 165 | 167 | 'search_modal_doc_query_type' => 'specific_doc_term_ids' |
| 166 | 168 | ] |
| 167 | 169 | ] |
| @@ -171,10 +173,10 @@ | ||
| 171 | 173 | 'search_modal_query_doc_ids', |
| 172 | 174 | [ |
| 173 | 175 | 'label' => __( "Doc ID's", 'betterdocs' ), |
| 174 | 176 | 'type' => Controls_Manager::TEXT, |
| 175 | - 'description' => __('Example: 15, 16'), | |
| 176 | - 'default' => "", | |
| 177 | + 'description' => __( 'Example: 15, 16', 'betterdocs' ), | |
| 178 | + 'default' => '', | |
| 177 | 179 | 'condition' => [ |
| 178 | 180 | 'search_modal_doc_query_type' => 'specific_doc_ids' |
| 179 | 181 | ] |
| 180 | 182 | ] |
| @@ -199,10 +201,10 @@ | ||
| 199 | 201 | 'search_modal_query_faq_term_ids', |
| 200 | 202 | [ |
| 201 | 203 | 'label' => __( "FAQ Term ID's", 'betterdocs' ), |
| 202 | 204 | 'type' => Controls_Manager::TEXT, |
| 203 | - 'description' => __('Example: 8, 9'), | |
| 204 | - 'default' => "", | |
| 205 | + 'description' => __( 'Example: 8, 9', 'betterdocs' ), | |
| 206 | + 'default' => '', | |
| 205 | 207 | 'condition' => [ |
| 206 | 208 | 'search_modal_faq_query_type' => 'specific_faq_term_ids' |
| 207 | 209 | ] |
| 208 | 210 | ] |
| @@ -443,9 +445,9 @@ | ||
| 443 | 445 | ); |
| 444 | 446 | $this->add_control( |
| 445 | 447 | 'column_height', |
| 446 | 448 | [ |
| 447 | - 'label' => __( 'Height', 'plugin-domain' ), | |
| 449 | + 'label' => __( 'Height', 'betterdocs' ), | |
| 448 | 450 | 'type' => Controls_Manager::SLIDER, |
| 449 | 451 | 'size_units' => ['px', '%'], |
| 450 | 452 | 'range' => [ |
| 451 | 453 | 'px' => [ |
| @@ -732,9 +734,9 @@ | ||
| 732 | 734 | |
| 733 | 735 | $this->add_control( |
| 734 | 736 | 'arrow_color', |
| 735 | 737 | [ |
| 736 | - 'label' => __( 'Arrow Color', 'plugin-domain' ), | |
| 738 | + 'label' => __( 'Arrow Color', 'betterdocs' ), | |
| 737 | 739 | 'type' => Controls_Manager::COLOR, |
| 738 | 740 | 'selectors' => [ |
| 739 | 741 | '{{WRAPPER}} .betterdocs-category-collapse' => 'color: {{VALUE}}' |
| 740 | 742 | ], |
| @@ -845,9 +847,9 @@ | ||
| 845 | 847 | |
| 846 | 848 | $this->add_control( |
| 847 | 849 | 'arrow_color_hover', |
| 848 | 850 | [ |
| 849 | - 'label' => __( 'Arrow Color', 'plugin-domain' ), | |
| 851 | + 'label' => __( 'Arrow Color', 'betterdocs' ), | |
| 850 | 852 | 'type' => Controls_Manager::COLOR, |
| 851 | 853 | 'selectors' => [ |
| 852 | 854 | '{{WRAPPER}} .betterdocs-category-grid-wrapper .betterdocs-category-header:hover .betterdocs-category-arrow' => 'color: {{VALUE}}' |
| 853 | 855 | ] |
| @@ -1547,9 +1549,9 @@ | ||
| 1547 | 1549 | |
| 1548 | 1550 | $this->add_control( |
| 1549 | 1551 | 'second_color_seperator', |
| 1550 | 1552 | [ |
| 1551 | - 'label' => esc_html__( 'Second Color', 'textdomain' ), | |
| 1553 | + 'label' => esc_html__( 'Second Color', 'betterdocs' ), | |
| 1552 | 1554 | 'type' => \Elementor\Controls_Manager::HEADING, |
| 1553 | 1555 | 'separator' => 'before', |
| 1554 | 1556 | 'condition' => [ |
| 1555 | 1557 | 'betterdocs_sidebar_layout' => 'layout-1' |
| @@ -1659,9 +1661,9 @@ | ||
| 1659 | 1661 | |
| 1660 | 1662 | $this->add_control( |
| 1661 | 1663 | 'hover_second_color_seperator', |
| 1662 | 1664 | [ |
| 1663 | - 'label' => esc_html__( 'Second Color', 'textdomain' ), | |
| 1665 | + 'label' => esc_html__( 'Second Color', 'betterdocs' ), | |
| 1664 | 1666 | 'type' => \Elementor\Controls_Manager::HEADING, |
| 1665 | 1667 | 'separator' => 'before', |
| 1666 | 1668 | 'condition' => [ |
| 1667 | 1669 | 'betterdocs_sidebar_layout' => 'layout-1' |
| @@ -2504,9 +2506,9 @@ | ||
| 2504 | 2506 | |
| 2505 | 2507 | $this->add_control( |
| 2506 | 2508 | 'sidebar_search_modal_field', |
| 2507 | 2509 | [ |
| 2508 | - 'label' => esc_html__( 'Search Field', 'textdomain' ), | |
| 2510 | + 'label' => esc_html__( 'Search Field', 'betterdocs' ), | |
| 2509 | 2511 | 'type' => \Elementor\Controls_Manager::HEADING, |
| 2510 | 2512 | 'separator' => 'before' |
| 2511 | 2513 | ] |
| 2512 | 2514 | ); |
| @@ -2565,9 +2567,9 @@ | ||
| 2565 | 2567 | |
| 2566 | 2568 | $this->add_control( |
| 2567 | 2569 | 'sidebar_search_modal_category_section', |
| 2568 | 2570 | [ |
| 2569 | - 'label' => esc_html__( 'Search Category', 'textdomain' ), | |
| 2571 | + 'label' => esc_html__( 'Search Category', 'betterdocs' ), | |
| 2570 | 2572 | 'type' => \Elementor\Controls_Manager::HEADING, |
| 2571 | 2573 | 'separator' => 'before' |
| 2572 | 2574 | ] |
| 2573 | 2575 | ); |
| @@ -2593,9 +2595,9 @@ | ||
| 2593 | 2595 | |
| 2594 | 2596 | $this->add_control( |
| 2595 | 2597 | 'sidebar_search_modal_content_tabs', |
| 2596 | 2598 | [ |
| 2597 | - 'label' => esc_html__( 'Content Tabs', 'textdomain' ), | |
| 2599 | + 'label' => esc_html__( 'Content Tabs', 'betterdocs' ), | |
| 2598 | 2600 | 'type' => \Elementor\Controls_Manager::HEADING, |
| 2599 | 2601 | 'separator' => 'before' |
| 2600 | 2602 | ] |
| 2601 | 2603 | ); |
| @@ -2610,9 +2612,9 @@ | ||
| 2610 | 2612 | |
| 2611 | 2613 | $this->add_control( |
| 2612 | 2614 | 'sidebar_search_modal_content_tabs_icon_size', |
| 2613 | 2615 | [ |
| 2614 | - 'label' => __( 'Icon Size', 'plugin-domain' ), | |
| 2616 | + 'label' => __( 'Icon Size', 'betterdocs' ), | |
| 2615 | 2617 | 'type' => Controls_Manager::SLIDER, |
| 2616 | 2618 | 'size_units' => ['px', '%'], |
| 2617 | 2619 | 'range' => [ |
| 2618 | 2620 | 'px' => [ |
| @@ -2642,9 +2644,9 @@ | ||
| 2642 | 2644 | |
| 2643 | 2645 | $this->add_control( |
| 2644 | 2646 | 'sidebar_search_modal_content_list', |
| 2645 | 2647 | [ |
| 2646 | - 'label' => esc_html__( 'Content List', 'textdomain' ), | |
| 2648 | + 'label' => esc_html__( 'Content List', 'betterdocs' ), | |
| 2647 | 2649 | 'type' => \Elementor\Controls_Manager::HEADING, |
| 2648 | 2650 | 'separator' => 'before' |
| 2649 | 2651 | ] |
| 2650 | 2652 | ); |
| @@ -2670,9 +2672,9 @@ | ||
| 2670 | 2672 | |
| 2671 | 2673 | $this->add_control( |
| 2672 | 2674 | 'sidebar_search_modal_content_list_icon_size', |
| 2673 | 2675 | [ |
| 2674 | - 'label' => __( 'Icon Size', 'plugin-domain' ), | |
| 2676 | + 'label' => __( 'Icon Size', 'betterdocs' ), | |
| 2675 | 2677 | 'type' => Controls_Manager::SLIDER, |
| 2676 | 2678 | 'size_units' => ['px', '%'], |
| 2677 | 2679 | 'range' => [ |
| 2678 | 2680 | 'px' => [ |
| @@ -2702,9 +2704,9 @@ | ||
| 2702 | 2704 | |
| 2703 | 2705 | $this->add_control( |
| 2704 | 2706 | 'sidebar_search_modal_content_list_category', |
| 2705 | 2707 | [ |
| 2706 | - 'label' => esc_html__( 'Content List Category', 'textdomain' ), | |
| 2708 | + 'label' => esc_html__( 'Content List Category', 'betterdocs' ), | |
| 2707 | 2709 | 'type' => \Elementor\Controls_Manager::HEADING, |
| 2708 | 2710 | 'separator' => 'before' |
| 2709 | 2711 | ] |
| 2710 | 2712 | ); |
| @@ -2730,9 +2732,9 @@ | ||
| 2730 | 2732 | |
| 2731 | 2733 | $this->add_control( |
| 2732 | 2734 | 'sidebar_search_modal_content_list_category_icon_size', |
| 2733 | 2735 | [ |
| 2734 | - 'label' => __( 'Icon Size', 'plugin-domain' ), | |
| 2736 | + 'label' => __( 'Icon Size', 'betterdocs' ), | |
| 2735 | 2737 | 'type' => Controls_Manager::SLIDER, |
| 2736 | 2738 | 'size_units' => ['px', '%'], |
| 2737 | 2739 | 'range' => [ |
| 2738 | 2740 | 'px' => [ |
| @@ -2928,9 +2930,16 @@ | ||
| 2928 | 2930 | /** |
| 2929 | 2931 | * Localize This In Order To Know If This Block Is Arriving From Betterdocs Templates Or Not |
| 2930 | 2932 | */ |
| 2931 | 2933 | betterdocs()->assets->localize( 'betterdocs-category-grid', 'betterdocsCategoryGridConfig', [ |
| 2932 | - 'is_betterdocs_templates' => betterdocs()->helper->is_templates() ? true : false | |
| 2934 | + 'is_betterdocs_templates' => betterdocs()->helper->is_templates() ? true : false, | |
| 2935 | + // Must also carry the lazy-load endpoint. wp_localize_script concatenates | |
| 2936 | + // every `var betterdocsCategoryGridConfig = …` for this object name and the | |
| 2937 | + // last assignment wins; shipping only is_betterdocs_templates here clobbered | |
| 2938 | + // Scripts.php's full config on Elementor pages, leaving ajax_url undefined so | |
| 2939 | + // loadLazyBody() bailed and the sidebar widget's lazy-load never fired. | |
| 2940 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), | |
| 2941 | + 'lazy_load_action' => 'betterdocs_lazy_category_body', | |
| 2933 | 2942 | ] ); |
| 2934 | 2943 | |
| 2935 | 2944 | $settings = &$this->attributes; |
| 2936 | 2945 | $default_multiple_kb = (bool) betterdocs()->editor->get( 'elementor' )->multiple_kb_status(); |
| @@ -2959,10 +2968,9 @@ | ||
| 2959 | 2968 | 'terms_include' => array_diff( $settings['include'], (array) $settings['exclude'] ), |
| 2960 | 2969 | 'terms_exclude' => $settings['exclude'], |
| 2961 | 2970 | 'terms_offset' => $settings['offset'], |
| 2962 | 2971 | 'nested_subcategory' => $settings['nested_subcategory'], |
| 2963 | - 'multiple_knowledge_base' => $default_multiple_kb, | |
| 2964 | - 'kb_slug' => $kb_slug, | |
| 2972 | + 'lazy_load' => ! empty( $settings['lazy_load'] ), | |
| 2965 | 2973 | 'sidebar_list' => true, |
| 2966 | 2974 | 'disable_customizer_style' => true, |
| 2967 | 2975 | 'posts_per_page' => -1, |
| 2968 | 2976 | 'title_tag' => $settings['category_title_tag'], |
| @@ -2968,8 +2976,18 @@ | ||
| 2968 | 2976 | 'title_tag' => $settings['category_title_tag'], |
| 2969 | 2977 | 'sidebar_layout' => $settings['betterdocs_sidebar_layout'] |
| 2970 | 2978 | ] |
| 2971 | 2979 | ]; |
| 2980 | + | |
| 2981 | + // Pass a KB scope only when one is explicitly selected on the widget. When none | |
| 2982 | + // is set, omit kb_slug so the betterdocs_sidebar_template_shortcode_params filter | |
| 2983 | + // (Pro/MKB) can inject the current knowledge_base context on KB templates — the | |
| 2984 | + // same path the default sidebar uses. With no KB context nothing is injected and | |
| 2985 | + // all categories render. (Passing kb_slug='' here would block that injection.) | |
| 2986 | + if ( ! empty( $kb_slug ) ) { | |
| 2987 | + $params['shortcode_attr']['kb_slug'] = $kb_slug; | |
| 2988 | + $params['shortcode_attr']['multiple_knowledge_base'] = (bool) $default_multiple_kb; | |
| 2989 | + } | |
| 2972 | 2990 | |
| 2973 | 2991 | if ( $settings['betterdocs_sidebar_layout'] == 'layout-1' ) { |
| 2974 | 2992 | $params['shortcode_attr']['show_icon'] = $settings['show_icon']; |
| 2975 | 2993 | $params['shortcode_attr']['show_count'] = $settings['show_count']; |