Skip to content

Instantly share code, notes, and snippets.

@jtcote
Last active December 22, 2015 22:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtcote/6543911 to your computer and use it in GitHub Desktop.
Save jtcote/6543911 to your computer and use it in GitHub Desktop.
WP media library filter to display only logged in users uploaded files
<?php
/**
* Media Library - View logged in author uploads only
*
* @package GUM WP Child Theme Functions
* @author Jayson T. Cote <askjayson@gmail.com>
* @copyright Copyright (c) 2013, Jayson T. Cote
* @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
*
*/
add_filter('parse_query', 'gum_author_only_media_uploads' );
function gum_author_only_media_uploads( $wp_query ) {
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false ) {
if ( !current_user_can( 'level_5' ) ) {
global $current_user;
$wp_query->set( 'author', $current_user->id );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment