WordPress.org

Make WordPress Core

Changeset 39915


Ignore:
Timestamp:
01/16/17 23:23:06 (3 months 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.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-user-query.php

    r38768 r39915  
    613613         */ 
    614614        if ( isset( $qv['count_total'] ) && $qv['count_total'] ) 
    615             $this->total_users = $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); 
     615            $this->total_users = (int) $wpdb->get_var( apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()' ) ); 
    616616 
    617617        if ( !$this->results ) 
  • 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.