From d06cb2443f65f58931460964d94f08f4482c6073 Mon Sep 17 00:00:00 2001 From: Andrew Nacin Date: Sat, 14 Sep 2013 23:09:59 +0000 Subject: [PATCH] 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 --- src/wp-includes/ms-functions.php | 2 +- tests/phpunit/tests/ms.php | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/ms-functions.php b/src/wp-includes/ms-functions.php index ec77ec4951..3cf7f0b09f 100644 --- a/src/wp-includes/ms-functions.php +++ b/src/wp-includes/ms-functions.php @@ -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'] ); diff --git a/tests/phpunit/tests/ms.php b/tests/phpunit/tests/ms.php index b0de1ef7b8..350adc26d9 100644 --- a/tests/phpunit/tests/ms.php +++ b/tests/phpunit/tests/ms.php @@ -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;