从WP_EDITOR上载图像失败

时间:2015-01-14 作者:user1048676

我正在尝试从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..

为什么要从管理仪表板上传,而不是从我的前端页面?

1 个回复
最合适的回答,由SO网友:user1048676 整理而成

实际上,我必须为我所使用的角色赋予额外的能力。我必须允许访问该功能edit_others_php 文件已成功上载。

结束

相关推荐

Admin Theme customization

我遵循wordpress codex网站上关于通过插件创建管理主题的说明。我激活了插件,但我的样式表没有包含在<head>.. 这是我的代码:add_action( \'admin_init\', \'kd_plugin_admin_init\' ); add_action( \'admin_menu\', \'kd_plugin_admin_menu\' ); function kd_plugin_admin_init() { /* Register