Home >Backend Development >PHP Tutorial >WordPress author role cannot add video code_PHP tutorial
There has always been a very strange situation, that is, video code cannot be added in WordPress. Specifically, after adding the video code in the background editor text mode, switching to visualization can see the video box normally, but after saving Video code message.
After careful observation, I found that authors cannot add, but editors and administrators can.
Without getting too excited, let’s talk about the solution first: To put it bluntly, it’s very simple. Just install a plug-in “User Role Editor” and check “Do not filter html tags” under the author role.
1. Debug and find the following code calling sequence:
wp_update_post->
wp_insert_post->
sanitize_post->
sanitize_post_field->
2.
content_save_pre.
wp_filter_post_kses');.
function kses_init() {
kses_remove_filters();
if (current_user_can('unfiltered_html') == false)
kses_init_filters();
}
add_action('init', 'kses_init');
add_action('set_current_user', 'kses_init');
At this time, I found that the current user does not have the permission to unfilter_html.
Solution
1. Try to remove this wp_filter_post_kses using the function remove_filter, but this will cause a problem of the order of add_filter and remove_filter, but where I added remove_filter is before add_filter.
In this way, even if you find a clever place to add remove, you still rely too much on this sequence relationship to ensure that no one will cause a big mess.
2. Directly grant pre-unfilter_html permission to the user. One disadvantage of this is that a series of functions in kses_init_filters are deleted. Considering that this is my own blog, the authors are all designated people, and this solution is easy to understand and there are not so many twists and turns, I decided to use this method.
Wordpress is so powerful and frustrating.