wordpress - WordPress 角色和功能的雄辩模型
问题描述
我正在使用 Laravel 访问一些 WordPress 表,我的问题是我不了解 WordPress 角色和功能是如何工作的,所以有人可以给我一个 Schema 或解释我如何将角色和功能转换为雄辩的模型吗?
我做了什么:
class User extend Model {
/**
* Get the User meta.
*
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
public function meta(): Relation
{
return $this->hasMany(UserMeta::class, 'user_id');
}
/**
* Get the meta value
*
* @param string $key
* @return mixed
*/
public function getMeta(string $key)
{
$value = $this->meta()->where('meta_key', $key)->value('meta_value');
return maybe_unserialize($value);
}
/**
* Get the User roles.
*
* @return array
*/
public function getRolesAttribute(): array
{
return array_keys($this->getMeta('wp_capabilities'));
}
/**
* Get the User permissions.
*
* @return array
*/
public function getPermissionsAttribute(): array
{
// How I can search the user permissions in which table?
}
}
class UserMeta extends Model
{
protected $table = 'usermeta';
protected $primaryKey = 'umeta_id';
/**
* Get the meta parent.
*
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
public function user(): Relation
{
return $this->belongsTo(User::class, 'user_id');
}
}
解决方案
推荐阅读
- java - 动画如何在 UI 线程上工作而不阻塞其他消息并在 UI 线程的消息队列中运行?
- google-sheets - 如何检测 Google 表格中合并了哪些单元格
- java - 使用 OneToMany 连接维护订单
- numpy - 如何在满足特定条件的情况下创建行索引的 Numpy 矩阵?
- python-3.x - 我想用python解决Image Capthca
- python - 读取 excel 文件后将 StyleFrame obj 转换为 pandas 数据框
- c# - 未处理的异常:Android.Content.Res.Resources+NotFoundException:
发生了 - mysql - 是否可以将 SET 值动态添加到表中?
- python - Pandas- 在各种日期时间范围内分箱分钟数
- php - 我真的可以对致命的解析错误无所事事吗?