mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-17 16:15:24 +01:00
Query: Don't attempt caching if running a WP_User_Query before plugins_loaded.
In #55594 user meta caching was enabled by default when making a `WP_User_Query`. Previously, this was only enabled if a developer specifically queried for 'all_with_meta' fields. User meta caching is implemented using a pluggable function, `cache_users`. If a plugin runs a `WP_User_Query` before pluggable functions have been defined, this will now cause a fatal error. In this commit, a `function_exists` check is introduced to avoid calling `cache_users` if it's not defined. Additionally, a `_doing_it_wrong` notice is issued if the `WP_User_Query::query` method is called before the 'plugins_loaded' hook. Props carazo, subrataemfluence, oakesjosh, spacedmonkey, obenland, SergeyBiryukov, peterwilsoncc, TimothyBlynJacobs. Merges [54766] to the 6.1 branch. Fixes #56952. Built from https://develop.svn.wordpress.org/branches/6.1@54773 git-svn-id: http://core.svn.wordpress.org/branches/6.1@54325 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
65a6a14ed6
commit
73cd0d0c47
@ -776,6 +776,18 @@ class WP_User_Query {
|
||||
public function query() {
|
||||
global $wpdb;
|
||||
|
||||
if ( ! did_action( 'plugins_loaded' ) ) {
|
||||
_doing_it_wrong(
|
||||
'WP_User_Query::query',
|
||||
sprintf(
|
||||
/* translators: %s: plugins_loaded */
|
||||
__( 'User queries should not be run before the %s hook.' ),
|
||||
'<code>plugins_loaded</code>'
|
||||
),
|
||||
'6.1.1'
|
||||
);
|
||||
}
|
||||
|
||||
$qv =& $this->query_vars;
|
||||
|
||||
/**
|
||||
@ -840,7 +852,9 @@ class WP_User_Query {
|
||||
$result->id = $result->ID;
|
||||
}
|
||||
} elseif ( 'all_with_meta' === $qv['fields'] || 'all' === $qv['fields'] ) {
|
||||
if ( function_exists( 'cache_users' ) ) {
|
||||
cache_users( $this->results );
|
||||
}
|
||||
|
||||
$r = array();
|
||||
foreach ( $this->results as $userid ) {
|
||||
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.1.1-alpha-54772';
|
||||
$wp_version = '6.1.1-alpha-54773';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
Loading…
Reference in New Issue
Block a user