Answer the question
In order to leave comments, you need to log in
Restriction on editing and deleting media files in wordpress. How to do?
I have a User Role Editor plugin in which I allow users with "Author" rights to upload media files.
Suppose the author writes a post, inserts a media file there. After that, sends the post to the admin for approval. After the admin publishes this post, the user with "Author" rights cannot edit or delete this post (in my case).
However, if he enters the media, then he has open rights to edit and delete media that are tied to this already published post. In role plugins, there is no such function for restriction. Those. I want to protect myself from authors who, after receiving payment for the article, can play a dirty trick and delete the photos that they uploaded for publication. I hope the meaning of my idea is clear.
How in functions.php to limit the rights of the "Author" (or everyone except the admin) to edit and delete media that are attached to an already published post?
On one of the forums, I was offered a solution, but it does not work:
// Права доступа на удаление файлов вложеныyх в посты со статусом "Опубликовано"
add_action('delete_attachment', 'DontDeleteMedia', 11, 1);
function DontDeleteMedia($postID){
$post_image = get_post( $postID ); // инфа про изображение // получаем отсюда страницу вложения
$post_post = get_post( $post_image->post_parent ); // Инфа о странице вложения // получаем отсюда статус публикации
if (!current_user_can('manage_options') && $post_post->post_status == 'publish' && +($post_image->post_parent) !== 0 ) { // роли
exit('Дальнейшие действия с файлом по разрешению администратора');
}
}
Answer the question
In order to leave comments, you need to log in
A similar topic was raised here:
https://wordpress.stackexchange.com/questions/1287...
Maybe it will help you...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question