我正在尝试从wp_editor
. 这很好,但我试图只允许用户查看他们是作者的图像。下面是我用来执行此操作的代码:
//restrict authors to only being able to view media that they\'ve uploaded
function ik_eyes_only( $wp_query ) {
//are we looking at the Media Library or the Posts list?
if ( strpos( $_SERVER[ \'REQUEST_URI\' ], \'/wp-admin/upload.php\' ) !== false
|| strpos( $_SERVER[ \'REQUEST_URI\' ], \'/wp-admin/edit.php\' ) !== false ) {
global $current_user;
$wp_query->set( \'author\', $current_user->id );
}
}
//filter media library & posts list for authors
add_filter(\'parse_query\', \'ik_eyes_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;
}
这很好用,上传的图像都会被过滤掉。php位于仪表板和页面前端。但是,如果我尝试从upload上传文件。在仪表板的php页面中,文件上载成功。当我从wp\\u编辑器中执行此操作时,尽管我会收到一个错误,即
An error occurred in the upload. Please try again later.
.
为什么要从管理仪表板上传,而不是从我的前端页面?