Users: Prime user meta in WP_User_Query class.

When querying 'fields' equal to 'all' using the `WP_User_Query` class, this returns an array of `WP_User` objects. A `WP_User` object requires user meta to be primed, as the user's role is stored in user meta. Ensure that all users meta is primed in a single request by calling the `cache_users` function when querying 'fields' equal to 'all'. Soft deprecate fields equal to `all_with_meta` as it now acts the same as 'fields' equal to 'all'.

Props Spacedmonkey, peterwilsoncc, mehulkaklotar, timothyblynjacobs, furi3r.
Fixes #55594.

git-svn-id: https://develop.svn.wordpress.org/trunk@53655 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Jonny Harris
2022-07-05 09:26:21 +00:00
parent b8ae106814
commit 2db7debe8a
2 changed files with 30 additions and 12 deletions

View File

@@ -155,6 +155,26 @@ class Tests_User_Query extends WP_UnitTestCase {
}
}
/**
* @ticket 55594
*/
public function test_get_all_primed_users() {
$filter = new MockAction();
add_filter( 'update_user_metadata_cache', array( $filter, 'filter' ), 10, 2 );
new WP_User_Query(
array(
'include' => self::$author_ids,
'fields' => 'all',
)
);
$args = $filter->get_args();
$last_args = end( $args );
$this->assertIsArray( $last_args[1] );
$this->assertSameSets( self::$author_ids, $last_args[1], 'Ensure that user meta is primed' );
}
/**
* @ticket 39297
*/