admin管理员组文章数量:1122846
I have this code, which works perfectly:
if (in_array('administrator', $user->roles)) {
I need it to also check for another role, so that it would be an, 'if this or that' scenario, such as, if administrator or editor
I've tried:
if (in_array('administrator', 'editor' $user->roles)) {
But that didn't work. Any help is appreciated.
I have this code, which works perfectly:
if (in_array('administrator', $user->roles)) {
I need it to also check for another role, so that it would be an, 'if this or that' scenario, such as, if administrator or editor
I've tried:
if (in_array('administrator', 'editor' $user->roles)) {
But that didn't work. Any help is appreciated.
Share Improve this question asked May 27, 2024 at 21:23 BarkingBirdBarkingBird 32 bronze badges1 Answer
Reset to default 0If I understand you correctly, you want to determine if the user has any role that is in some pre-defined list like this:
$accepted_roles = array(
'administrator',
'editor',
);
if ( ! empty( array_intersect( $accepted_roles, $user->roles ) ) ) {
...
本文标签: phpIf user is Admin or another role
版权声明:本文标题:php - If user is Admin or another role 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736305911a1932761.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论