| @@ -1,145 +1,186 @@ | ||
| 1 | 1 | <?php |
| 2 | - //var_dump($terms_query_args); | |
| 3 | - $terms = get_terms( apply_filters( 'betterdocs_base_terms_args', $terms_query_args ) ); | |
| 4 | - /** | |
| 5 | - * Base Layout Before Wrapper | |
| 6 | - */ | |
| 7 | - do_action_ref_array( 'betterdocs_base_layout_wrapper_before', [ & $terms] ); | |
| 2 | +// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound -- view template receives variables via extract(); prefixing is impractical. | |
| 3 | + | |
| 4 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 5 | + exit; | |
| 6 | +} | |
| 7 | +if ( $terms_query_args == false ) { | |
| 8 | + return; | |
| 9 | +} | |
| 10 | + $terms = get_terms( apply_filters( 'betterdocs_base_terms_args', $terms_query_args ) ); | |
| 11 | + /** | |
| 12 | + * Base Layout Before Wrapper | |
| 13 | + */ | |
| 14 | + do_action_ref_array( 'betterdocs_base_layout_wrapper_before', [ & $terms ] ); | |
| 8 | 15 | ?> |
| 9 | 16 | |
| 10 | 17 | <div |
| 11 | - <?php echo $wrapper_attr; ?>> | |
| 18 | + <?php echo $wrapper_attr; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> | |
| 12 | 19 | <?php |
| 13 | - /** | |
| 14 | - * Base Layout Before Inner Wrapper | |
| 15 | - */ | |
| 16 | - do_action_ref_array( 'betterdocs_base_layout_inner_wrapper_before', [ & $terms] ); | |
| 20 | + /** | |
| 21 | + * Base Layout Before Inner Wrapper | |
| 22 | + */ | |
| 23 | + do_action_ref_array( 'betterdocs_base_layout_inner_wrapper_before', [ & $terms ] ); | |
| 17 | 24 | ?> |
| 18 | 25 | <div |
| 19 | - <?php echo $inner_wrapper_attr; ?>> | |
| 20 | - <?php | |
| 21 | - $_defined_vars = get_defined_vars(); | |
| 22 | - $_params = isset( $_defined_vars['params'] ) ? $_defined_vars['params'] : []; | |
| 26 | + <?php echo $inner_wrapper_attr; //phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>> | |
| 27 | + <?php | |
| 28 | + $_defined_vars = get_defined_vars(); | |
| 29 | + $_params = isset( $_defined_vars['params'] ) ? $_defined_vars['params'] : []; | |
| 23 | 30 | |
| 24 | - $nested_subcategory = isset( $nested_subcategory ) ? $nested_subcategory : false; | |
| 31 | + $nested_subcategory = isset( $nested_subcategory ) ? $nested_subcategory : false; | |
| 25 | 32 | |
| 26 | - $_current_queried_object_id = null; | |
| 27 | - $_current_queried_object = get_queried_object(); | |
| 33 | + $_current_queried_object_id = null; | |
| 34 | + $_current_queried_object = get_queried_object(); | |
| 28 | 35 | |
| 29 | - if ( $_current_queried_object instanceof \WP_Post ) { | |
| 30 | - $_current_terms = get_the_terms( $_current_queried_object->ID, 'doc_category' ); | |
| 31 | - $_current_queried_object_id = isset( $_current_terms[0]->term_id ) ? $_current_terms[0]->term_id : null; | |
| 32 | - } elseif ( $_current_queried_object instanceof \WP_Term ) { | |
| 33 | - $_current_queried_object_id = $_current_queried_object->term_id; | |
| 34 | - } | |
| 36 | + if ( $_current_queried_object instanceof \WP_Post ) { | |
| 37 | + $_current_terms = get_the_terms( $_current_queried_object->ID, 'doc_category' ); | |
| 38 | + $_current_queried_object_id = isset( $_current_terms[0]->term_id ) ? $_current_terms[0]->term_id : null; | |
| 39 | + } elseif ( $_current_queried_object instanceof \WP_Term ) { | |
| 40 | + $_current_queried_object_id = $_current_queried_object->term_id; | |
| 41 | + } | |
| 35 | 42 | |
| 36 | - $ancestors = []; | |
| 43 | + $ancestors = []; | |
| 37 | 44 | |
| 38 | - if ( is_single() && ! empty( $_current_queried_object_id ) ) { | |
| 39 | - $_category_ids = wp_get_post_terms( get_the_ID(), 'doc_category', ["fields" => "ids"] ); | |
| 40 | - $ancestors = get_ancestors( $_category_ids[0], 'doc_category' ); | |
| 41 | - } | |
| 45 | + if ( is_single() && ! empty( $_current_queried_object_id ) ) { | |
| 46 | + $_category_ids = wp_get_post_terms( get_the_ID(), 'doc_category', [ 'fields' => 'ids' ] ); | |
| 47 | + $ancestors = get_ancestors( $_category_ids[0], 'doc_category' ); | |
| 48 | + } | |
| 42 | 49 | |
| 43 | - if ( ! is_wp_error( $terms ) ) { | |
| 44 | - do_action_ref_array( 'betterdocs_layout_base_loop_start', [ & $terms, &$_defined_vars] ); | |
| 50 | + if ( ! is_wp_error( $terms ) ) { | |
| 51 | + do_action_ref_array( 'betterdocs_layout_base_loop_start', [ & $terms, &$_defined_vars ] ); | |
| 45 | 52 | |
| 46 | - $_docs_query_args = [ | |
| 47 | - 'posts_per_page' => isset( $_params['posts_per_page'] ) ? $_params['posts_per_page'] : 0, | |
| 48 | - 'multiple_kb' => isset( $_params['multiple_knowledge_base'] ) ? $_params['multiple_knowledge_base'] : false, | |
| 49 | - 'kb_slug' => isset( $_params['kb_slug'] ) ? $_params['kb_slug'] : '' | |
| 50 | - ]; | |
| 53 | + $_docs_query_args = [ | |
| 54 | + 'posts_per_page' => isset( $_params['posts_per_page'] ) ? $_params['posts_per_page'] : 0, | |
| 55 | + 'multiple_kb' => isset( $_params['multiple_knowledge_base'] ) ? $_params['multiple_knowledge_base'] : false, | |
| 56 | + 'kb_slug' => isset( $_params['kb_slug'] ) ? $_params['kb_slug'] : '' | |
| 57 | + ]; | |
| 51 | 58 | |
| 52 | - $docs_query_args = ! isset( $docs_query_args ) ? $_docs_query_args : wp_parse_args( $docs_query_args, $_docs_query_args ); | |
| 59 | + $docs_query_args = ! isset( $docs_query_args ) ? $_docs_query_args : wp_parse_args( $docs_query_args, $_docs_query_args ); | |
| 53 | 60 | |
| 54 | - foreach ( $terms as $term ) { | |
| 55 | - $_counts = betterdocs()->query->get_docs_count( $term, $nested_subcategory, [ | |
| 56 | - 'multiple_knowledge_base' => isset( $_params['multiple_knowledge_base'] ) ? $_params['multiple_knowledge_base'] : false, | |
| 57 | - 'kb_slug' => isset( $_params['kb_slug'] ) ? $_params['kb_slug'] : '' | |
| 58 | - ] ); | |
| 61 | + $terms_count = count( $terms ); | |
| 62 | + $terms_number = 1; | |
| 59 | 63 | |
| 60 | - if ( $_counts <= 0 ) { | |
| 61 | - continue; | |
| 62 | - } | |
| 64 | + $_term_ids = wp_list_pluck( $terms, 'term_id' ); | |
| 65 | + if ( ! empty( $_term_ids ) ) { | |
| 66 | + update_termmeta_cache( $_term_ids ); | |
| 67 | + } | |
| 63 | 68 | |
| 64 | - if ( $widget_type == 'category-box' ) { | |
| 65 | - $_counts = [ | |
| 66 | - 'counts' => $_counts, | |
| 67 | - 'prefix' => ! empty( $count_prefix ) ? $count_prefix : '', | |
| 68 | - 'suffix' => ! empty( $count_suffix ) ? $count_suffix : '', | |
| 69 | - 'suffix_singular' => ! empty( $count_suffix_singular ) ? $count_suffix_singular : '' | |
| 70 | - ]; | |
| 71 | - } | |
| 69 | + foreach ( $terms as $term ) { | |
| 70 | + $_counts = betterdocs()->query->get_docs_count( | |
| 71 | + $term, | |
| 72 | + $nested_subcategory, | |
| 73 | + [ | |
| 74 | + 'multiple_knowledge_base' => isset( $_params['multiple_knowledge_base'] ) ? $_params['multiple_knowledge_base'] : false, | |
| 75 | + 'kb_slug' => isset( $_params['kb_slug'] ) ? $_params['kb_slug'] : '' | |
| 76 | + ] | |
| 77 | + ); | |
| 72 | 78 | |
| 73 | - $permalink = apply_filters( | |
| 74 | - 'betterdocs_term_permalink', | |
| 75 | - get_term_link( $term->term_id, $term->taxonomy ), $term, 'doc_category', $_params | |
| 76 | - ); | |
| 79 | + if ( $_counts <= 0 ) { | |
| 80 | + continue; | |
| 81 | + } | |
| 77 | 82 | |
| 78 | - $docs_query_args['term_id'] = $term->term_id; | |
| 79 | - $docs_query_args['term_slug'] = $term->slug; | |
| 80 | - $docs_query_args['nested_subcategory'] = $nested_subcategory; | |
| 83 | + if ( $widget_type == 'category-box' || ( $widget_type == 'category-grid' && $layout == 'layout-2' ) ) { | |
| 84 | + $_counts = [ | |
| 85 | + 'counts' => $_counts, | |
| 86 | + 'prefix' => ! empty( $count_prefix ) ? $count_prefix : '', | |
| 87 | + 'suffix' => ! empty( $count_suffix ) ? $count_suffix : '', | |
| 88 | + 'suffix_singular' => ! empty( $count_suffix_singular ) ? $count_suffix_singular : '' | |
| 89 | + ]; | |
| 90 | + } | |
| 81 | 91 | |
| 82 | - $_params = wp_parse_args( [ | |
| 83 | - 'permalink' => $permalink, | |
| 84 | - 'wrapper_class' => [$layout], | |
| 85 | - 'term' => $term, | |
| 86 | - 'counts' => $_counts, | |
| 87 | - 'queried_object' => $_current_queried_object, | |
| 88 | - 'current_queried_object_id' => $_current_queried_object_id, | |
| 89 | - 'ancestors' => $ancestors, | |
| 90 | - 'query_args' => betterdocs()->query->docs_query_args( $docs_query_args ) | |
| 91 | - ], $_params ); | |
| 92 | + // Count Sub Terms | |
| 93 | + $sub_terms_count = 0; | |
| 94 | + if ( isset( $_params['taxonomy'] ) && $_params['taxonomy'] == 'doc_category' ) { | |
| 95 | + $sub_terms_count = count( betterdocs()->query->get_all_child_term_ids( $_params['taxonomy'], $term->term_id ) ); | |
| 96 | + } elseif ( isset( $_params['taxonomy'] ) && $_params['taxonomy'] == 'knowledge_base' ) { | |
| 97 | + $count_doc_categories = betterdocs()->query->count_doc_categories_for_knowledge_base( $term->slug ); | |
| 98 | + $sub_terms_count = $count_doc_categories; | |
| 99 | + } | |
| 92 | 100 | |
| 93 | - $template_params = apply_filters( 'betterdocs_template_params', $_params, $layout, $term, $widget_type ); | |
| 94 | - $layout_filename = apply_filters( 'betterdocs_layout_filename', $layout, $layout, $widget_type ); | |
| 95 | 101 | |
| 96 | - betterdocs()->views->get( 'layouts/' . $widget_type . '/' . $layout_filename, $template_params ); | |
| 97 | - } | |
| 102 | + $permalink = apply_filters( | |
| 103 | + 'betterdocs_term_permalink', | |
| 104 | + get_term_link( $term->term_id, $term->taxonomy ), | |
| 105 | + $term, | |
| 106 | + 'doc_category', | |
| 107 | + $_params | |
| 108 | + ); | |
| 98 | 109 | |
| 99 | - do_action_ref_array( 'betterdocs_layout_base_loop_end', [ & $terms, &$_defined_vars] ); | |
| 100 | - } else { | |
| 101 | - betterdocs()->views->get( 'layout-parts/no-content' ); | |
| 102 | - } | |
| 110 | + $docs_query_args['term_id'] = $term->term_id; | |
| 111 | + $docs_query_args['term_slug'] = $term->slug; | |
| 112 | + $docs_query_args['nested_subcategory'] = $nested_subcategory; | |
| 103 | 113 | |
| 104 | - wp_reset_postdata(); | |
| 105 | - ?> | |
| 114 | + $_params = wp_parse_args( | |
| 115 | + [ | |
| 116 | + 'permalink' => $permalink, | |
| 117 | + 'wrapper_class' => [ $layout ], | |
| 118 | + 'term' => $term, | |
| 119 | + 'counts' => $_counts, | |
| 120 | + 'terms_count' => $terms_count, | |
| 121 | + 'terms_number' => $terms_number, | |
| 122 | + 'sub_terms_count' => $sub_terms_count, | |
| 123 | + 'queried_object' => $_current_queried_object, | |
| 124 | + 'current_queried_object_id' => $_current_queried_object_id, | |
| 125 | + 'ancestors' => $ancestors, | |
| 126 | + 'query_args' => betterdocs()->query->docs_query_args( $docs_query_args ) | |
| 127 | + ], | |
| 128 | + $_params | |
| 129 | + ); | |
| 130 | + | |
| 131 | + $template_params = apply_filters( 'betterdocs_template_params', $_params, $layout, $term, $widget_type ); | |
| 132 | + $layout_filename = apply_filters( 'betterdocs_layout_filename', $layout, $layout, $widget_type ); | |
| 133 | + $layout_filename = sanitize_file_name( $layout_filename ); | |
| 134 | + | |
| 135 | + betterdocs()->views->get( 'layouts/' . $widget_type . '/' . $layout_filename, $template_params ); | |
| 136 | + ++$terms_number; | |
| 137 | + --$terms_count; | |
| 138 | + } | |
| 139 | + | |
| 140 | + do_action_ref_array( 'betterdocs_layout_base_loop_end', [ & $terms, &$_defined_vars ] ); | |
| 141 | + } else { | |
| 142 | + betterdocs()->views->get( 'layout-parts/no-content' ); | |
| 143 | + } | |
| 144 | + | |
| 145 | + wp_reset_postdata(); | |
| 146 | + ?> | |
| 106 | 147 | </div> |
| 107 | - <?php | |
| 108 | - /** | |
| 109 | - * Base Layout After Inner Wrapper | |
| 110 | - */ | |
| 111 | - do_action_ref_array( 'betterdocs_base_layout_inner_wrapper_after', [ & $terms] ); | |
| 112 | - ?> | |
| 113 | - <div class="clearfix"></div> | |
| 114 | - <?php if ( isset( $is_edit_mode ) && $is_edit_mode && $widget_type == 'category-grid' ): ?> | |
| 115 | - <script> | |
| 116 | - /** | |
| 117 | - * TODO: Not working in Elementor Editor on first Load. | |
| 118 | - */ | |
| 119 | - jQuery(document).ready(function($) { | |
| 120 | - $('.betterdocs-category-grid').each(function() { | |
| 121 | - let $grid = $(this), | |
| 122 | - $layout_mode = $grid.data('layout-mode'), | |
| 123 | - $column = $grid.data('column'), | |
| 124 | - $column_space = $grid.data('column_space'); | |
| 125 | - if ($layout_mode === 'masonry') { | |
| 126 | - let masonryItem = $(".betterdocs-single-category-wrapper", $grid); | |
| 127 | - let total_margin = ($column - 1) * $column_space; | |
| 128 | - masonryItem.css("width", "calc((100% - " + total_margin + "px) / " + parseInt($column) + ")"); | |
| 129 | - $grid.masonry({ | |
| 130 | - itemSelector: ".betterdocs-single-category-wrapper", | |
| 131 | - percentPosition: true, | |
| 132 | - gutter: $column_space | |
| 133 | - }); | |
| 134 | - } | |
| 135 | - }); | |
| 136 | - }); | |
| 137 | - </script> | |
| 138 | - <?php endif;?> | |
| 148 | + <?php | |
| 149 | + /** | |
| 150 | + * Base Layout After Inner Wrapper | |
| 151 | + */ | |
| 152 | + do_action_ref_array( 'betterdocs_base_layout_inner_wrapper_after', [ & $terms ] ); | |
| 153 | + ?> | |
| 154 | + <div class="clearfix"></div> | |
| 155 | + <?php if ( isset( $is_edit_mode ) && $is_edit_mode && $widget_type == 'category-grid' ) : ?> | |
| 156 | + <script> | |
| 157 | + /** | |
| 158 | + * TODO: Not working in Elementor Editor on first Load. | |
| 159 | + */ | |
| 160 | + jQuery(document).ready(function($) { | |
| 161 | + $('.betterdocs-category-grid').each(function() { | |
| 162 | + let $grid = $(this), | |
| 163 | + $layout_mode = $grid.data('layout-mode'), | |
| 164 | + $column = $grid.data('column'), | |
| 165 | + $column_space = $grid.data('column_space'); | |
| 166 | + if ($layout_mode === 'masonry') { | |
| 167 | + let masonryItem = $(".betterdocs-single-category-wrapper", $grid); | |
| 168 | + let total_margin = ($column - 1) * $column_space; | |
| 169 | + masonryItem.css("width", "calc((100% - " + total_margin + "px) / " + parseInt($column) + ")"); | |
| 170 | + $grid.masonry({ | |
| 171 | + itemSelector: ".betterdocs-single-category-wrapper", | |
| 172 | + percentPosition: true, | |
| 173 | + gutter: $column_space | |
| 174 | + }); | |
| 175 | + } | |
| 176 | + }); | |
| 177 | + }); | |
| 178 | + </script> | |
| 179 | + <?php endif; ?> | |
| 139 | 180 | </div> |
| 140 | 181 | <?php |
| 141 | - /** | |
| 142 | - * Base Layout After Wrapper | |
| 143 | - */ | |
| 144 | - do_action_ref_array( 'betterdocs_base_layout_wrapper_after', [ & $terms] ); | |
| 182 | + /** | |
| 183 | + * Base Layout After Wrapper | |
| 184 | + */ | |
| 185 | + do_action_ref_array( 'betterdocs_base_layout_wrapper_after', [ & $terms ] ); | |
| 145 | 186 | ?> |