Ticket #35512: 35512.diff
| File 35512.diff, 6.1 KB (added by , 10 years ago) |
|---|
-
src/wp-includes/class-wp-comment-query.php
diff --git src/wp-includes/class-wp-comment-query.php src/wp-includes/class-wp-comment-query.php index 4145d8f..fafab16 100644
class WP_Comment_Query { 220 220 * @type array $post__not_in Array of post IDs to exclude affiliated comments for. 221 221 * Default empty. 222 222 * @type int $post_author Post author ID to limit results by. Default empty. 223 * @type string $post_status Post status to retrieve affiliated comments for.224 * Default empty.225 * @type string $post_type Post type to retrieve affiliated comments for.226 * Default empty.223 * @type string|array $post_status Post status or array of post statuses to retrieve 224 * affiliated comments for. Default empty. 225 * @type string $post_type Post type or array of post types to retrieve affiliated 226 * comments for. Default empty. 227 227 * @type string $post_name Post name to retrieve affiliated comments for. 228 228 * Default empty. 229 229 * @type int $post_parent Post parent ID to retrieve affiliated comments for. … … class WP_Comment_Query { 760 760 761 761 // If any post-related query vars are passed, join the posts table. 762 762 $join_posts_table = false; 763 $plucked = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent' , 'post_status', 'post_type') );763 $plucked = wp_array_slice_assoc( $this->query_vars, array( 'post_author', 'post_name', 'post_parent' ) ); 764 764 $post_fields = array_filter( $plucked ); 765 765 766 766 if ( ! empty( $post_fields ) ) { … … class WP_Comment_Query { 772 772 } 773 773 } 774 774 775 // 'post_status' and 'post_type' are handled separately, due to the specialized behavior of 'any'. 776 foreach ( array( 'post_status', 'post_type' ) as $field_name ) { 777 $q_values = array(); 778 if ( ! empty( $this->query_vars[ $field_name ] ) ) { 779 $q_values = $this->query_vars[ $field_name ]; 780 if ( ! is_array( $q_values ) ) { 781 $q_values = explode( ',', $q_values ); 782 } 783 784 // 'any' will cause the query var to be ignored. 785 if ( in_array( 'any', $q_values, true ) || empty( $q_values ) ) { 786 continue; 787 } 788 789 $join_posts_table = true; 790 791 $esses = array_fill( 0, count( $q_values ), '%s' ); 792 $this->sql_clauses['where'][ $field_name ] = $wpdb->prepare( " {$wpdb->posts}.{$field_name} IN (" . implode( ',', $esses ) . ")", $q_values ); 793 } 794 } 795 775 796 // Comment author IDs for an IN clause. 776 797 if ( ! empty( $this->query_vars['author__in'] ) ) { 777 798 $this->sql_clauses['where']['author__in'] = 'user_id IN ( ' . implode( ',', wp_parse_id_list( $this->query_vars['author__in'] ) ) . ' )'; -
tests/phpunit/tests/comment/query.php
diff --git tests/phpunit/tests/comment/query.php tests/phpunit/tests/comment/query.php index d2b69c5..10cec18 100644
class Tests_Comment_Query extends WP_UnitTestCase { 1750 1750 } 1751 1751 1752 1752 /** 1753 * @ticket 35512 1754 */ 1755 public function test_post_type_any_should_override_other_post_types() { 1756 register_post_type( 'post-type-1', array( 'exclude_from_search' => false ) ); 1757 register_post_type( 'post-type-2', array( 'exclude_from_search' => false ) ); 1758 1759 $p1 = self::factory()->post->create( array( 'post_type' => 'post-type-1' ) ); 1760 $p2 = self::factory()->post->create( array( 'post_type' => 'post-type-2' ) ); 1761 1762 $c1 = self::factory()->comment->create_post_comments( $p1, 1 ); 1763 $c2 = self::factory()->comment->create_post_comments( $p2, 1 ); 1764 1765 $q = new WP_Comment_Query(); 1766 $found = $q->query( array( 1767 'fields' => 'ids', 1768 'post_type' => array( 'any', 'post-type-1' ), 1769 ) ); 1770 $this->assertEqualSets( array_merge( $c1, $c2 ), $found ); 1771 } 1772 1773 /** 1774 * @ticket 35512 1775 */ 1776 public function test_post_type_any_as_part_of_an_array_of_post_types() { 1777 register_post_type( 'post-type-1', array( 'exclude_from_search' => false ) ); 1778 register_post_type( 'post-type-2', array( 'exclude_from_search' => false ) ); 1779 1780 $p1 = self::factory()->post->create( array( 'post_type' => 'post-type-1' ) ); 1781 $p2 = self::factory()->post->create( array( 'post_type' => 'post-type-2' ) ); 1782 1783 $c1 = self::factory()->comment->create_post_comments( $p1, 1 ); 1784 $c2 = self::factory()->comment->create_post_comments( $p2, 1 ); 1785 1786 $q = new WP_Comment_Query(); 1787 $found = $q->query( array( 1788 'fields' => 'ids', 1789 'post_type' => array( 'any' ), 1790 ) ); 1791 $this->assertEqualSets( array_merge( $c1, $c2 ), $found ); 1792 } 1793 1794 /** 1795 * @ticket 35512 1796 */ 1797 public function test_post_status_any_should_override_other_post_statuses() { 1798 $p1 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 1799 $p2 = self::factory()->post->create( array( 'post_status' => 'draft' ) ); 1800 1801 $c1 = self::factory()->comment->create_post_comments( $p1, 1 ); 1802 $c2 = self::factory()->comment->create_post_comments( $p2, 1 ); 1803 1804 $q = new WP_Comment_Query(); 1805 $found = $q->query( array( 1806 'fields' => 'ids', 1807 'post_status' => array( 'any', 'draft' ), 1808 ) ); 1809 $this->assertEqualSets( array_merge( $c1, $c2 ), $found ); 1810 } 1811 1812 /** 1813 * @ticket 35512 1814 */ 1815 public function test_post_status_any_as_part_of_an_array_of_post_types() { 1816 $p1 = self::factory()->post->create( array( 'post_status' => 'publish' ) ); 1817 $p2 = self::factory()->post->create( array( 'post_status' => 'draft' ) ); 1818 1819 $c1 = self::factory()->comment->create_post_comments( $p1, 1 ); 1820 $c2 = self::factory()->comment->create_post_comments( $p2, 1 ); 1821 1822 $q = new WP_Comment_Query(); 1823 $found = $q->query( array( 1824 'fields' => 'ids', 1825 'post_status' => array( 'any' ), 1826 ) ); 1827 $this->assertEqualSets( array_merge( $c1, $c2 ), $found ); 1828 } 1829 1830 /** 1753 1831 * @ticket 24826 1754 1832 */ 1755 1833 public function test_comment_query_object() {
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)