WordPress.org

Make WordPress Core


Ignore:
Timestamp:
01/16/2017 11:23:06 PM (4 years ago)
Author:
pento
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/user/query.php

    r38715 r39915  
    123123            $this->assertInstanceOf( 'WP_User', $user );
    124124        }
     125    }
     126
     127    /**
     128     * @ticket 39297
     129     */
     130    public function test_get_total_is_int() {
     131        $users = new WP_User_Query( array( 'blog_id' => get_current_blog_id() ) );
     132        $total_users = $users->get_total();
     133
     134        $this->assertSame( 13, $total_users );
    125135    }
    126136
Note: See TracChangeset for help on using the changeset viewer.