Proper treatment of the 'archived' field in wp_get_sites(). see #14511.

git-svn-id: https://develop.svn.wordpress.org/trunk@25446 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2013-09-14 23:09:59 +00:00
parent eb2e3536a9
commit d06cb2443f
2 changed files with 19 additions and 1 deletions

View File

@ -2041,7 +2041,7 @@ function wp_get_sites( $args = array() ) {
$query .= $wpdb->prepare( "AND public = %d ", $args['public'] );
if ( isset( $args['archived'] ) )
$query .= $wpdb->prepare( "AND archived = %d ", $args['archived'] );
$query .= $wpdb->prepare( "AND archived = %s ", (int) $args['archived'] ); // ENUM field
if ( isset( $args['mature'] ) )
$query .= $wpdb->prepare( "AND mature = %d ", $args['mature'] );

View File

@ -1068,6 +1068,24 @@ class Tests_MS extends WP_UnitTestCase {
$this->assertCount( 3, wp_get_sites( array( 'network_id' => 3, 'public' => 0 ) ) );
}
/**
* Test the 'archived' argument for wp_get_sites().
*
* archived is an ENUM, not an integer field.
* ENUM('0', '1') means '0' is index 1 and '1' is index 2.
* `WHERE archived = 1` is like saying `WHERE archived = '0'`.
* `WHERE archived = 0` would produce no results.
*
* @ticket 14511
*/
function test_wp_get_sites_archived_enum() {
global $wpdb;
$id = $this->factory->blog->create( array( 'site_id' => 2, 'meta' => array( 'archived' => '1' ) ) );
$this->factory->blog->create( array( 'site_id' => 2, 'meta' => array( 'archived' => '0' ) ) );
$results = wp_get_sites( array( 'network_id' => 2, 'archived' => 1 ) );
$this->assertCount( 1, $results );
$this->assertEquals( $id, $results[0]['blog_id'], "This query is wrong:\n" . $wpdb->last_query );
}
}
endif;