PluginProbe
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot / 4.9.3
BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ & Chatbot v4.9.3
4.9.3 4.9.2 4.9.1 4.9.0 4.8.2 4.8.1 4.8.0 4.7.0 4.6.2 4.6.1 4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 4.5.1 4.5.0 4.4.1 4.4.0 3.3.4 3.4.0 3.4.1 3.4.2 3.5.0 All 201 releases
← All changes | views/template-parts/category-list.php +122 -24 3.4.0 → 4.9.3 View file →
@@ -1,11 +1,16 @@
1 1 <?php
2 - use WPDeveloper\BetterDocs\Utils\Helper;
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 +use WPDeveloper\BetterDocs\Utils\Helper;
3 8
4 9 $posts = betterdocs()->query->get_posts( $query_args, true );
5 10
6 11 if ( ! $posts->have_posts() ) {
7 - wp_reset_query();
12 + wp_reset_postdata();
8 13 }
9 14
10 15 $_page_id = null;
11 16
@@ -11,34 +16,104 @@
11 16
12 17 if ( is_single() ) {
13 18 $_page_id = get_the_ID();
14 19 }
20 +
21 + // if there have list icon url from settings or customizer or shortcodes attribites format it to $list_icon_name
22 + $settings_list_icon = betterdocs()->settings->get( 'docs_list_icon' );
23 +
24 + // Ensure $layout_type is set
25 + if ( ! isset( $layout_type ) ) {
26 + $layout_type = '';
27 + }
28 +
29 + // Ensure $list_icon_url is set
30 + if ( ! isset( $list_icon_url ) ) {
31 + $list_icon_url = '';
32 + }
33 +
34 + // Ensure $list_icon_name is always initialized as an array to prevent TypeError
35 + if ( ! isset( $list_icon_name ) || ! is_array( $list_icon_name ) ) {
36 + $list_icon_name = array();
37 + }
38 +
39 + #for elementor if icon is not selected from settings, and icon attributes are empty, then look for settings, if settings is empty show default icon, else show from settings. If svg from list is selected, then show svg, else show from settings, if settings is empty then show default. Not applicable for sidebar layout-2 elementor
40 + if ( isset( $layout_type ) && 'widget' == $layout_type ) {
41 + if ( isset( $sidebar_layout ) && 'layout-2' == $sidebar_layout ) { #done to avoid warning for elementor sidebar layout-2
42 + $list_icon_name = array();
43 + }
44 +
45 + // Ensure $list_icon_name is an array before using array_key_exists
46 + if ( ! is_array( $list_icon_name ) ) {
47 + $list_icon_name = array();
48 + }
49 +
50 + $list_icon_name = ( array_key_exists( 'value', $list_icon_name ) && array_key_exists( 'library', $list_icon_name ) || array_key_exists( 'value', $list_icon_name ) ) ? ( empty( $list_icon_name[ 'value' ] ) && empty( $list_icon_name[ 'library' ] ) || empty( $list_icon_name[ 'value' ] ) ? ( isset( $settings_list_icon[ 'url' ] ) ? array( 'value' => array( 'url' => $settings_list_icon[ 'url' ] ) ) : array() ) : $list_icon_name ) : ( isset( $list_icon_name[ 'url' ] ) ? array( 'value' => array( 'url' => $list_icon_name[ 'url' ] ) ) : ( isset( $settings_list_icon[ 'url' ] ) ? $settings_list_icon[ 'url' ] : array() ) );
51 + }
52 +
53 + // #for blocks if $list_icon_name is empty, but for category grid block
54 + if ( isset( $layout_type ) && 'block' == $layout_type ) {
55 + if ( empty( $list_icon_name ) && isset( $widget_type ) && 'category-grid' == $widget_type ) {
56 + $list_icon_name = array(
57 + 'value'
58 + );
59 + }
60 + }
61 +
62 + #for blocks if $sidebar_layout is passed, then remove the list icon for layout-4
63 + if ( isset( $layout_type ) && 'block' == $layout_type ) {
64 + if ( isset( $sidebar_layout ) && 'layout-4' == $sidebar_layout ) {
65 + $list_icon_name = array(
66 + 'value' => array(
67 + 'url' => 'list'
68 + )
69 + );
70 + }
71 + }
72 +
73 + if ( isset( $layout_type ) && ! empty( $layout_type ) && 'template' == $layout_type && isset( $list_icon_url ) && $list_icon_url ) {
74 + if ( isset( $list_icon_url ) && $list_icon_url ) {
75 + $list_icon_name = array(
76 + 'value' => array(
77 + 'url' => $list_icon_url
78 + )
79 + );
80 + }
81 + }
15 82 ?>
16 83
17 84 <ul class="betterdocs-articles-list">
18 - <?php
19 - if ( $query_args['posts_per_page'] === '' ) $query_args['posts_per_page'] = get_option('posts_per_page');
85 + <?php
86 + if ( '' === $query_args[ 'posts_per_page' ] ) {
87 + $query_args[ 'posts_per_page' ] = get_option( 'posts_per_page' );
88 + }
20 89
21 - if ( $query_args['posts_per_page'] == -1 || $query_args['posts_per_page'] > 0 ) {
22 - $pos = 'left';
23 - $icon = 'list';
24 - if( ! empty ( $list_icon_position ) ) {
25 - if( $list_icon_position == 'right' ) {
90 + if ( -1 == $query_args[ 'posts_per_page' ] || $query_args[ 'posts_per_page' ] > 0 ) {
91 + $pos = 'left';
92 + $icon = 'list';
93 + $show_icon = true;
94 +
95 + // Check if list icon should be shown
96 + if ( isset( $show_list_icon ) && false === $show_list_icon ) {
97 + $show_icon = false;
98 + }
99 +
100 + if ( ! empty( $list_icon_position ) ) {
101 + if ( 'right' == $list_icon_position ) {
26 102 $pos = 'right';
27 103 }
28 104 }
29 - if( ! empty ( $list_icon_name ) ) {
105 + if ( ! empty( $list_icon_name ) ) {
30 106 $icon = $list_icon_name;
31 107 }
32 -
33 -
34 - while ( $posts->have_posts() ): $posts->the_post();
35 - $_link_attributes = [
108 + while ( $posts->have_posts() ):
109 + $posts->the_post();
110 + $_link_attributes = array(
36 111 'href' => esc_url( get_the_permalink() )
37 - ];
112 + );
38 113
39 - if ( $_page_id === get_the_ID() && Helper::get_tax() != 'doc_category' ) {
40 - $_link_attributes['class'] = 'active';
114 + if ( get_the_ID() === $_page_id && Helper::get_tax() != 'doc_category' ) {
115 + $_link_attributes[ 'class' ] = 'active';
41 116 }
42 117
43 118 $_link_attributes = betterdocs()->template_helper->get_html_attributes( $_link_attributes );
44 119
@@ -43,17 +118,31 @@
43 118 $_link_attributes = betterdocs()->template_helper->get_html_attributes( $_link_attributes );
44 119
45 120 echo wp_sprintf(
46 121 '<li>%4$s<a %1$s><span>%2$s</span> %3$s</a></li>',
47 - $_link_attributes,
48 - betterdocs()->template_helper->kses( get_the_title() ),
49 - $pos == 'right' ? betterdocs()->template_helper->icon( $icon ) : '',
50 - $pos == 'left' ? betterdocs()->template_helper->icon( $icon ) : ''
122 + $_link_attributes, // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
123 + /**
124 + * Filter a doc item's title markup in category/sidebar doc
125 + * lists (e.g. to prepend an API method badge). Deliberately
126 + * NOT core `the_title` — this must stay scoped to list items.
127 + *
128 + * SECURITY CONTRACT: the return value is echoed as HTML and
129 + * is NOT escaped afterwards — it has to be, or a callback
130 + * could not add the markup this filter exists for. The value
131 + * passed in is already kses'd; a callback that wraps or
132 + * appends to it is responsible for escaping whatever IT
133 + * introduces. Never hand this filter unsanitised user input.
134 + *
135 + * @param string $title_html Kses'd title markup.
136 + * @param int $post_id
137 + */
138 + apply_filters( 'betterdocs_docs_list_item_title', betterdocs()->template_helper->kses( get_the_title() ), get_the_ID() ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
139 + ( $show_icon && 'right' == $pos ) ? betterdocs()->template_helper->icon( $icon ) : '', // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
140 + ( $show_icon && 'left' == $pos ) ? betterdocs()->template_helper->icon( $icon ) : '' // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
51 141 );
52 142 endwhile;
53 143
54 144 wp_reset_postdata();
55 - wp_reset_query();
56 145 }
57 146 /**
58 147 * Nested Sub Categories
59 148 */
@@ -58,10 +147,19 @@
58 147 * Nested Sub Categories
59 148 */
60 149 if ( (bool) $nested_subcategory && $term instanceof \WP_Term ) {
61 150 $_params = get_defined_vars();
62 - $_params = isset( $_params['params'] ) ? $_params['params'] : [];
63 - $_params = wp_parse_args( ['term_id' => $term->term_id], $_params );
151 + $_params = isset( $_params[ 'params' ] ) ? $_params[ 'params' ] : array();
152 + $_params = wp_parse_args(
153 + array(
154 + 'term_id' => $term->term_id,
155 + 'list_icon_url' => $list_icon_url
156 + ),
157 + $_params
158 + );
159 + if ( 'widget' == $layout_type || 'block' == $layout_type ) {
160 + $_params[ 'list_icon_name' ] = $list_icon_name;
161 + }
64 162 $view_object->get( 'template-parts/nested-categories', $_params );
65 163 }
66 164 ?>
67 165 </ul>