From b8e7bbb0f2a20037015b6212c562377cd5bbd55b Mon Sep 17 00:00:00 2001 From: Scott Taylor Date: Sun, 2 Feb 2014 07:35:54 +0000 Subject: [PATCH] Fix an error in SQL generation when `perm` is set and an array is passed for `post_status`. Adds unit test. Props oso96_2000. Fixes #25523. git-svn-id: https://develop.svn.wordpress.org/trunk@27067 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/query.php | 6 ++++-- tests/phpunit/tests/query.php | 1 - tests/phpunit/tests/query/results.php | 10 ++++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/query.php b/src/wp-includes/query.php index 417405d677..3276351f31 100644 --- a/src/wp-includes/query.php +++ b/src/wp-includes/query.php @@ -2756,8 +2756,10 @@ class WP_Query { foreach ( $statuswheres as $index => $statuswhere ) $statuswheres[$index] = "($statuswhere OR ($wpdb->posts.post_status = 'inherit' AND " . str_replace($wpdb->posts, 'p2', $statuswhere) . "))"; } - foreach ( $statuswheres as $statuswhere ) - $where .= " AND $statuswhere"; + $where_status = implode( ' OR ', $statuswheres ); + if ( ! empty( $where_status ) ) { + $where .= " AND ($where_status)"; + } } elseif ( !$this->is_singular ) { $where .= " AND ($wpdb->posts.post_status = 'publish'"; diff --git a/tests/phpunit/tests/query.php b/tests/phpunit/tests/query.php index 75c188a2df..bc16c1d7ad 100644 --- a/tests/phpunit/tests/query.php +++ b/tests/phpunit/tests/query.php @@ -76,6 +76,5 @@ class Tests_Query extends WP_UnitTestCase { $first_query->reset_postdata(); $this->assertEquals( get_the_ID(), $post_id ); } - } } \ No newline at end of file diff --git a/tests/phpunit/tests/query/results.php b/tests/phpunit/tests/query/results.php index 404aea6720..04bdf1961a 100644 --- a/tests/phpunit/tests/query/results.php +++ b/tests/phpunit/tests/query/results.php @@ -533,4 +533,14 @@ class Tests_Query_Results extends WP_UnitTestCase { $this->assertFalse( $this->q->is_month ); $this->assertFalse( $this->q->is_year ); } + + function test_perm_with_status_array() { + global $wpdb; + $this->q->query( array( 'perm' => 'readable', 'post_status' => array( 'publish', 'private' ) ) ); + $this->assertTrue( $this->q->have_posts() ); + $this->assertContains( "(({$wpdb->posts}.post_status = 'publish') OR ({$wpdb->posts}.post_author = 0 AND ({$wpdb->posts}.post_status = 'private')))", + $this->q->request + ); + $this->assertNotContains( "({$wpdb->posts}.post_status = 'publish') AND", $this->q->request ); + } }