Make WordPress Core


Ignore:
Timestamp:
10/03/2015 06:44:40 PM (8 years ago)
Author:
boonebgorges
Message:

Ensure that WP_User_Query vars are filled after 'pre_get_users'.

This prevents notices from being thrown when a 'pre_get_users' callback
removes required values from the list of query_vars.

For backward compatibility with previous uses of 'pre_get_users', default
values are parsed both before and after the action is fired.

Fixes #33449.

File:
1 edited

Legend:

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

    r34531 r34804  
    875875        $this->assertEquals( array( $users[2], $users[1] ), $q->results );
    876876    }
     877
     878    /**
     879     * @ticket 33449
     880     */
     881    public function test_query_vars_should_be_filled_in_after_pre_get_users() {
     882        $query_vars = array( 'blog_id', 'role', 'meta_key', 'meta_value', 'meta_compare', 'include', 'exclude', 'search', 'search_columns', 'orderby', 'order', 'offset', 'number', 'paged', 'count_total', 'fields', 'who', 'has_published_posts' );
     883
     884        add_action( 'pre_get_users', array( $this, 'filter_pre_get_users_args' ) );
     885        $q = new WP_User_Query( array_fill_keys( $query_vars, '1' ) );
     886        remove_action( 'pre_get_users', array( $this, 'filter_pre_get_users_args' ) );
     887
     888        foreach ( $query_vars as $query_var ) {
     889            $this->assertTrue( array_key_exists( $query_var, $q->query_vars ), "$query_var does not exist." );
     890        }
     891
     892    }
     893
     894    public function filter_pre_get_users_args( $q ) {
     895        foreach ( $q->query_vars as $k => $v ) {
     896            unset( $q->query_vars[ $k ] );
     897        }
     898    }
    877899}
Note: See TracChangeset for help on using the changeset viewer.