From 8e3b56fbe38e4d0feaa25790cce1921255d657cb Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Mon, 16 Jan 2017 23:23:06 +0000 Subject: [PATCH] User Query: Cast `$user_total` as an `int`. The `$user_total` member of `WP_User_Query`, and corresponding `get_total()` method, have always been documented as returning an `int`. `$user_total`, however, is populated by `$wpdb->get_var()`, which returns a string (containing an integer value). Casting the return value from `get_var()` as an `int` rectifies this discrepency. Props runciters. Fixes #39297. git-svn-id: https://develop.svn.wordpress.org/trunk@39915 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/class-wp-user-query.php | 2 +- tests/phpunit/tests/user/query.php | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wp-user-query.php b/src/wp-includes/class-wp-user-query.php index 0c3e105273..4522f7eead 100644 --- a/src/wp-includes/class-wp-user-query.php +++ b/src/wp-includes/class-wp-user-query.php @@ -612,7 +612,7 @@ class WP_User_Query { * @param string $sql The SELECT FOUND_ROWS() query for the current WP_User_Query. */ if ( isset( $qv['count_total'] ) && $qv['count_total'] ) - $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); + $this->total_users = (int) $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); if ( !$this->results ) return; diff --git a/tests/phpunit/tests/user/query.php b/tests/phpunit/tests/user/query.php index 1f1c9a8dd8..2cadc916fe 100644 --- a/tests/phpunit/tests/user/query.php +++ b/tests/phpunit/tests/user/query.php @@ -124,6 +124,16 @@ class Tests_User_Query extends WP_UnitTestCase { } } + /** + * @ticket 39297 + */ + public function test_get_total_is_int() { + $users = new WP_User_Query( array( 'blog_id' => get_current_blog_id() ) ); + $total_users = $users->get_total(); + + $this->assertSame( 13, $total_users ); + } + /** * @dataProvider orderby_should_convert_non_prefixed_keys_data */