Wordpress 如何隐藏”添加媒体”按钮
2014-03-10 14:29
295 查看
在多用户WordPress站点, 如果给用户开启了编辑权限, 那么无论是一般作者还是编辑在撰写文章时都会用到添加媒体功能. 但是我们却又不想给一些级别作者添加媒体的权利或者只想每个用户只能上传并管理自己的媒体文件, 不能编辑他人的媒体.
这篇文章的教程就是教会大家如何隐藏”添加媒体”按钮与限定作者只能看到及编辑自己的媒体文件.
下面则是效果图
这篇文章的教程就是教会大家如何隐藏”添加媒体”按钮与限定作者只能看到及编辑自己的媒体文件.
只要不是管理员就隐藏”添加媒体”按钮
下面这段代码设置只要权限等级不是最高等级level_10就隐藏掉”添加媒体”按钮1 2 3 4 5 6 | functionRemoveAddMediaButtonsForNonAdmins(){ if(!current_user_can('level_10')){ remove_action('media_buttons','media_buttons'); } } add_action('admin_head','RemoveAddMediaButtonsForNonAdmins'); |
只能看见并编辑自己的媒体文件
运用以下代码, 管理员能看见并编辑所有媒体文件. 如果你也想要编辑也能看见所有媒体文件, 那么你需要改变’manage_options’, 如’edit pages’这样编辑拥有的权限.1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | /** * 只能看见自己的媒体文件 */ functionmy_authored_content($query){ //get current user info to see if they are allowed to access ANY posts and pages $current_user=wp_get_current_user(); // set current user to $is_user $is_user=$current_user->user_login; //if is admin or 'is_user' does not equal #username if(!current_user_can('manage_options')){ //if in the admin panel if($query->is_admin){ global$user_ID; $query->set('author', $user_ID); } return$query; } return$query; } add_filter('pre_get_posts','my_authored_content'); |
相关文章推荐
- 黄聪:wordpress如何添加自定义文章快速编辑按钮
- 黄聪:如何给wordpress的编辑器添加一个自定义按钮,并且实现插入功能
- Dynamics CRM 365 子网格上"添加"按钮旁的“查看关联视图”按钮如何控制显示和隐藏?
- win10专业版如何给右键菜单添加显示隐藏文件按钮?
- 黄聪:如何使用钩子定制WordPress添加媒体界面,去除不需要的元素
- 黄聪:wordpress如何扩展TinyMCE编辑器,添加自定义按钮及功能
- WordPress添加显示和隐藏侧边栏按钮开关
- 如何动态给图片添加、隐藏按钮
- Dynamics CRM2011 隐藏sub-grid 新建项和添加现有项按钮
- BCB如何隐藏任务栏上对应的程序图标按钮,不是托盘上的
- 在页面中,我们经常看到,一个button按钮,如果属标点击,就会触发一个窗口的显示,如果二次点击并可以隐藏,那么如何通过JAVA配合html来实现这一功能呢?
- QT中如何给表格添加按钮
- 教你如何在wordpress添加统计代码
- 将1:N关系的界面上"添加现有****"按钮隐藏掉
- 有一行表格,点击按钮后,如何再添加一行呀
- 如何让WordPress自动对外链添加"nofollow"标签
- WordPress如何添加广告位?wordpress常见的几种广告位的添加方法
- MFC 如何添加位图按钮
- js如何实现点击一个按钮显示一个div,然后该div上有一个按钮,点击此按钮后隐藏,隐藏的同时显示另外一个div,而在次弹出的div也有一个按钮,点击后隐藏.