Joy
(@joyously)
Do you have custom roles?
If not, isn’t the author role the least capable role to be able to publish? Any other roles less capable have to have their pages published by someone else, who can remove shortcodes.
What is the actual problem you are trying to solve?
Thread Starter
9march
(@9march)
Hi,
Sorry for the delayed response, I must have missed the email. Yes i have a custom role that was created by the frontend posting plugin i use and whenever i create a post as subscriber or any other role except administrator, The shortcodes show up all the time. Sorry for the misunderstanding, I meant to say, I want to remove the usage of shortcodes for all user roles except administrator.
Thanks,
Joy
(@joyously)
You could use a filter on the content either when it is saved or when it is output, and look at the author and call strip_shortcodes().
https://developer.wordpress.org/reference/functions/strip_shortcodes/
Thread Starter
9march
(@9march)
Hi,
Thanks for your great help, I received this code from my theme providers.
add_action( ‘init’, ‘remove_my_shortcodes’,20 );
function remove_my_shortcodes() {
if( !current_user_can(‘administrator’)){
remove_shortcode( ‘myshortcode’ );
}
}
Regards,
-
This reply was modified 6 years, 11 months ago by
9march.
-
This reply was modified 6 years, 11 months ago by
9march.
Joy
(@joyously)
Well, that might do what you want, however, it is a bit rough.
The current_user_can function should be used with a capability (like edit_posts), not a role. Here’s the list:
https://codex.wordpress.org/Roles_and_Capabilities
And since the init action happens on both the front end and the admin, it is always run. And all it does is make the shortcode handler not process the shortcode. The actual shortcode is still in the post.
My suggestion to use strip_shortcodes removes the actual characters of the shortcode from the content of the post.
You can find the sequence of the basic actions here:
https://codex.wordpress.org/Plugin_API/Action_Reference