Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#39297 closed defect (bug) (fixed)

wrong return type in WP_User_Query::get_total()

Reported by: runciters's profile runciters Owned by: pento's profile pento
Milestone: 4.8 Priority: normal
Severity: normal Version: 3.1
Component: Users Keywords: has-patch has-unit-tests
Focuses: Cc:


As stated here:

WP_User_Query::get_total() method should return an integer value, but it returns a string value:

$total_users get its value from wpdb::get_var() which returns a string:

Attachments (2)

class-wp-user-query.php.patch (416 bytes) - added by runciters 6 years ago.
class-wp-user-query-#39297-svn-test.diff (1.2 KB) - added by runciters 6 years ago.
New patch with test

Download all attachments as: .zip

Change History (7)

#1 @runciters
6 years ago

  • Keywords has-patch added

#2 follow-up: @pento
6 years ago

  • Component changed from Database to Users
  • Keywords needs-refresh added
  • Milestone changed from Awaiting Review to 4.8
  • Version changed from 4.7 to 3.1

Thank you for the ticket and patch, @runciters!

The $total_users member is also supposed to be an int, so I think the better method would be to cast the value that $wpdb->get_var() returns as int.

If you'd like to update the patch, we can get this sorted.

6 years ago

New patch with test

#3 in reply to: ↑ 2 @runciters
6 years ago

Thank you for your reply @pento!

Here's a new updated patch (I also added a test).

#4 @pento
6 years ago

  • Keywords has-unit-tests added; needs-refresh removed
  • Owner set to pento
  • Status changed from new to assigned

#5 @pento
6 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 39915:

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.

Note: See TracTickets for help on using tickets.