朱纯树博客
VPS测评推荐网站
cloudacead cloudacead

WordPress后台只显示当前用户的文章和媒体文件

在我们使用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后台只显示当前用户的文章和媒体文件

赞(0) 打赏
未经允许不得转载:VPS测评推荐网站 - 朱纯树博客 » WordPress后台只显示当前用户的文章和媒体文件

评论 30

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #30

    Keep on writing, great job!

  2. #29

    This piece of writing is actually a pleasant one it assists new internet
    viewers, who are wishing for blogging.

  3. #28

    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.

  4. #27

    Actually when someone doesn’t know afterward its up to other users that they will
    assist, so here it takes place.

  5. #26

    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!

  6. #25

    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!

    tinyurl.com2周前 (07-26)回复
  7. #24

    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.

  8. #23

    I am in fact glad to read this webpage posts which includes lots of valuable facts, thanks
    for providing such statistics.

    http://bit.ly4周前 (07-15)回复
  9. #22

    Психолог онлайн. Консультация Когда необходим прием психолога? – 6833 врачей, 6147 отзывов.

  10. #21

    Keep this going please, great job!

    tinyurl.com1个月前 (07-07)回复
  11. #20

    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.

    tinyurl.com2个月前 (06-14)回复
  12. #19

    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.

  13. #18

    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!!

    tinyurl.com2个月前 (06-05)回复
  14. #17

    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.

  15. #16

    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

    http://tinyurl.com3个月前 (05-11)回复