Ticket #42261: 42261.2.diff
File 42261.2.diff, 4.2 KB (added by , 7 years ago) |
---|
-
src/wp-includes/class-wp-query.php
1806 1806 if ( ( isset( $q['posts_per_archive_page'] ) && $q['posts_per_archive_page'] != 0 ) && ( $this->is_archive || $this->is_search ) ) { 1807 1807 $q['posts_per_page'] = $q['posts_per_archive_page']; 1808 1808 } 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 } 1809 1817 if ( ! isset( $q['nopaging'] ) ) { 1810 1818 if ( $q['posts_per_page'] == -1 ) { 1811 1819 $q['nopaging'] = true; … … 1814 1822 } 1815 1823 } 1816 1824 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 }1826 1825 $q['posts_per_page'] = (int) $q['posts_per_page']; 1827 1826 if ( $q['posts_per_page'] < -1 ) { 1828 1827 $q['posts_per_page'] = abs( $q['posts_per_page'] ); … … 2577 2576 */ 2578 2577 $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) ); 2579 2578 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 : ''; 2580 2582 /** 2581 2583 * Filters the LIMIT clause of the comments feed query before sending. 2582 2584 * … … 2585 2587 * @param string $climits The JOIN clause of the query. 2586 2588 * @param WP_Query $this The WP_Query instance (passed by reference). 2587 2589 */ 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 ) ); 2589 2591 } 2590 2592 $cgroupby = ( ! empty( $cgroupby ) ) ? 'GROUP BY ' . $cgroupby : ''; 2591 2593 $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; … … 2991 2993 $corderby = apply_filters_ref_array( 'comment_feed_orderby', array( 'comment_date_gmt DESC', &$this ) ); 2992 2994 $corderby = ( ! empty( $corderby ) ) ? 'ORDER BY ' . $corderby : ''; 2993 2995 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 : ''; 2994 2999 /** 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 ) ); 2996 3001 2997 3002 $comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits"; 2998 3003 $comments = $wpdb->get_results( $comments_request ); -
tests/phpunit/tests/query.php
57 57 } 58 58 59 59 /** 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 /** 60 97 * @ticket 26627 61 98 */ 62 99 function test_tag_queried_object() {