Make WordPress Core

Ticket #42261: 42261.2.diff

File 42261.2.diff, 4.2 KB (added by mauteri, 7 years ago)

Update to fix comment feed to support -1 plus unit test

  • src/wp-includes/class-wp-query.php

     
    18061806                if ( ( isset( $q['posts_per_archive_page'] ) && $q['posts_per_archive_page'] != 0 ) && ( $this->is_archive || $this->is_search ) ) {
    18071807                        $q['posts_per_page'] = $q['posts_per_archive_page'];
    18081808                }
     1809                if ( $this->is_feed ) {
     1810                        // This overrides posts_per_page.
     1811                        if ( ! empty( $q['posts_per_rss'] ) ) {
     1812                                $q['posts_per_page'] = $q['posts_per_rss'];
     1813                        } else {
     1814                                $q['posts_per_page'] = get_option( 'posts_per_rss' );
     1815                        }
     1816                }
    18091817                if ( ! isset( $q['nopaging'] ) ) {
    18101818                        if ( $q['posts_per_page'] == -1 ) {
    18111819                                $q['nopaging'] = true;
     
    18141822                        }
    18151823                }
    18161824
    1817                 if ( $this->is_feed ) {
    1818                         // This overrides posts_per_page.
    1819                         if ( ! empty( $q['posts_per_rss'] ) ) {
    1820                                 $q['posts_per_page'] = $q['posts_per_rss'];
    1821                         } else {
    1822                                 $q['posts_per_page'] = get_option( 'posts_per_rss' );
    1823                         }
    1824                         $q['nopaging'] = false;
    1825                 }
    18261825                $q['posts_per_page'] = (int) $q['posts_per_page'];
    18271826                if ( $q['posts_per_page'] < -1 ) {
    18281827                        $q['posts_per_page'] = abs( $q['posts_per_page'] );
     
    25772576                                 */
    25782577                                $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
    25792578
     2579                                // If -1 do not set LIMIT
     2580                                $posts_per_rss = intval( get_option( 'posts_per_rss' ) );
     2581                                $posts_per_rss = ( -1 !== $posts_per_rss ) ? 'LIMIT ' . $posts_per_rss : '';
    25802582                                /**
    25812583                                 * Filters the LIMIT clause of the comments feed query before sending.
    25822584                                 *
     
    25852587                                 * @param string   $climits The JOIN clause of the query.
    25862588                                 * @param WP_Query $this    The WP_Query instance (passed by reference).
    25872589                                 */
    2588                                 $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) );
     2590                                $climits = apply_filters_ref_array( 'comment_feed_limits', array( $posts_per_rss , &$this ) );
    25892591                        }
    25902592                        $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : '';
    25912593                        $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
     
    29912993                        $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) );
    29922994                        $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : '';
    29932995
     2996                        // If -1 do not set LIMIT
     2997                        $posts_per_rss = intval( get_option( 'posts_per_rss' ) );
     2998                        $posts_per_rss = ( -1 !== $posts_per_rss ) ? 'LIMIT ' . $posts_per_rss : '';
    29942999                        /** This filter is documented in wp-includes/query.php */
    2995                         $climits = apply_filters_ref_array( 'comment_feed_limits', array( 'LIMIT ' . get_option( 'posts_per_rss' ), &$this ) );
     3000                        $climits = apply_filters_ref_array( 'comment_feed_limits', array( $posts_per_rss, &$this ) );
    29963001
    29973002                        $comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
    29983003                        $comments         = $wpdb->get_results( $comments_request );
  • tests/phpunit/tests/query.php

     
    5757        }
    5858
    5959        /**
     60         * @ticket 42261
     61         */
     62        function test_rss_post_query_no_limit() {
     63                self::factory()->post->create_many( 15 );
     64
     65                // Programmatically set posts_per_rss to -1
     66                add_filter( 'option_posts_per_rss', array( $this, 'filter_option_posts_per_rss' ) );
     67
     68                $this->go_to( get_feed_link() );
     69
     70                global $wp_query;
     71
     72                $this->assertEquals( 15, count( $wp_query->posts ) );
     73        }
     74
     75        /**
     76         * @ticket 42261
     77         */
     78        function test_rss_comment_query_no_limit() {
     79                $post_id = self::factory()->post->create();
     80                self::factory()->comment->create_post_comments( $post_id, 30 );
     81
     82                // Programmatically set posts_per_rss to -1
     83                add_filter( 'option_posts_per_rss', array( $this, 'filter_option_posts_per_rss' ) );
     84
     85                $this->go_to( home_url( '/comments/feed/' ) );
     86
     87                global $wp_query;
     88
     89                $this->assertEquals( 30, count( $wp_query->comments ) );
     90        }
     91
     92        public function filter_option_posts_per_rss() {
     93                return -1;
     94        }
     95
     96        /**
    6097         * @ticket 26627
    6198         */
    6299        function test_tag_queried_object() {