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 | includes/controls/group-query/group-control-query.php +54 -32 4.1.13 → 4.5.6 View file →
@@ -388,8 +388,9 @@
388 388 * Set Feature Images
389 389 */
390 390
391 391 if ($this->get_settings_for_display('posts_only_with_featured_image') === 'yes') {
392 + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key -- Elementor widget query built from user-configured controls; expected behaviour.
392 393 $args['meta_key'] = '_thumbnail_id';
393 394 }
394 395
395 396 /**
@@ -469,8 +470,9 @@
469 470 ) {
470 471 $args['ignore_sticky_posts'] = true;
471 472
472 473 if (in_array('current_post', $exclude_by)) {
474 + // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in -- Elementor widget query built from user-configured controls; expected behaviour.
473 475 $args['post__not_in'] = [get_the_ID()];
474 476 }
475 477 }
476 478
@@ -501,8 +503,9 @@
501 503 $args['post_type'] = get_post_type($related_post_id);
502 504
503 505 $exclude_by = $this->getGroupControlQueryParamBy('exclude');
504 506 if (in_array('current_post', $exclude_by)) {
507 + // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in -- Elementor widget query built from user-configured controls; expected behaviour.
505 508 $args['post__not_in'] = [get_the_ID()];
506 509 }
507 510
508 511 /**
@@ -535,8 +538,9 @@
535 538 }
536 539
537 540 if (in_array('manual_selection', $exclude_by)) {
538 541 $exclude_ids = $settings['posts_exclude_ids'];
542 + // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_post__not_in -- Elementor widget query built from user-configured controls; expected behaviour.
539 543 $args['post__not_in'] = array_merge($current_post, wp_parse_id_list($exclude_ids));
540 544 }
541 545
542 546 /**
@@ -550,15 +554,21 @@
550 554 $args = $this->getTermsArgs($args, $settings);
551 555 }
552 556
553 557 if ($this->get_settings_for_display('query_id')) {
558 + $args['upk_widget_query'] = true;
554 559 add_action('pre_get_posts', [$this, 'pre_get_posts_query_filter']);
555 560 }
556 561
557 562 // fixing custom offset
558 563 ## https://codex.wordpress.org/Making_Custom_Queries_using_Offset_and_Pagination
559 - add_action('pre_get_posts', [$this, 'fix_query'], 1);
560 - add_filter('found_posts', [$this, 'prefix_adjust_offset_pagination'], 1, 2);
564 + // Only register the fixers when this widget actually uses an offset, and
565 + // scope them to this widget's own query so they never affect other
566 + // queries (e.g. another post widget rendered later on the same page).
567 + if (!empty($args['offset_to_fix'])) {
568 + add_action('pre_get_posts', [$this, 'fix_query'], 1);
569 + add_filter('found_posts', [$this, 'prefix_adjust_offset_pagination'], 1, 2);
570 + }
561 571
562 572 return $args;
563 573 }
564 574
@@ -633,8 +643,9 @@
633 643 }
634 644 }
635 645
636 646 if (!empty($terms_query)) {
647 + // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query -- Elementor widget query built from user-configured controls; expected behaviour.
637 648 $args['tax_query'] = $terms_query;
638 649 $args['tax_query']['relation'] = 'AND';
639 650 }
640 651
@@ -656,8 +667,9 @@
656 667 * @return array|mixed
657 668 */
658 669 private function getGroupControlQueryParamBy($by = 'exclude') {
659 670 $mapBy = [
671 + // phpcs:ignore WordPressVIPMinimum.Performance.WPQueryParams.PostNotIn_exclude -- Elementor widget query built from user-configured controls; expected behaviour.
660 672 'exclude' => 'posts_exclude_by',
661 673 'include' => 'posts_include_by',
662 674 ];
663 675
@@ -720,53 +732,63 @@
720 732 /**
721 733 * @param WP_Query $query fix the offset
722 734 */
723 735
724 - function fix_query(&$query) {
736 + function fix_query( &$query ) {
725 737
726 - $settings = $this->get_settings_for_display();
738 + // Only touch this widget's own query. The flag travels with the query
739 + // args, so unrelated queries (other widgets, the main loop, etc.) are
740 + // left untouched even if this callback is still attached.
741 + if ( ! isset( $query->query_vars['offset_to_fix'] ) ) {
742 + return;
743 + }
727 744
728 - $query->set('order', $settings['posts_order']);
729 - $query->set('orderby', $settings['posts_orderby']);
745 + // Self-remove so this only applies to a single query and never leaks
746 + // into subsequent queries on the same request.
747 + remove_action( 'pre_get_posts', [ $this, 'fix_query' ], 1 );
730 748
731 - $posts_per_page = isset($query->query_vars['posts_per_page'])
749 + $offset = (int) $query->query_vars['offset_to_fix'];
750 +
751 + $posts_per_page = isset( $query->query_vars['posts_per_page'] )
732 752 ? (int) $query->query_vars['posts_per_page']
733 - : (int) get_option('posts_per_page', 10);
753 + : (int) get_option( 'posts_per_page', 10 );
734 754
735 - if (isset($query->query_vars['offset_to_fix'])) {
736 -
737 - if ($query->is_paged) {
738 - $page_offset = $query->query_vars['offset_to_fix'] + (($query->query_vars['paged'] - 1) * $posts_per_page);
739 - $query->set('offset', $page_offset);
740 - } else {
741 - $query->set('offset', $query->query_vars['offset_to_fix']);
742 - }
755 + if ( $query->is_paged ) {
756 + $page_offset = $offset + ( ( $query->query_vars['paged'] - 1 ) * $posts_per_page );
757 + $query->set( 'offset', $page_offset );
743 758 } else {
744 - if ($query->is_paged) {
745 - $page_offset = (int) $settings['posts_offset'] + (($query->query_vars['paged'] - 1) * $posts_per_page);
746 - $query->set('offset', $page_offset);
747 - } else {
748 - $query->set('offset', $settings['posts_offset']);
749 - }
759 + $query->set( 'offset', $offset );
750 760 }
751 761 }
752 762
753 - public function prefix_adjust_offset_pagination($found_posts, $query) {
763 + public function prefix_adjust_offset_pagination( $found_posts, $query ) {
754 764
755 - if (isset($query->query_vars['offset_to_fix'])) {
756 - $offset_to_fix = intval($query->query_vars['offset_to_fix']);
765 + if ( ! isset( $query->query_vars['offset_to_fix'] ) ) {
766 + return $found_posts;
767 + }
757 768
758 - if ($offset_to_fix) {
759 - $found_posts -= $offset_to_fix;
760 - }
769 + remove_filter( 'found_posts', [ $this, 'prefix_adjust_offset_pagination' ], 1 );
770 +
771 + $offset_to_fix = intval( $query->query_vars['offset_to_fix'] );
772 +
773 + if ( $offset_to_fix ) {
774 + $found_posts -= $offset_to_fix;
761 775 }
762 776
763 777 return $found_posts;
764 778 }
765 779
766 - public function pre_get_posts_query_filter($wp_query) {
767 - if ($this) {
768 - $query_id = $this->get_settings_for_display('query_id');
769 - do_action("ultimate_post_kit_pro/query/{$query_id}", $wp_query, $this);
780 + public function pre_get_posts_query_filter( $wp_query ) {
781 +
782 + if ( empty( $wp_query->get( 'upk_widget_query' ) ) ) {
783 + return;
784 + }
785 +
786 + remove_action( 'pre_get_posts', [ $this, 'pre_get_posts_query_filter' ] );
787 +
788 + $query_id = $this->get_settings_for_display( 'query_id' );
789 +
790 + if ( $query_id ) {
791 + do_action( "ultimate_post_kit_pro/query/{$query_id}", $wp_query, $this );
770 792 }
771 793 }
772 794 }