本文整理汇总了PHP中WP_User_Query::set方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_User_Query::set方法的具体用法?PHP WP_User_Query::set怎么用?PHP WP_User_Query::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_User_Query
的用法示例。
在下文中一共展示了WP_User_Query::set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function test_exclude()
{
$users = new WP_User_Query();
$users->set('fields', '');
$users->set('exclude', $this->user_id);
$users->prepare_query();
$users->query();
$ids = $users->get_results();
$this->assertNotContains($this->user_id, $ids);
}
示例2:
function test_get_and_set()
{
$users = new WP_User_Query();
$this->assertEquals('', $users->get('fields'));
$this->assertEquals('', @$users->query_vars['fields']);
$users->set('fields', 'all');
$this->assertEquals('all', $users->get('fields'));
$this->assertEquals('all', $users->query_vars['fields']);
$users->set('fields', '');
$this->assertEquals('', $users->get('fields'));
$this->assertEquals('', $users->query_vars['fields']);
$this->assertNull($users->get('does-not-exist'));
}
示例3: hocwp_setup_theme_pre_get_users
function hocwp_setup_theme_pre_get_users(WP_User_Query $query)
{
if (is_admin()) {
if ($GLOBALS['pagenow'] == 'users.php') {
$user = wp_get_current_user();
$exclude = (array) $query->get('exclude');
$exclude[] = $user->ID;
$exclude = array_unique($exclude);
$query->set('exclude', $exclude);
}
}
return $query;
}