Last active
December 2, 2023 18:33
-
-
Save softiconic/bac4ad8853f3dae3fb05e40ab2419062 to your computer and use it in GitHub Desktop.
Restrict access to the media library in WordPress.
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
// Limit media library access | |
add_filter( 'ajax_query_attachments_args', 'wpb_show_current_user_attachments' ); | |
function wpb_show_current_user_attachments( $query ) { | |
$user_id = get_current_user_id(); | |
if ( $user_id && !current_user_can('activate_plugins') && !current_user_can('edit_others_posts | |
') ) { | |
$query['author'] = $user_id; | |
} | |
return $query; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment