Plugin Directory

Changeset 2042292


Ignore:
Timestamp:
03/01/2019 04:24:16 PM (7 years ago)
Author:
toddhuish
Message:

Update with wp_remote_request() instead of curl()

Location:
chargify/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • chargify/trunk/chargify.php

    r1657870 r2042292  
    55Description: Manage subscriptions to WordPress using the Chargify API
    66Author: Subscription Tools - Programming by 9seeds
    7 Version: 2.0.10
     7Version: 2.1
    88Author URI: http://9seeds.com/plugins
    99*/
  • chargify/trunk/lib/ChargifyConnector.php

    r1652566 r2042292  
    259259  protected function sendRequest($uri, $post_xml = null,$method = null) {   
    260260    $apiUrl = "https://{$this->active_domain}.chargify.com{$uri}";
    261     $ch = curl_init();
    262     curl_setopt($ch, CURLOPT_URL, $apiUrl);
    263     curl_setopt($ch, CURLOPT_USERPWD,$this->active_api_key.':x');
    264     curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    265     curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
    266     curl_setopt($ch, CURLOPT_HEADER , 0);
    267     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    268     curl_setopt ($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
     261
     262    $args = array(
     263        'headers' => array(
     264            'Authorization' => 'Basic ' . base64_encode( $this->active_api_key . ':x')
     265        ),
     266        'method' => 'GET'
     267    );
    269268
    270269    if($method == 'put')
    271270    {
    272         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
     271        $args['method'] = 'PUT';
    273272    }
    274273    if($post_xml)
    275274    {
    276         curl_setopt($ch, CURLOPT_POST, 1);
    277         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml);
    278         curl_setopt($ch, CURLOPT_HTTPHEADER , array('Content-Type: application/xml'));
     275        $args['body'] = $post_xml;
     276        $args['headers']['Content-Type'] = 'application/xml';
    279277    }
    280278    if($method == 'delete')
    281279    {
    282         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
    283     }
    284     curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    285     $xml = curl_exec($ch);
     280        $args['method'] = 'DELETE';
     281    }
     282    $error = false;
     283
     284    $response = wp_remote_request( $apiUrl, $args );
     285    $response_code = wp_remote_retrieve_response_code( $response );
    286286   
    287     curl_close($ch);
    288287   
     288    if(substr($response_code,0,1) != 2){
     289        $error = wp_remote_retrieve_body($response);
     290        $xml = '<error>'.$error.'</error>';
     291    } else {
     292        $xml = wp_remote_retrieve_body($response);
     293    }
    289294    libxml_use_internal_errors(true);
    290295    $sxe = simplexml_load_string($xml);
    291296    if (!$sxe) { $xml = '<error>'.$xml.'</error>'; }
    292297
     298
    293299    return $xml;
    294300  }
  • chargify/trunk/readme.txt

    r1657870 r2042292  
    44Tags: Chargify, subscription, registration, tools, membership
    55Requires at least: 2.9
    6 Tested up to: 4.7.4
    7 Stable Tag: 2.0.10
     6Tested up to: 5.1
     7Stable Tag: 2.1
    88
    99WP-Chargify allows users to integrate the Chargify service with WordPress.
     
    4444
    4545== Changelog ==
     46= 2.1 =
     47* Test up to WP 5.1
     48* Change hard curl calls to wp_remote_request
     49
    4650= 2.0.10 =
    4751* Fix versioning
Note: See TracChangeset for help on using the changeset viewer.