| @@ -1,13 +1,8 @@ | ||
| 1 | 1 | <?php |
| 2 | -// phpcs:disable WordPress.DB.SlowDBQuery.slow_db_query_meta_query,WordPress.DB.SlowDBQuery.slow_db_query_meta_key,WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- core block query; meta/tax filtering required. | |
| 2 | + | |
| 3 | 3 | namespace WPDeveloper\BetterDocs\Editors\BlockEditor\Blocks; |
| 4 | 4 | |
| 5 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 6 | - exit; | |
| 7 | -} | |
| 8 | - | |
| 9 | - | |
| 10 | 5 | use WPDeveloper\BetterDocs\Editors\BlockEditor\Block; |
| 11 | 6 | |
| 12 | 7 | class Sidebar extends Block { |
| 13 | 8 | |
| @@ -34,18 +29,16 @@ | ||
| 34 | 29 | return 'sidebar'; |
| 35 | 30 | } |
| 36 | 31 | |
| 37 | 32 | public function register_scripts() { |
| 38 | - if( is_admin() ){ // load for wordpress admin panel only | |
| 39 | - if ( function_exists( 'betterdocs_pro' ) && betterdocs_pro()->assets != null ) { // get the sidebar modal on gutenberg edit mode | |
| 40 | - betterdocs_pro()->assets->enqueue( 'betterdocs-extend-search-modal', 'public/js/extend-search-modal.js', [] ); | |
| 41 | - } | |
| 42 | - $this->assets_manager->enqueue( | |
| 43 | - 'betterdocs-search-modal', | |
| 44 | - 'shortcodes/js/search-modal.js', | |
| 45 | - [ 'jquery' ] | |
| 46 | - ); | |
| 33 | + if ( function_exists( 'betterdocs_pro' ) && betterdocs_pro()->assets != null ) { // get the sidebar modal on gutenberg edit mode | |
| 34 | + betterdocs_pro()->assets->enqueue( 'betterdocs-extend-search-modal', 'public/js/extend-search-modal.js', [] ); | |
| 47 | 35 | } |
| 36 | + $this->assets_manager->enqueue( | |
| 37 | + 'betterdocs-search-modal', | |
| 38 | + 'shortcodes/js/search-modal.js', | |
| 39 | + [ 'jquery' ] | |
| 40 | + ); | |
| 48 | 41 | } |
| 49 | 42 | |
| 50 | 43 | public function get_default_attributes() { |
| 51 | 44 | return [ |
| @@ -60,12 +53,8 @@ | ||
| 60 | 53 | 'docs_per_page' => -1, |
| 61 | 54 | 'postsOrderBy' => 'title', |
| 62 | 55 | 'postsOrder' => 'asc', |
| 63 | 56 | 'enableNestedSubcategory' => false, |
| 64 | - // Default follows the global "Lazy Load Sidebar Docs & Subcategories" | |
| 65 | - // setting, mirroring the Elementor sidebar widget's control default, so | |
| 66 | - // enabling the setting lazy-loads the block too unless overridden. | |
| 67 | - 'enableLazyLoad' => (bool) betterdocs()->settings->get( 'archive_lazy_load_descendants' ), | |
| 68 | 57 | 'docs_per_subcategory' => 10, |
| 69 | 58 | 'titleTag' => 'h1', |
| 70 | 59 | 'show_count' => false, |
| 71 | 60 | 'enableStickyTOC' => false, |
| @@ -88,10 +77,9 @@ | ||
| 88 | 77 | 3 => 5, |
| 89 | 78 | 4 => 2, |
| 90 | 79 | 5 => 3, |
| 91 | 80 | 6 => 6, |
| 92 | - 7 => 7, | |
| 93 | - 8 => 8, | |
| 81 | + 7 => 7 | |
| 94 | 82 | ]; |
| 95 | 83 | $sidebar_layout = isset( $layout_mapper[ $layout ] ) ? $layout_mapper[ $layout ] : 1; |
| 96 | 84 | |
| 97 | 85 | if ( ! betterdocs()->is_pro_active() ) { |
| @@ -131,9 +119,10 @@ | ||
| 131 | 119 | 'terms_orderby' => $settings['terms_orderby'] == 'doc_category_order' ? 'betterdocs_order' : $settings['terms_orderby'], |
| 132 | 120 | 'terms_include' => array_diff( $this->string_to_array( $settings['includeCategories'] ), $this->string_to_array( $settings['excludeCategories'] ) ), |
| 133 | 121 | 'terms_exclude' => isset( $settings['excludeCategories'] ) ? $this->string_to_array( $settings['excludeCategories'] ) : '', |
| 134 | 122 | 'nested_subcategory' => $settings['enableNestedSubcategory'], |
| 135 | - 'lazy_load' => ! empty( $settings['enableLazyLoad'] ), | |
| 123 | + 'multiple_knowledge_base' => $default_multiple_kb, | |
| 124 | + 'kb_slug' => $kb_slug, | |
| 136 | 125 | 'sidebar_list' => true, |
| 137 | 126 | 'list_icon_url' => '', |
| 138 | 127 | 'list_icon_name' => $settings['sidebar_layout'] == 'layout-4' ? '' : ( ! empty( $this->attributes['listIconImageUrl'] ) ? $this->attributes['listIconImageUrl'] : ( ! empty( $this->attributes['listIcon'] ) ? $this->attributes['listIcon'] : ( ! empty( betterdocs()->settings->get( 'docs_list_icon' ) ) ? betterdocs()->settings->get( 'docs_list_icon' )['url'] : 'list' ) ) ), |
| 139 | 128 | 'layout_type' => 'block', |
| @@ -151,17 +140,8 @@ | ||
| 151 | 140 | $default_view_params['number_of_faqs'] = $settings['initialFAQQueryNumber']; |
| 152 | 141 | $default_view_params['faq_term_ids'] = $settings['searchModalQueriesFaqGroupIds']; |
| 153 | 142 | $default_view_params['doc_ids'] = $settings['searchModalQueryDocIds']; |
| 154 | 143 | $default_view_params['doc_term_ids'] = $settings['searchModalQueryTermIds']; |
| 155 | - } | |
| 156 | - | |
| 157 | - // Pass a KB scope only when one is explicitly selected on the block. When none is | |
| 158 | - // set, omit kb_slug so the betterdocs_sidebar_template_shortcode_params filter | |
| 159 | - // (Pro/MKB) can inject the current knowledge_base context on KB templates — the | |
| 160 | - // same path the default sidebar uses. (Passing kb_slug='' would block injection.) | |
| 161 | - if ( ! empty( $kb_slug ) ) { | |
| 162 | - $default_view_params['shortcode_attr']['kb_slug'] = $kb_slug; | |
| 163 | - $default_view_params['shortcode_attr']['multiple_knowledge_base'] = (bool) $default_multiple_kb; | |
| 164 | 144 | } |
| 165 | 145 | |
| 166 | 146 | return $default_view_params; |
| 167 | 147 | } |