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

查看:20
本文介绍了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!

推荐答案

你可以试试这个插件: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;
}

来源:http://wpsnipp.com/index.php/functions-php/restricting-users-to-view-only-media-library-items-they-upload/#comment-810649773

这篇关于wordpress 仅显示用户已在 wp_editor 中上传的媒体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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