在我们使用wordpress多用户主题的时候,WordPress后台会默认显示的所有用户文章、媒体文件,这样的情况会导致大家都可以看到其他用户的文章、媒体文件,很不方便管理。
今天本站分享一篇够让后台后台只显示当前登录用户的文章和媒体文件wordpress教程希望能给大家带来帮助
具体方法是将下面的代码添加到当前主题的 functions.php 文件即可:
//仅显示当前用户的文章、媒体文件
add_action( 'init', 'check_user_role' );
function check_user_role() {
global $current_user;
if( $current_user->roles[0] != 'administrator' ) {
//在[媒体库]只显示用户上传的文件
add_action('pre_get_posts','MBT_restrict_media_library');
function MBT_restrict_media_library( $wp_query_obj ) {
global $current_user, $pagenow;
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;
}
}
}
注:如果你的WordPress所使用的数据库前缀不是默认的wp_,请将第 5 、6 行中的wp_ 修改为你的WordPress站点的数据库前缀。
文章来源于互联网:wordpress后台只显示当前用户的文章和媒体文件
Stunning story there. What occurred after? Take care!
https://cutt.ly/r9myRbP
Pretty nice post. I just stumbled upon your weblog and wanted to say that I’ve really enjoyed browsing your blog posts.
In any case I’ll be subscribing to your feed and I hope you write again soon! https://www.youtube.com/watch?v=2IEIuU18xdk
Wonderful article! This is the type of information that are
supposed to be shared around the web. Shame on Google
for no longer positioning this submit higher! Come on over and
visit my site . Thank you =)
Here is my page … coupon
Somebody necessarily lend a hand to make seriously articles I’d state.
That is the very first time I frequented your website page
and up to now? I amazed with the analysis you made to make this actual put up incredible.
Great activity!
Very nice blog post. I absolutely love this site. Thanks!
I like the valuable info you provide in your articles.
I’ll bookmark your blog and check again here regularly.
I am quite certain I will learn many new stuff right here!
Best of luck for the next!
Quality content is the secret to interest the viewers to pay a quick
visit the web site, that’s what this web page is providing.
This information is invaluable. When can I find out more?
Good day! Would you mind if I share your blog with my myspace
group? There’s a lot of folks that I think would really appreciate your content.
Please let me know. Thank you
Here is my web page coupon