首页 > 解决方案 > 去除除管理员以外的所有用户角色的简码

问题描述

我正在寻找一种解决方案,该解决方案将去除除管理员之外的所有 wordpress 用户角色以及我选择的任何角色的简码。类似于以下链接中的解决方案,它从未被确认可以工作,我不知道哪个有效。

禁用某些用户角色的简码使用

谢谢,

标签: wordpressuser-roleswordpress-shortcode

解决方案


您应该结合两个答案:

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”将是您还想从简码剥离中排除的其他角色。


推荐阅读