我正在寻找一种解决方案,它将删除所有wordpress用户角色的短代码,除了管理员和我选择的角色。类似于以下链接的解决方案,它从未被确认工作,我不知道哪个工作。
Disable Shortcode usage for certain user roles
谢谢,
你应该结合两个答案:
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”将是您还希望从短代码剥离中排除的其他角色。