Last active
August 29, 2015 14:16
-
-
Save franz-josef-kaiser/0688bfb7fda30e815ef8 to your computer and use it in GitHub Desktop.
WordPress Plugin: Limit the display of attachments (in the admin screens) to the ones uploaded by the current user
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 | |
| /** | |
| * Plugin Name: Attachment Role limit | |
| * Plugin URI: https://gist.github.com/franz-josef-kaiser/0688bfb7fda30e815ef8 | |
| * Description: Limit the display of attachments (in the admin screens) to the ones uploaded by the current user. | |
| * Version: 2015.02.24 | |
| * Author: Franz Josef Kaiser <wecodemore@gmail.com> | |
| * Author URI: http://unserkaiser.com | |
| * License: MIT | |
| * License URI: https://tldrlegal.com/license/mit-license | |
| */ | |
| class AttachmentRoleLimitService | |
| { | |
| /** | |
| * @param \WP_Query $query | |
| */ | |
| public function setup( \WP_Query $query = null ) | |
| { | |
| if ( ! is_admin() ) | |
| return; | |
| if ( | |
| current_user_can( 'manage_options' ) | |
| // @TODO Add additional capability checks for not-affected roles here | |
| // or current_user_can( 'another_capability' ) | |
| or 'attachment' !== $query->get( 'post_type' ) | |
| ) | |
| return; | |
| $query->set( 'author', get_current_user_id() ); | |
| } | |
| } | |
| add_filter( 'pre_get_posts', array( new AttachmentRoleLimitService, 'setup' ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment