PluginProbe
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets / 4.5.6
Ultimate Post Kit – Elementor Post Grid, Post Carousel, Post Slider & Blog Layout Widgets v4.5.6
4.5.6 4.5.5 4.5.4 4.2.1 4.2.2 4.2.3 4.5.0 4.5.2 4.5.3 4.2.0 4.1.18 4.1.17 4.1.16 4.1.15 4.1.14 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.0.9 4.1.0 4.1.1 4.1.2 All 148 releases
← All changes | modules/post-category/widgets/post-category.php +54 -11 4.1.2 → 4.5.6 View file →
@@ -173,8 +173,9 @@
173 173 $this->add_group_control(
174 174 Group_Control_Image_Size::get_type(),
175 175 [
176 176 'name' => 'cat_image_size',
177 + // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Elementor widget query built from user-configured controls; expected behaviour.
177 178 'exclude' => [ 'custom' ],
178 179 'include' => [],
179 180 'default' => 'thumbnail',
180 181 'condition' => [
@@ -242,8 +243,11 @@
242 243 ],
243 244 'default' => [
244 245 'size' => 6,
245 246 ],
247 + 'condition' => [
248 + 'posts_source!' => 'current_query',
249 + ]
246 250 ]
247 251 );
248 252
249 253 $this->add_control(
@@ -262,18 +266,36 @@
262 266 'label' => esc_html__( 'Order By', 'ultimate-post-kit' ),
263 267 'type' => Controls_Manager::SELECT,
264 268 'default' => 'name',
265 269 'options' => [
266 - 'name' => esc_html__( 'Name', 'ultimate-post-kit' ),
267 - 'post_date' => esc_html__( 'Date', 'ultimate-post-kit' ),
268 - 'post_title' => esc_html__( 'Title', 'ultimate-post-kit' ),
269 - 'menu_order' => esc_html__( 'Menu Order', 'ultimate-post-kit' ),
270 - 'rand' => esc_html__( 'Random', 'ultimate-post-kit' ),
270 + 'name' => esc_html__( 'Name', 'ultimate-post-kit' ),
271 + 'term_id' => esc_html__( 'ID', 'ultimate-post-kit' ),
272 + 'slug' => esc_html__( 'Slug', 'ultimate-post-kit' ),
273 + 'count' => esc_html__( 'Post Count', 'ultimate-post-kit' ),
274 + 'description' => esc_html__( 'Description', 'ultimate-post-kit' ),
275 + 'parent' => esc_html__( 'Parent', 'ultimate-post-kit' ),
276 + 'term_order' => esc_html__( 'Menu Order', 'ultimate-post-kit' ),
277 + 'rand' => esc_html__( 'Random', 'ultimate-post-kit' ),
271 278 ],
272 279 ]
273 280 );
274 281
275 282 $this->add_control(
283 + 'minimum_post_count',
284 + [
285 + 'label' => esc_html__( 'Minimum Post Count', 'ultimate-post-kit' ) .BDTUPK_NC,
286 + 'type' => Controls_Manager::NUMBER,
287 + 'default' => 0,
288 + 'min' => 0,
289 + 'placeholder' => '0',
290 + 'condition' => [
291 + 'orderby' => 'count',
292 + ],
293 + 'description' => esc_html__( 'Hide categories that have fewer than this many posts. 0 = show all.', 'ultimate-post-kit' ),
294 + ]
295 + );
296 +
297 + $this->add_control(
276 298 'order',
277 299 [
278 300 'label' => esc_html__( 'Order', 'ultimate-post-kit' ),
279 301 'type' => Controls_Manager::SELECT,
@@ -805,19 +827,35 @@
805 827
806 828 public function render() {
807 829 $settings = $this->get_settings_for_display();
808 830 $image_settings = ultimate_post_kit_option( 'category_image', 'ultimate_post_kit_other_settings', 'off' );
831 + $taxonomy = ! empty( $settings['taxonomy'] ) ? $settings['taxonomy'] : 'category';
832 + $taxonomy_object = get_taxonomy( $taxonomy );
833 + $taxonomy_label = $taxonomy_object ? $taxonomy_object->labels->name : ucwords( str_replace( [ '-', '_' ], ' ', $taxonomy ) );
834 + $orderby = $settings['orderby'];
809 835 $categories = get_categories(
810 836 [
811 - 'taxonomy' => $settings["taxonomy"],
812 - 'orderby' => $settings["orderby"],
837 + 'taxonomy' => $taxonomy,
838 + 'orderby' => $orderby === 'rand' ? 'name' : $orderby,
813 839 'order' => $settings["order"],
814 840 'hide_empty' => 0,
841 + // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Elementor widget query built from user-configured controls; expected behaviour.
815 842 'exclude' => explode( ',', esc_attr( $settings["exclude"] ) ),
816 843 'parent' => $settings["parent"],
817 844 ]
818 845 );
846 + if ( $orderby === 'rand' && ! empty( $categories ) ) {
847 + shuffle( $categories );
848 + }
819 849
850 + $min_post_count = isset( $settings['minimum_post_count'] ) ? (int) $settings['minimum_post_count'] : 0;
851 + if ( $min_post_count > 0 ) {
852 + $categories = array_values( array_filter( $categories, function ( $cat ) use ( $min_post_count ) {
853 + $count = isset( $cat->count ) ? (int) $cat->count : ( isset( $cat->category_count ) ? (int) $cat->category_count : 0 );
854 + return $count >= $min_post_count;
855 + } ) );
856 + }
857 +
820 858 $this->add_render_attribute( 'category-container', 'class', 'upk-post-category' );
821 859 $this->add_render_attribute( 'category-container', 'class', 'upk-category-style-' . $settings['style'] );
822 860
823 861 if ( $settings['view_all_button'] == 'yes' ) {
@@ -834,9 +872,10 @@
834 872 $multiple_bg = explode( ',', rtrim( $multi_bg, ',' ) );
835 873 $total_category = count( $categories );
836 874
837 875 // re-creating array for the multiple colors
838 - $jCount = count( $multiple_bg );
876 + $multiple_bg_create = [];
877 + $jCount = count( $multiple_bg );
839 878 $j = 0;
840 879 for ( $i = 0; $i < $total_category; $i++ ) {
841 880 if ( $j == $jCount ) {
842 881 $j = 0;
@@ -857,9 +896,9 @@
857 896 $category_image_id = get_term_meta( $cat->cat_ID, 'upk-category-image-id', true );
858 897
859 898 if ( ! empty( $category_image_id ) ) {
860 899 $category_url = wp_get_attachment_image_url( $category_image_id, $settings['cat_image_size_size'] );
861 - $category_image = '<div class="upk-category-image"><img src="' . $category_url . '" alt=""></div>';
900 + $category_image = '<div class="upk-category-image"><img src="' . esc_url( $category_url ) . '" alt="' . esc_attr( $cat->cat_name ) . '"></div>';
862 901 } else {
863 902 $category_image = '';
864 903 }
865 904 //===============================
@@ -888,9 +927,9 @@
888 927 </span>
889 928
890 929 <?php if ( ! empty( $cat->category_description ) and $settings['show_text'] == 'yes' ) : ?>
891 930 <span class="upk-category-text">
892 - <?php echo wp_trim_words( $cat->category_description, $settings['text_length'] ); ?>
931 + <?php echo esc_html( wp_trim_words( $cat->category_description, $settings['text_length'] ) ); ?>
893 932 </span>
894 933 <?php endif; ?>
895 934
896 935 <?php if ( $settings['show_count'] == 'yes' ) : ?>
@@ -922,9 +961,13 @@
922 961 </div>
923 962 <?php
924 963 else :
925 964
926 - echo '<div class="upk-alert">' . esc_html__( 'Category Not Found!', 'ultimate-post-kit' ) . '</div>';
965 + echo '<div class="upk-alert">' . esc_html( sprintf(
966 + /* translators: %s: taxonomy label */
967 + __( '%s Categories Not Found!', 'ultimate-post-kit' ),
968 + $taxonomy_label
969 + ) ) . '</div>';
927 970
928 971 endif;
929 972 }
930 973 }