| @@ -140,8 +140,9 @@ | ||
| 140 | 140 | $this->add_group_control( |
| 141 | 141 | Group_Control_Image_Size::get_type(), |
| 142 | 142 | [ |
| 143 | 143 | 'name' => 'primary_thumbnail', |
| 144 | + // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Elementor widget query built from user-configured controls; expected behaviour. | |
| 144 | 145 | 'exclude' => ['custom'], |
| 145 | 146 | 'default' => 'medium', |
| 146 | 147 | ] |
| 147 | 148 | ); |
| @@ -192,8 +193,11 @@ | ||
| 192 | 193 | ], |
| 193 | 194 | 'default' => [ |
| 194 | 195 | 'size' => 3, |
| 195 | 196 | ], |
| 197 | + 'condition' => [ | |
| 198 | + 'posts_source!' => 'current_query', | |
| 199 | + ] | |
| 196 | 200 | ] |
| 197 | 201 | ); |
| 198 | 202 | |
| 199 | 203 | $this->register_query_builder_controls(); |
| @@ -747,21 +751,33 @@ | ||
| 747 | 751 | $this->register_ajax_loadmore_style_controls(); |
| 748 | 752 | } |
| 749 | 753 | |
| 750 | 754 | /** |
| 751 | - * Main query render for this widget | |
| 752 | - * @param $posts_per_page number item query limit | |
| 755 | + * Get post query builder arguments | |
| 753 | 756 | */ |
| 754 | - public function query_posts($posts_per_page) { | |
| 757 | + public function query_posts( $posts_per_page ) { | |
| 758 | + $settings = $this->get_settings(); | |
| 759 | + $posts_per_page = isset( $posts_per_page ) ? (int) $posts_per_page : 0; | |
| 760 | + $args = $this->getGroupControlQueryArgs(); | |
| 761 | + $is_current_query = ( ! empty( $settings['posts_source'] ) && $settings['posts_source'] === 'current_query' ); | |
| 755 | 762 | |
| 756 | - $default = $this->getGroupControlQueryArgs(); | |
| 757 | - $args = []; | |
| 758 | - if ($posts_per_page) { | |
| 763 | + if ( $is_current_query ) { | |
| 764 | + unset( $args['offset'] ); | |
| 765 | + unset( $args['no_found_rows'] ); | |
| 766 | + $posts_per_page = 0; | |
| 767 | + } | |
| 768 | + | |
| 769 | + if ( $posts_per_page > 0 ) { | |
| 759 | 770 | $args['posts_per_page'] = $posts_per_page; |
| 760 | - $args['paged'] = max(1, get_query_var('paged'), get_query_var('page')); | |
| 771 | + } else { | |
| 772 | + $args['posts_per_page'] = (int) get_option( 'posts_per_page', 10 ); | |
| 761 | 773 | } |
| 762 | - $args = array_merge($default, $args); | |
| 763 | - $this->_query = new WP_Query($args); | |
| 774 | + | |
| 775 | + if ( $settings['show_pagination'] ) { | |
| 776 | + $args['paged'] = max( 1, (int) get_query_var( 'paged' ), (int) get_query_var( 'page' ) ); | |
| 777 | + } | |
| 778 | + | |
| 779 | + $this->_query = new \WP_Query( $args ); | |
| 764 | 780 | } |
| 765 | 781 | |
| 766 | 782 | public function render_image($image_id, $size) { |
| 767 | 783 | $placeholder_image_src = Utils::get_placeholder_image_src(); |
| @@ -775,9 +791,9 @@ | ||
| 775 | 791 | } |
| 776 | 792 | |
| 777 | 793 | ?> |
| 778 | 794 | <a class="upk-image-wrap" href="<?php echo esc_url(get_permalink()) ?>"> |
| 779 | - <img src="<?php echo esc_url($image_src); ?>" alt="<?php echo esc_html(get_the_title()); ?>"> | |
| 795 | + <img src="<?php echo esc_url($image_src); ?>" alt="<?php echo esc_attr(get_the_title()); ?>"> | |
| 780 | 796 | <span class="upk-img-overlay"></span> |
| 781 | 797 | </a> |
| 782 | 798 | <?php |
| 783 | 799 | } |
| @@ -801,13 +817,12 @@ | ||
| 801 | 817 | |
| 802 | 818 | if (!$this->get_settings('show_comments')) { |
| 803 | 819 | return; |
| 804 | 820 | } |
| 805 | - ?> | |
| 821 | + ?> | |
| 806 | 822 | |
| 807 | 823 | <div class="upk-scott-comments"> |
| 808 | - <?php echo get_comments_number($id) ?> | |
| 809 | - <?php echo esc_html_x('Comments', 'Frontend', 'ultimate-post-kit') ?> | |
| 824 | + <?php echo esc_html( $this->upk_get_formatted_comments_count( $id ) ); ?> | |
| 810 | 825 | </div> |
| 811 | 826 | |
| 812 | 827 | <?php |
| 813 | 828 | } |
| @@ -831,15 +846,15 @@ | ||
| 831 | 846 | <div class="upk-meta upk-flex upk-flex-middle"> |
| 832 | 847 | <?php $this->render_author(); ?> |
| 833 | 848 | |
| 834 | 849 | <?php if ($settings['show_date'] == 'yes') : ?> |
| 835 | - <div data-separator="<?php echo esc_html($settings['meta_separator']); ?>"> | |
| 850 | + <div data-separator="<?php echo esc_attr($settings['meta_separator']); ?>"> | |
| 836 | 851 | <?php $this->render_date(); ?> |
| 837 | 852 | </div> |
| 838 | 853 | <?php endif; ?> |
| 839 | 854 | |
| 840 | 855 | <?php if ($settings['show_comments']) : ?> |
| 841 | - <div data-separator="<?php echo esc_html($settings['meta_separator']); ?>"> | |
| 856 | + <div data-separator="<?php echo esc_attr($settings['meta_separator']); ?>"> | |
| 842 | 857 | <?php $this->render_comments($post_id); ?> |
| 843 | 858 | </div> |
| 844 | 859 | <?php endif; ?> |
| 845 | 860 | |
| @@ -844,9 +859,9 @@ | ||
| 844 | 859 | <?php endif; ?> |
| 845 | 860 | |
| 846 | 861 | <?php if (_is_upk_pro_activated()) : |
| 847 | 862 | if ('yes' === $settings['show_reading_time']) : ?> |
| 848 | - <div class="upk-reading-time" data-separator="<?php echo esc_html($settings['meta_separator']); ?>"> | |
| 863 | + <div class="upk-reading-time" data-separator="<?php echo esc_attr($settings['meta_separator']); ?>"> | |
| 849 | 864 | <?php echo esc_html( ultimate_post_kit_reading_time( get_the_content(), $settings['avg_reading_speed'], $settings['hide_seconds'] ?? 'no', $settings['hide_minutes'] ?? 'no' ) ); ?> |
| 850 | 865 | </div> |
| 851 | 866 | <?php endif; ?> |
| 852 | 867 | <?php endif; ?> |