コード例 #1
0
function evo_wp_remote_test($protocol)
{
    if ($protocol == 'post') {
        $request_string = array('body' => array('action' => 'wp_remote_post'));
        $request = wp_remote_post('http://74.62.111.12/~updates/eventon/json.php', $request_string);
        if (!is_wp_error($request) || wp_remote_retrieve_response_code($request) === 200) {
            if (isset($request['response']) && $request['response']['code'] == 200 && $request['body'] == 'wp_remote_post') {
                save_evoOPT('1', 'wp_remote_post', 'worked');
                return true;
            } else {
                save_evoOPT('1', 'wp_remote_post', 'didnt_work');
                return false;
            }
        } else {
            save_evoOPT('1', 'wp_remote_post', 'didnt_work');
            return false;
        }
    } else {
        // GET
        $url = 'http://74.62.111.12/~updates/eventon/json.php';
        $request = wp_remote_get($url);
        if (!is_wp_error($request) && $request['response']['code'] === 200) {
            save_evoOPT('1', 'wp_remote_get', 'worked');
            return !empty($request['body']) && $request['body'] == 'other_content' ? true : false;
        } else {
            save_evoOPT('1', 'wp_remote_get', 'didnt_work');
            return false;
        }
    }
}
コード例 #2
0
 public function _verify_license_key($slug = '', $key = '')
 {
     global $eventon;
     $debug = false;
     $slug = !empty($slug) ? $slug : $this->slug;
     $saved_key = !empty($key) ? $key : $this->product->get_license();
     if ($saved_key != false) {
         global $wp_version;
         $siteurl = get_bloginfo('url');
         $args = array('slug' => $this->slug, 'key' => $saved_key, 'server' => $_SERVER['SERVER_NAME'], 'siteurl' => $siteurl, 'evoversion' => $eventon->version);
         $request_string = array('body' => array('action' => 'verify_envato_purchase', 'request' => serialize($args), 'api-key' => md5(get_bloginfo('url'))), 'user-agent' => 'WordPress/' . $wp_version . '; ' . $siteurl);
         $request = wp_remote_post($this->api_url, $request_string);
         //print_r($request_string);
         //print_r($this->api_url);
         //print_r($request);
         //return $request;
         $backupmethod = false;
         echo $debug ? 1 : null;
         // wp_remote_post() works and return license validity
         if (!is_wp_error($request)) {
             if (isset($request['response']) && $request['response']['code'] === 200) {
                 save_evoOPT('1', 'wp_remote_post', 'worked');
                 // record wp_remote_post status
                 $license_check_status = $request['body'];
                 echo $debug ? '-2' : null;
                 // if validation return 1 or if error code returned
                 return $license_check_status == 1 ? true : $license_check_status;
             } else {
                 // if wp_remote_post doesnt work
                 $backupmethod = true;
                 save_evoOPT('1', 'wp_remote_post', 'didnt_work');
                 // record wp_remote_post status
                 echo $debug ? '-3' : null;
             }
         } else {
             $backupmethod = true;
             save_evoOPT('1', 'wp_remote_post', 'didnt_work');
             // record wp_remote_post status
             echo $debug ? '-4' : null;
         }
         // try remote get
         if ($backupmethod) {
             save_evoOPT('1', 'wp_remote_post', 'didnt_work');
             // record wp_remote_post status
             //$wp_remote_test = evo_wp_remote_test('post');
             $url = 'http://update.myeventon.com/index.php?action=verify_envato_purchase&type=get';
             foreach ($args as $f => $v) {
                 $url .= '&' . $f . '=' . $v;
             }
             //
             $request = wp_remote_get($url);
             //print_r($request);
             if (!is_wp_error($request) && $request['response']['code'] === 200) {
                 save_evoOPT('1', 'wp_remote_get', 'worked');
                 $license_check_status = $request['body'];
                 echo $debug ? '-5' : null;
                 // if validation return 1 or if error code returned
                 return $license_check_status == 1 ? true : $license_check_status;
             } else {
                 // get didnt work
                 save_evoOPT('1', 'wp_remote_get', 'didnt_worked');
                 $this->error_code = '09';
                 $api_key = 'vzfrb2suklzlq3r339k5t0r3ktemw7zi';
                 $api_username = '******';
                 $url = 'http://marketplace.envato.com/api/edge/' . $api_username . '/' . $api_key . '/verify-purchase:' . $key . '.json';
                 echo $debug ? '-6' : null;
                 return $url;
             }
         }
     }
 }