wordpress - 去除除管理员以外的所有用户角色的简码
问题描述
我正在寻找一种解决方案,该解决方案将去除除管理员之外的所有 wordpress 用户角色以及我选择的任何角色的简码。类似于以下链接中的解决方案,它从未被确认可以工作,我不知道哪个有效。
谢谢,
解决方案
您应该结合两个答案:
function remove_shortcode_for_user_roles( $content ) {
$user = wp_get_current_user();
if ( in_array( 'administrator', (array) $user->roles ) == false &&
in_array( 'other_role', (array) $user->roles ) == false ) {
$content = strip_shortcodes( $content );
}
return $content;
}
add_filter( 'the_content', 'remove_shortcode_for_user_roles' );
“other_role”将是您还想从简码剥离中排除的其他角色。
推荐阅读
- typescript - TypeScript:如何使用 Object.entries 向此函数添加正确的类型
- c# - 如何使用 C# 在 PC 上模拟 PS4 控制器的操纵杆?
- python - 如何让我的函数打印我的代码?
- xml - 重写声明,使顺序不再重要
- matlab - 边缘函数如何在边缘函数中自动计算阈值?
- angular - 有没有办法将现有的 Angular 应用程序连接到另一个 nativescript 应用程序(角度)?
- android - 新的安卓应用在旧手机上运行良好,但在新手机上却不行
- c - 奇怪的 C 行为
- r - 在 Google Colab 中保存 R 输出
- go - 为什么指针类型可以访问嵌入类型的所有方法