本文整理汇总了PHP中WP_User::__get方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_User::__get方法的具体用法?PHP WP_User::__get怎么用?PHP WP_User::__get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_User
的用法示例。
在下文中一共展示了WP_User::__get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __get
/**
* Magic getter method. Looks for the specified key in the mapped keys before using WP_User's __get method.
*
* @return mixed
* @access public
* @since 1.0.0
*/
public function __get($key)
{
$mapped_keys = $this->get_mapped_keys();
if (array_key_exists($key, $mapped_keys)) {
$key = $mapped_keys[$key];
}
return parent::__get($key);
}
示例2:
function __get($key)
{
if ($key == 'assignments') {
return $this->getAssignments();
} else {
// fallback to default WP_User magic method
return parent::__get($key);
}
}
示例3: admin_user_rights
/**
* Assign the 'DJ' role to an administrator
*
* @since 1.3
* @param int $user_id User ID.
* @param int $old_data Object containing user's data prior to update.
* @return
*/
public function admin_user_rights($user_id, $old_data)
{
if (!user_can($user_id, 'administrator')) {
return;
}
// Retrieve the current user object after the profile update
$user = new WP_User($user_id);
$is_staff = $user->__get('_mdjm_event_staff');
$required_roles = $user->__get('_mdjm_event_roles');
$make_admin = $user->__get('_mdjm_event_admin');
$mdjm_roles = mdjm_get_roles();
if (!empty($is_staff) && !empty($required_roles)) {
// Reset roles and caps before applying updates due to some wierd bug
foreach ($mdjm_roles as $role_id => $role_name) {
$user->remove_role($role_id);
}
$user->remove_cap('mdjm_employee');
foreach ($required_roles as $role_id) {
$user->add_role($role_id);
}
$user->add_cap('mdjm_employee');
delete_user_meta($user->ID, '_mdjm_event_roles');
} else {
foreach ($mdjm_roles as $role_id => $role_name) {
$user->remove_role($role_id);
}
$user->remove_cap('mdjm_employee');
}
$permissions = new MDJM_Permissions();
if (!empty($make_admin)) {
$permissions->make_admin($user->ID);
$user->add_cap('mdjm_employee');
} else {
$permissions->make_admin($user->ID, true);
$user->remove_cap('mdjm_employee');
}
}