Make WordPress Core

Ticket #55699: 55699.4.diff

File 55699.4.diff, 3.4 KB (added by SergeyBiryukov, 4 years ago)
  • src/wp-includes/class-wp-query.php

     
    27542754                        }
    27552755                }
    27562756
    2757                 $clauses = array( 'where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits' );
    2758 
    27592757                /*
    27602758                 * Apply post-paging filters on where and join. Only plugins that
    27612759                 * manipulate paging queries should use these hooks.
     
    28352833                         */
    28362834                        $fields = apply_filters_ref_array( 'posts_fields', array( $fields, &$this ) );
    28372835
     2836                        $clauses = array( 'where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits' );
     2837
    28382838                        /**
    28392839                         * Filters all query clauses at once, for convenience.
    28402840                         *
     
    29672967                         */
    29682968                        $limits = apply_filters_ref_array( 'post_limits_request', array( $limits, &$this ) );
    29692969
     2970                        $clauses = array( 'where', 'groupby', 'join', 'orderby', 'distinct', 'fields', 'limits' );
     2971
    29702972                        /**
    29712973                         * Filters all query clauses at once, for convenience.
    29722974                         *
     
    29902992                         * }
    29912993                         * @param WP_Query $query  The WP_Query instance (passed by reference).
    29922994                         */
    2993                         $clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( $clauses, &$this ) );
     2995                        $clauses = (array) apply_filters_ref_array( 'posts_clauses_request', array( compact( $clauses ), &$this ) );
    29942996
    29952997                        $where    = isset( $clauses['where'] ) ? $clauses['where'] : '';
    29962998                        $groupby  = isset( $clauses['groupby'] ) ? $clauses['groupby'] : '';
  • tests/phpunit/tests/query.php

     
    719719                $this->assertInstanceOf( 'WP_User', get_queried_object() );
    720720                $this->assertSame( get_queried_object_id(), $user_id );
    721721        }
     722
     723        /**
     724         * Tests that the `posts_clauses` filter receives an array of clauses
     725         * with the other `posts_*` filters applied, e.g. `posts_join_paged`.
     726         *
     727         * @ticket 55699
     728         * @covers WP_Query::get_posts
     729         */
     730        public function test_posts_clauses_filter_should_receive_filtered_clauses() {
     731                add_filter(
     732                        'posts_join_paged',
     733                        static function() {
     734                                return '/* posts_join_paged */';
     735                        }
     736                );
     737
     738                $filter = new MockAction();
     739                add_filter( 'posts_clauses', array( $filter, 'filter' ), 10, 2 );
     740                $this->go_to( '/' );
     741                $filter_args   = $filter->get_args();
     742                $posts_clauses = $filter_args[0][0];
     743
     744                $this->assertArrayHasKey( 'join', $posts_clauses );
     745                $this->assertSame( '/* posts_join_paged */', $posts_clauses['join'] );
     746        }
     747
     748        /**
     749         * Tests that the `posts_clauses_request` filter receives an array of clauses
     750         * with the other `posts_*_request` filters applied, e.g. `posts_join_request`.
     751         *
     752         * @ticket 55699
     753         * @covers WP_Query::get_posts
     754         */
     755        public function test_posts_clauses_request_filter_should_receive_filtered_clauses() {
     756                add_filter(
     757                        'posts_join_request',
     758                        static function() {
     759                                return '/* posts_join_request */';
     760                        }
     761                );
     762
     763                $filter = new MockAction();
     764                add_filter( 'posts_clauses_request', array( $filter, 'filter' ), 10, 2 );
     765                $this->go_to( '/' );
     766                $filter_args           = $filter->get_args();
     767                $posts_clauses_request = $filter_args[0][0];
     768
     769                $this->assertArrayHasKey( 'join', $posts_clauses_request );
     770                $this->assertSame( '/* posts_join_request */', $posts_clauses_request['join'] );
     771        }
    722772}