PHP有条件检查多个WordPress角色
我正在寻找更多的性能代码来选择多个WordPress角色作为检查来运行一些代码的检查:
if ( current_user_can( 'wholesale_customer' ) || current_user_can( 'wholesale_premium' ) || current_user_can( 'wholesale_nz') || current_user_can( 'wholesale_wa') ){
// do something
}
上述代码有效,但我疑问是最佳的,据我了解,您无法将多个角色传递到 current_user_user_can 作为一个数组,但更多的功能。
I am looking for more performant code for selecting multiple WordPress roles as a check to run some code:
if ( current_user_can( 'wholesale_customer' ) || current_user_can( 'wholesale_premium' ) || current_user_can( 'wholesale_nz') || current_user_can( 'wholesale_wa') ){
// do something
}
The above code works but I question is it optimal, from what I understand you can't pass multiple roles into current_user_can as an array but more so capabilities.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您也可以使用
user_roles_array
检查 -You can also check with
user_roles_array
like this -那一个 -
How about this one -