本文整理汇总了PHP中update_user_caches函数的典型用法代码示例。如果您正苦于以下问题:PHP update_user_caches函数的具体用法?PHP update_user_caches怎么用?PHP update_user_caches使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了update_user_caches函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_should_store_raw_data_in_users_bucket_when_passed_a_wp_user_object
/**
* @ticket 24635
*/
public function test_should_store_raw_data_in_users_bucket_when_passed_a_wp_user_object()
{
global $wpdb;
$u = self::factory()->user->create();
$raw_userdata = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE ID = %d", $u));
$user_object = new WP_User($u);
update_user_caches($user_object);
$cached = wp_cache_get($u, 'users');
$this->assertFalse($cached instanceof WP_User);
$this->assertEquals($raw_userdata, $cached);
}
示例2: set_current_user
public function set_current_user()
{
if (!is_user_logged_in()) {
return;
}
global $current_user, $user_identity;
$old = $current_user->display_name;
$current_user->display_name = $this->get_display_name($current_user->ID, $current_user->display_name);
$user_identity = $current_user->display_name;
if ($old != $user_identity) {
update_user_caches($current_user);
}
}
示例3: forge
public static function forge($user = null, $cache = true)
{
global $wpdb;
empty($user) and $user = get_current_user_id();
if (!$cache and is_numeric($user)) {
if (!($user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE ID = %s", $user)))) {
return false;
}
update_user_caches($user);
}
if (empty($user)) {
return false;
}
return new static($user);
}
示例4: _fill_single_user
/**
* Unserialize user metadata, fill $user object, then cache everything.
*
* @since 3.0.0
* @param object $user The User object.
* @param array $metavalues An array of objects provided by get_user_metavalues()
*/
function _fill_single_user(&$user, &$metavalues)
{
global $wpdb;
foreach ($metavalues as $meta) {
$value = maybe_unserialize($meta->meta_value);
// Keys used as object vars cannot have dashes.
$key = str_replace('-', '', $meta->meta_key);
$user->{$key} = $value;
}
$level = $wpdb->prefix . 'user_level';
if (isset($user->{$level})) {
$user->user_level = $user->{$level};
}
// For backwards compat.
if (isset($user->first_name)) {
$user->user_firstname = $user->first_name;
}
if (isset($user->last_name)) {
$user->user_lastname = $user->last_name;
}
if (isset($user->description)) {
$user->user_description = $user->description;
}
update_user_caches($user);
}
示例5: cache_users
/**
* Retrieve info for user lists to prevent multiple queries by get_userdata()
*
* @since 3.0.0
*
* @param array $user_ids User ID numbers list
*/
function cache_users($user_ids)
{
global $wpdb;
$clean = _get_non_cached_ids($user_ids, 'users');
if (empty($clean)) {
return;
}
$list = implode(',', $clean);
$users = $wpdb->get_results("SELECT * FROM {$wpdb->users} WHERE ID IN ({$list})");
$ids = array();
foreach ($users as $user) {
update_user_caches($user);
$ids[] = $user->ID;
}
update_meta_cache('user', $ids);
}
示例6: get_data_by
/**
* Return only the main user fields
*
* @since 3.3.0
*
* @param string $field The field to query against: 'id', 'slug', 'email' or 'login'
* @param string|int $value The field value
* @return object Raw user object
*/
static function get_data_by($field, $value)
{
global $wpdb;
if ('id' == $field) {
// Make sure the value is numeric to avoid casting objects, for example,
// to int 1.
if (!is_numeric($value)) {
return false;
}
$value = absint($value);
} else {
$value = trim($value);
}
if (!$value) {
return false;
}
switch ($field) {
case 'id':
$user_id = $value;
$db_field = 'ID';
break;
case 'slug':
$user_id = wp_cache_get($value, 'userslugs');
$db_field = 'user_nicename';
break;
case 'email':
$user_id = wp_cache_get($value, 'useremail');
$db_field = 'user_email';
break;
case 'login':
$value = sanitize_user($value);
$user_id = wp_cache_get($value, 'userlogins');
$db_field = 'user_login';
break;
default:
return false;
}
if (false !== $user_id) {
if ($user = wp_cache_get($user_id, 'users')) {
return $user;
}
}
if (!($user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE {$db_field} = %s", $value)))) {
return false;
}
update_user_caches($user);
return $user;
}
示例7: cache_users
/**
* Retrieve info for user lists to prevent multiple queries by get_userdata()
*
* @since 3.0.0
*
* @param array $user_ids User ID numbers list
*/
function cache_users($user_ids)
{
global $nxtdb;
$clean = array();
foreach ($user_ids as $id) {
$id = (int) $id;
if (!nxt_cache_get($id, 'users')) {
$clean[] = $id;
}
}
if (empty($clean)) {
return;
}
$list = implode(',', $clean);
$users = $nxtdb->get_results("SELECT * FROM {$nxtdb->users} WHERE ID IN ({$list})");
$ids = array();
foreach ($users as $user) {
update_user_caches($user);
$ids[] = $user->ID;
}
update_meta_cache('user', $ids);
}
示例8: get_data_by
/**
* Return only the main user fields
*
* @since 3.3.0
*
* @param string $field The field to query against: 'id', 'slug', 'email' or 'login'
* @param string|int $value The field value
* @return object Raw user object
*/
static function get_data_by( $field, $value ) {
global $wpdb;
if ( 'id' == $field )
$value = absint( $value );
else
$value = trim( $value );
if ( !$value )
return false;
switch ( $field ) {
case 'id':
$user_id = $value;
$db_field = 'ID';
break;
case 'slug':
$user_id = wp_cache_get($value, 'userslugs');
$db_field = 'user_nicename';
break;
case 'email':
$user_id = wp_cache_get($value, 'useremail');
$db_field = 'user_email';
break;
case 'login':
$value = sanitize_user( $value );
$user_id = wp_cache_get($value, 'userlogins');
$db_field = 'user_login';
break;
default:
return false;
}
if ( false !== $user_id ) {
if ( $user = wp_cache_get( $user_id, 'users' ) )
return $user;
}
if ( !$user = $wpdb->get_row( $wpdb->prepare(
"SELECT * FROM $wpdb->users WHERE $db_field = %s", $value
) ) )
return false;
update_user_caches( $user );
return $user;
}
示例9: _fill_single_user
/**
* Unserialize user metadata, fill $user object, then cache everything.
*
* @since 3.0.0
* @param object $user The User object.
* @param array $metavalues An array of objects provided by get_user_metavalues()
*/
function _fill_single_user(&$user, &$metavalues)
{
global $wpdb;
foreach ($metavalues as $meta) {
$value = maybe_unserialize($meta->meta_value);
$user->{$meta->meta_key} = $value;
}
$level = $wpdb->prefix . 'user_level';
if (isset($user->{$level})) {
$user->user_level = $user->{$level};
}
// For backwards compat.
if (isset($user->first_name)) {
$user->user_firstname = $user->first_name;
}
if (isset($user->last_name)) {
$user->user_lastname = $user->last_name;
}
if (isset($user->description)) {
$user->user_description = $user->description;
}
update_user_caches($user);
}