Answers:
这实际上并不难。要添加新功能,请致电WP_Roles->add_cap()。您只需执行一次,因为它将存储在数据库中。因此,我们使用了插件激活挂钩。
其他读者注意事项:以下所有代码均为plugin region。
register_activation_hook( __FILE__, 'epp_add_cap' );
/**
 * Add new capability to "editor" role.
 *
 * @wp-hook "activate_" . __FILE__
 * @return  void
 */
function epp_add_cap()
{
    global $wp_roles;
    if ( ! isset( $wp_roles ) )
        $wp_roles = new WP_Roles;
    $wp_roles->add_cap( 'editor', 'edit_pending_posts' );
}现在我们必须过滤所有针对…的呼叫
current_user_can( $post_type_object->cap->edit_post, $post->ID );…因为这是WordPress检查用户是否可以编辑帖子的方式。在内部,这将映射到edit_others_posts其他作者职位的功能。
因此,当某些人想要使用user_has_cap新edit_pending_posts功能时,我们必须对其进行过滤和研究edit_post。
我也包括在内delete_post,因为这也是一种编辑。
听起来很复杂,但实际上很简单:
add_filter( 'user_has_cap', 'epp_filter_cap', 10, 3 );
/**
 * Allow editing others pending posts only with "edit_pending_posts" capability.
 * Administrators can still edit those posts.
 *
 * @wp-hook user_has_cap
 * @param   array $allcaps All the capabilities of the user
 * @param   array $caps    [0] Required capability ('edit_others_posts')
 * @param   array $args    [0] Requested capability
 *                         [1] User ID
 *                         [2] Post ID
 * @return  array
 */
function epp_filter_cap( $allcaps, $caps, $args )
{
    // Not our capability
    if ( ( 'edit_post' !== $args[0] && 'delete_post' !== $args[0] )
        or empty ( $allcaps['edit_pending_posts'] )
    )
        return $allcaps;
    $post = get_post( $args[2] );
    // Let users edit their own posts
    if ( (int) $args[1] === (int) $post->post_author
        and in_array(
            $post->post_status,
            array ( 'draft', 'pending', 'auto-draft' )
        )
    )
    {
        $allcaps[ $caps[0] ] = TRUE;
    }
    elseif ( 'pending' !== $post->post_status )
    { // Not our post status
        $allcaps[ $caps[0] ] = FALSE;
    }
    return $allcaps;
}$post->post_author它以字符串形式但$args[1]以整数形式传递。有时。愚蠢的WordPress!我通过将它们都转换为整数来修复它。而且我允许编辑者编辑自己发表的帖子。如果您不希望这样做,请删除return块之后的行// Let users edit their own posts。
                    return $allcaps;行,并且保存草稿时出现了相同的权限问题。为什么?
                    $allcaps[ $caps[0] ] = TRUE;?下的返回线。很奇怪,我正在经历这种情况,如果它对您有用
                    
edit_posts和edit_others_posts与新的edit_pending_posts。我试着edit_pending_posts在没有其他两个的情况下继续工作,而后菜单没有出现。测试时,我发现可以添加一个新帖子,但是无法保存草稿(请You are not allowed to edit this post注意)。您是否测试过保存自己的职位?编辑待处理的帖子很好。