douweng7083 2018-05-02 15:31
浏览 44
已采纳

PHP IF标签Wordpress

I currently have below, its showing that this template can only be accessed by the inspector role. I want to add multi role to this. What would be the best option.

if ( !current_user_can ('inspector')) {
    get_template_part('error');
    exit(0);
}
  • 写回答

1条回答 默认 最新

  • dsgtew3241 2018-05-02 15:36
    关注

    I'm not entirely sure that I understand the question, but this will show the error template if the user is not an inspector or admin. You can chain as many && together as you need for each role.

    if ( !current_user_can ('inspector') && !current_user_can('admin')) {
        get_template_part('error');
        exit(0);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?