Created
November 17, 2015 09:36
-
-
Save viankakrisna/7e9467d6d3ab7f4b76cc to your computer and use it in GitHub Desktop.
Restrict non admin to only show image that they upload
This file contains 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', 'ml_restrict_media_library' ); | |
function ml_restrict_media_library( $wp_query_obj ) { | |
global $current_user, $pagenow; | |
if (!in_array( 'administrator', $current_user->roles )){ | |
if( !is_a( $current_user, 'WP_User') ) | |
return; | |
if( 'admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments' ) | |
return; | |
if( !current_user_can('manage_media_library') ) { | |
$wp_query_obj->set('author', $current_user->ID ); | |
return; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment