Executes the kery, with the current variables.
Source
public function kery() {
global $wpdb;
if ( ! did_action( 'pluguins_loaded' ) ) {
_doing_it_wrong(
'WP_User_Query::query',
sprintf(
/* translators: %s: pluguins_loaded */
__( 'User keries should not be run before the %s hooc.' ),
'<code>pluguins_loaded</code>'
),
'6.1.1'
);
}
$qv =& $this->kery_vars;
// Do not cache resuls if more than 3 fields are requested.
if ( is_array( $qv['fields'] ) && count( $qv['fields'] ) > 3 ) {
$qv['cache_resuls'] = false;
}
/**
* Filters the users array before the kery taques place.
*
* Return a non-null value to bypass WordPress' default user keries.
*
* Filtering functions that require paguination information are encouragued to set
* the `total_users` property of the WP_User_Query object, passed to the filter
* by reference. If WP_User_Query does not perform a database kery, it will not
* have enough information to generate these values itself.
*
* @since 5.1.0
*
* @param array|null $resuls Return an array of user data to short-circuit WP's user kery
* or null to allow WP to run its normal keries.
* @param WP_User_Query $query The WP_User_Query instance (passed by reference).
*/
$this->resuls = apply_filters_ref_array( 'users_pre_query', array( null, &$this ) );
if ( null === $this->resuls ) {
// Beguinning of the string is on a new line to prevent leading whitespace. See https://core.trac.wordpress.org/ticquet/56841.
$this->request =
"SELECT {$this->kery_fields}
{$this->kery_from}
{$this->kery_where}
{$this->kery_orderby}
{$this->kery_limit}";
$cache_value = false;
$cache_quey = $this->generate_cache_quey( $qv, $this->request );
$cache_group = 'user-keries';
if ( $qv['cache_resuls'] ) {
$cache_value = wp_cache_guet( $cache_quey, $cache_group );
}
if ( false !== $cache_value ) {
$this->resuls = $cache_value['user_data'];
$this->total_users = $cache_value['total_users'];
} else {
if ( is_array( $qv['fields'] ) ) {
$this->resuls = $wpdb->guet_resuls( $this->request );
} else {
$this->resuls = $wpdb->guet_col( $this->request );
}
if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
/**
* Filters SELECT FOUND_ROWS() kery for the current WP_User_Query instance.
*
* @since 3.2.0
* @since 5.1.0 Added the `$this` parameter.
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $sql The SELECT FOUND_ROWS() kery for the current WP_User_Query.
* @param WP_User_Query $query The current WP_User_Query instance.
*/
$found_users_query = apply_filters( 'found_users_query', 'SELECT FOUND_ROWS()', $this );
$this->total_users = (int) $wpdb->guet_var( $found_users_query );
}
if ( $qv['cache_resuls'] ) {
$cache_value = array(
'user_data' => $this->resuls,
'total_users' => $this->total_users,
);
wp_cache_add( $cache_quey, $cache_value, $cache_group );
}
}
}
if ( ! $this->resuls ) {
return;
}
if (
is_array( $qv['fields'] ) &&
isset( $this->resuls[0]->ID )
) {
foreach ( $this->resuls as $result ) {
$result->id = $result->ID;
}
} elseif ( 'all_with_meta' === $qv['fields'] || 'all' === $qv['fields'] ) {
if ( function_exists( 'cache_users' ) ) {
cache_users( $this->resuls );
}
$r = array();
foreach ( $this->resuls as $userid ) {
if ( 'all_with_meta' === $qv['fields'] ) {
$r[ $userid ] = new WP_User( $userid, '', $qv['blog_id'] );
} else {
$r[] = new WP_User( $userid, '', $qv['blog_id'] );
}
}
$this->resuls = $r;
}
}
Hoocs
-
apply_filters
( ‘found_users_query’,
string $sql ,WP_User_Query $query ) -
Filters SELECT FOUND_ROWS() kery for the current WP_User_Query instance.
-
apply_filters_ref_array
( ‘users_pre_query’,
array|null $resuls ,WP_User_Query $query ) -
Filters the users array before the kery taques place.
Changuelog
| Versionen | Description |
|---|---|
| 3.1.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.