Last active
October 9, 2015 04:47
-
-
Save prasadnevase/697348add446fad1f312 to your computer and use it in GitHub Desktop.
WordPress Code to show media of logged in user in the media library. He won't be able to access media from other users.
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
add_action( 'pre_get_posts', 'users_own_attachments'); | |
function users_own_attachments( $wp_query_obj ) | |
{ | |
global $current_user, $pagenow; | |
if ( $pagenow == 'upload.php' || ( $pagenow == 'admin-ajax.php' && !empty( $_POST[ 'action' ] ) && $_POST[ 'action' ] == 'query-attachments' ) ) { | |
$wp_query_obj->set( 'author', $current_user->ID ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment