I have a guest posting plugin on my Wordpress site and want to disable usage of shortcodes for certain users roles (subscribers for example). I need this for security reasons mostly.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Assume that you have shortcode,
function myshortcode(){
$user = wp_get_current_user();
if ( !in_array( 'author', (array) $user->roles ) ) {
//Run shortcode
}
}
add_shortcode('myshortcode','myshortcode');
回答2:
You can use the strip_shortcodes()
function, you can use it as a filter to strip shortcodes from your desired content:
function example_remove_shortcode( $content ) {
$content = strip_shortcodes( $content );
return $content;
}
add_filter( 'the_content', 'example_remove_shortcode' );
or
echo strip_shortcodes( $my_customly_created_content );
in where you want to show the content.