Last active
May 20, 2018 16:25
-
-
Save nydame/7c4901d00944cb411251e0df1d2ed3a7 to your computer and use it in GitHub Desktop.
Control who can delete Media Library files on a WordPress site on the basis of a capability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
</php | |
// In this example, only logged-in users with the 'activate_plugins' capability will be able to delete files shown in the Media Library. | |
// (By default, only administrators have this capability.) | |
// This code should be put in functions.php or in a plugin. | |
add_action('delete_attachment', array($this, 'restrict_media_deletion_permissions'), 1); | |
public function restrict_media_deletion_permissions($post_id) { | |
if (! current_user_can('activate_plugins')) { | |
?> | |
<script type="text/javascript">alert("You do not have permission to delete media files.");</script> | |
<?php | |
die(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment