| @@ -2930,9 +2930,16 @@ | ||
| 2930 | 2930 | /** |
| 2931 | 2931 | * Localize This In Order To Know If This Block Is Arriving From Betterdocs Templates Or Not |
| 2932 | 2932 | */ |
| 2933 | 2933 | betterdocs()->assets->localize( 'betterdocs-category-grid', 'betterdocsCategoryGridConfig', [ |
| 2934 | - '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', | |
| 2935 | 2942 | ] ); |
| 2936 | 2943 | |
| 2937 | 2944 | $settings = &$this->attributes; |
| 2938 | 2945 | $default_multiple_kb = (bool) betterdocs()->editor->get( 'elementor' )->multiple_kb_status(); |
| @@ -2961,10 +2968,9 @@ | ||
| 2961 | 2968 | 'terms_include' => array_diff( $settings['include'], (array) $settings['exclude'] ), |
| 2962 | 2969 | 'terms_exclude' => $settings['exclude'], |
| 2963 | 2970 | 'terms_offset' => $settings['offset'], |
| 2964 | 2971 | 'nested_subcategory' => $settings['nested_subcategory'], |
| 2965 | - 'multiple_knowledge_base' => $default_multiple_kb, | |
| 2966 | - 'kb_slug' => $kb_slug, | |
| 2972 | + 'lazy_load' => ! empty( $settings['lazy_load'] ), | |
| 2967 | 2973 | 'sidebar_list' => true, |
| 2968 | 2974 | 'disable_customizer_style' => true, |
| 2969 | 2975 | 'posts_per_page' => -1, |
| 2970 | 2976 | 'title_tag' => $settings['category_title_tag'], |
| @@ -2970,8 +2976,18 @@ | ||
| 2970 | 2976 | 'title_tag' => $settings['category_title_tag'], |
| 2971 | 2977 | 'sidebar_layout' => $settings['betterdocs_sidebar_layout'] |
| 2972 | 2978 | ] |
| 2973 | 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 | + } | |
| 2974 | 2990 | |
| 2975 | 2991 | if ( $settings['betterdocs_sidebar_layout'] == 'layout-1' ) { |
| 2976 | 2992 | $params['shortcode_attr']['show_icon'] = $settings['show_icon']; |
| 2977 | 2993 | $params['shortcode_attr']['show_count'] = $settings['show_count']; |