在我们使用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后台只显示当前用户的文章和媒体文件
Keep on writing, great job!
This piece of writing is actually a pleasant one it assists new internet
viewers, who are wishing for blogging.
Just want to say your article is as astounding.
The clearness in your put up is just nice and i could assume you are a professional in this
subject. Well with your permission allow me to grab your RSS feed
to stay updated with imminent post. Thank you 1,000,000 and please continue the rewarding work.
Actually when someone doesn’t know afterward its up to other users that they will
assist, so here it takes place.
Pretty nice post. I just stumbled upon your weblog and wanted to say
that I’ve truly enjoyed surfing around your blog posts. In any case I’ll be subscribing to
your feed and I hope you write again soon!
My brother recommended I might like this web site.
He was totally right. This post actually made my day.
You can not imagine simply how much time I had spent for this
information! Thanks!
Its like you read my mind! You appear to know so much about this, like you wrote the book in it or something.
I think that you can do with some pics to drive the message home a little bit, but instead of
that, this is fantastic blog. An excellent read. I’ll definitely be back.
I am in fact glad to read this webpage posts which includes lots of valuable facts, thanks
for providing such statistics.
Психолог онлайн. Консультация Когда необходим прием психолога? – 6833 врачей, 6147 отзывов.
Keep this going please, great job!
Link exchange is nothing else but it is simply placing the other person’s blog link on your page
at proper place and other person will also do similar
for you.
hi!,I love your writing very so much! percentage we
keep up a correspondence extra about your post
on AOL? I require an expert in this space to resolve my problem.
Maybe that’s you! Looking forward to see you.
Hi, i feel that i noticed you visited my site thus i got here to return the choose?.I’m attempting to find
things to enhance my site!I suppose its good enough to
make use of a few of your ideas!!
I all the time used to read piece of writing in news papers but now as I am a user of
net therefore from now I am using net for articles or reviews, thanks to web.
Awesome blog! Is your theme custom made or did you download it from somewhere?
A theme like yours with a few simple adjustements would really make my blog shine.
Please let me know where you got your theme. Kudos