function evc_comments_add_comment($comment, $post_id, $widget_api_id, $comment_parent = null)
{
    if (isset($comment['cid'])) {
        $comment['id'] = $comment['cid'];
    }
    $vk_item_id = 'app' . $widget_api_id . '_' . $comment['id'];
    $comment_wp_id = evc_get_wpid_by_vkid($vk_item_id, 'comment');
    if ($comment_wp_id && isset($comment_wp_id[$vk_item_id])) {
        return $comment_wp_id[$vk_item_id];
    }
    if (isset($comment['user']) && !empty($comment['user'])) {
        $user_wp_id = evc_get_wpid_by_vkid($comment['user']['id'], 'user');
        if (!$user_wp_id) {
            $user_wp_id = evc_add_user($comment['user']);
            if (!$user_wp_id) {
                return false;
            }
        } else {
            $user_wp_id = $user_wp_id[$comment['user']['id']];
        }
    } else {
        return false;
    }
    $args = array('comment_post_ID' => $post_id, 'comment_content' => $comment['text'], 'user_id' => $user_wp_id, 'comment_date' => date('Y-m-d H:i:s', $comment['date'] + get_option('gmt_offset') * 3600), 'comment_approved' => 1, 'comment_author_IP' => preg_replace('/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR']), 'comment_agent' => substr($_SERVER['HTTP_USER_AGENT'], 0, 254));
    if (isset($comment_parent) && !empty($comment_parent)) {
        $args['comment_parent'] = $comment_parent;
    }
    $args = apply_filters('evc_comments_add_comment_args', $args, $comment);
    //print__r($args); //
    $comment_wp_id = wp_insert_comment($args);
    if ($comment_wp_id) {
        update_comment_meta($comment_wp_id, 'vk_item_id', $vk_item_id);
    }
    return $comment_wp_id;
}
function evc_auth_user_authorize($user_vk_id)
{
    $user_wp_id = evc_get_wpid_by_vkid($user_vk_id, 'user');
    if (!$user_wp_id) {
        $user_vk_data = evc_vkapi_get_users(array('user_ids' => $user_vk_id));
        if (!$user_vk_data || !isset($user_vk_data[0])) {
            return false;
        }
        $user_wp_id = evc_add_user($user_vk_data[0]);
    } else {
        $user_wp_id = $user_wp_id[$user_vk_id];
    }
    if (!$user_wp_id) {
        return false;
    }
    wp_set_auth_cookie($user_wp_id, true);
    evc_refresh_vk_img_all();
    return $user_wp_id;
}