admin管理员组文章数量:1134579
I have an application that requires that only the user + admin can access files uploaded by that user?
EG a user uploads an image to media. Only that user should have access to it Thanks for any tips Mike
One attempt
Second cut - screws up routing
function restrict_media_access_to_creator($query) {
if (current_user_can('administrator')) {
return $query;
}
$current_user_id = get_current_user_id();
$query['author'] = $current_user_id;
return $query;
}
add_filter('ajax_query_attachments_args', 'restrict_media_access_to_creator');
function restrict_posts_to_creator($where) {
if (current_user_can('administrator')) {
return $where;
}
global $wpdb;
$current_user_id = get_current_user_id();
$where .= " AND {$wpdb->posts}.post_author = " . $current_user_id;
return $where;
}
add_filter('posts_where', 'restrict_posts_to_creator');
Other candidate plugins
WP Customer Area: This is a modular all-in-one solution to manage private content with WordPress. Sharing files/pages with one or multiple users is one of the main features provided by this plugin. Each user gets their own private page where they can add content and upload files.
FileBird – WordPress Media Library Folders: FileBird provides you with the ability to easily organize your files in the media library of your site. With this tool in hand, you can manage and arrange thousands of images, audios, videos, and other files in your media library.
WP Media Folder: This plugin offers a way to create folders in your WordPress media library. With the addon "WP Media Folder Addon" you can set user media access, which restricts media display and media management to user-owned or user-role media only. Note that this is a premium plugin.
WordPress Real Media Library: This is another premium option, but it's quite powerful. The WordPress Real Media Library provides a way to handle media files, folders, and galleries. It allows you to organize thousands of uploaded files into folders, collections, and galleries.
Other ideas
External file manager
- Involves discovery, Can we hook it in to WPDatatables
Some way of tagging files that matches a key that is part of the user profile
We are already using Ultimate Member plugin - paid version
I have an application that requires that only the user + admin can access files uploaded by that user?
EG a user uploads an image to media. Only that user should have access to it Thanks for any tips Mike
One attempt
Second cut - screws up routing
function restrict_media_access_to_creator($query) {
if (current_user_can('administrator')) {
return $query;
}
$current_user_id = get_current_user_id();
$query['author'] = $current_user_id;
return $query;
}
add_filter('ajax_query_attachments_args', 'restrict_media_access_to_creator');
function restrict_posts_to_creator($where) {
if (current_user_can('administrator')) {
return $where;
}
global $wpdb;
$current_user_id = get_current_user_id();
$where .= " AND {$wpdb->posts}.post_author = " . $current_user_id;
return $where;
}
add_filter('posts_where', 'restrict_posts_to_creator');
Other candidate plugins
WP Customer Area: This is a modular all-in-one solution to manage private content with WordPress. Sharing files/pages with one or multiple users is one of the main features provided by this plugin. Each user gets their own private page where they can add content and upload files.
FileBird – WordPress Media Library Folders: FileBird provides you with the ability to easily organize your files in the media library of your site. With this tool in hand, you can manage and arrange thousands of images, audios, videos, and other files in your media library.
WP Media Folder: This plugin offers a way to create folders in your WordPress media library. With the addon "WP Media Folder Addon" you can set user media access, which restricts media display and media management to user-owned or user-role media only. Note that this is a premium plugin.
WordPress Real Media Library: This is another premium option, but it's quite powerful. The WordPress Real Media Library provides a way to handle media files, folders, and galleries. It allows you to organize thousands of uploaded files into folders, collections, and galleries.
Other ideas
External file manager
- Involves discovery, Can we hook it in to WPDatatables
Some way of tagging files that matches a key that is part of the user profile
We are already using Ultimate Member plugin - paid version
Share Improve this question edited Aug 5, 2023 at 0:56 Cloudworks asked Aug 4, 2023 at 7:43 CloudworksCloudworks 11 bronze badge 6 | Show 1 more comment1 Answer
Reset to default 0Check this out, it might be helpful I am also looking for a good solution
https://wordpress.stackexchange.com/a/400352/220907
How to hide media uploads by other users in the Media menu?
本文标签: uploadsHow allow only the uploading user access to media
版权声明:本文标题:uploads - How allow only the uploading user access to media 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736849581a1955443.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
/uploads/
directory isn't really a thing. If they have the URL they're able to access the content in that directory. So if someone copy/pastes a URL of a file they uploaded to a colleague, that colleague can see the file in the browser. If what you want is to restrict access to things IN the media library, IN the WP Dashboard that could be done, but there's quite a bit of code you'd probably need to write. What have you tried? – Tony Djukic Commented Aug 4, 2023 at 16:31