Esempio n. 1
0
function evc_update_share()
{
    $version = get_option('evc_version');
    $options = get_option('evc_options');
    $evc_autopost = get_option('evc_autopost');
    $evc_vk_api_autopost = get_option('evc_vk_api_autopost');
    if (isset($options) && $options && !empty($options) && (!$version || empty($version))) {
        //if (!isset($version) || empty($version) || !$version) {
        if (isset($options['access_token']) && !empty($options['access_token'])) {
            $evc_vk_api_autopost['access_token'] = $options['access_token'];
        }
        if (isset($options['app_id']) && !empty($options['app_id'])) {
            $evc_vk_api_autopost['app_id'] = $options['app_id'];
        }
        if (isset($options['access_token_url']) && !empty($options['access_token_url'])) {
            $evc_vk_api_autopost['access_token_url'] = $options['access_token_url'];
        }
        update_option('evc_vk_api_autopost', $evc_vk_api_autopost);
        unset($options['access_token'], $options['access_token_url'], $options['app_id']);
        if (isset($options['from_group']) && !empty($options['from_group'])) {
            $evc_autopost['format']['from_group'] = 'from_group';
        }
        if (isset($options['signed']) && !empty($options['signed'])) {
            $evc_autopost['format']['signed'] = 'signed';
        }
        if (isset($options['add_link']) && !empty($options['add_link'])) {
            $evc_autopost['format']['add_link'] = 'add_link';
        }
        unset($options['from_group'], $options['signed'], $options['add_link']);
        $evc_autopost = wp_parse_args($evc_autopost, $options);
        update_option('evc_autopost', $evc_autopost);
        //delete_option('evc_options');
        update_option('evc_version', evc_version());
    }
}
Esempio n. 2
0
function evc_api_post($args)
{
    $params = array('body' => $args, 'user-agent' => 'EVCAPI/' . evc_version() . '; ' . site_url(), 'host' => get_bloginfo('url'));
    $data = wp_remote_post(EVC_API, $params, array('sslverify' => false));
    if (is_wp_error($data)) {
        evc_add_log('EVC API ' . $args['method'] . ': WP ERROR. ' . $data->get_error_code() . ' ' . $data->get_error_message());
        return false;
    }
    $resp = json_decode($data['body'], true);
    if (isset($resp['error'])) {
        if (isset($resp['error']['error_code'])) {
            evc_add_log('EVC API ' . $args['method'] . ': Error. ' . $resp['error']['error_code'] . ' ' . $resp['error']['error_msg']);
        }
        return false;
    }
    if (isset($resp['response']) && !empty($resp['response'])) {
        return $resp['response'];
    } else {
        return false;
    }
}