Skip to content

Instantly share code, notes, and snippets.

@franz-josef-kaiser
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save franz-josef-kaiser/0688bfb7fda30e815ef8 to your computer and use it in GitHub Desktop.

Select an option

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
<?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