WordPress仅显示媒体用户已在wp_editor中上传 [英] wordpress show only media user has uploaded in wp_editor

查看:112
本文介绍了WordPress仅显示媒体用户已在wp_editor中上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个wordpress网站,注册用户可以通过前端的wp_editor()创建自己的帖子,而只能发布一个帖子.

I'm creating a wordpress site where the registered user has the ability to create his own post via wp_editor() on the frontend, but just one post.

现在,我想限制用户只能看到他上传的媒体.我在functions.php中使用以下脚本,该脚本可在后端运行.因此,如果用户转到后端的媒体部分,那么他只会看到他上传的媒体.

Now I want to restrict the user to be able to only see his uploaded media. I use the following script in the functions.php, which works in the backend. So if a user goes to the media section in the backend he will only see his uploaded media.

但是,如果用户转到前端wp_editor上的插入媒体"弹出窗口,他仍然可以看到所有用户上传的媒体.

But if the user goes to "insert media" pop-up on the frontend wp_editor he can still see the uploaded media from all the users.

function restricted_media_view( $wp_query ) {
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false  
|| strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
    if ( !current_user_can( 'level_5' ) ) {
        global $current_user;
        $wp_query->set( 'author', $current_user->id );
    }
    }
}
add_filter('parse_query', 'restricted_media_view' );

您有解决这个烦恼的主意吗?谢谢!

Do you have any idea hot to solve this annoyance? Thank you!

推荐答案

您可以尝试使用此插件:

You might try this plugin: http://wordpress.org/extend/plugins/view-own-posts-media-only/

或者尝试以下方法:

add_action('pre_get_posts','ml_restrict_media_library');

function ml_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;
}

来源: 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆