array(
'manage_users' => true,
'manage_posts' => true,
'manage_comments' => true
),
'editor' => array(
'manage_posts' => true,
'manage_comments' => true
),
'author' => array(
'manage_posts' => true
),
'subscriber' => array(
'view_posts' => true
)
);
// 获取用户角色
$user_role = 'admin';
// 检查用户权限
if (isset($permissions[$user_role])) {
$user_permissions = $permissions[$user_role];
// 检查用户是否有权限管理用户
if ($user_permissions['manage_users']) {
echo "User has permission to manage users. ";
}
// 检查用户是否有权限管理文章
if ($user_permissions['manage_posts']) {
echo "User has permission to manage posts. ";
}
// 检查用户是否有权限管理评论
if ($user_permissions['manage_comments']) {
echo "User has permission to manage comments. ";
}
} else {
echo "User role not found. ";
}
?>