Exemplo n.º 1
0
 /**
  * Used from an external API call to wp admin ajax to handle
  * freemius installations and uninstallations
  *
  */
 public static function maybe_a_freemius_webhook()
 {
     $input = @file_get_contents('php://input');
     $event_json = json_decode($input);
     if (!isset($event_json->id)) {
         self::ajax_fail('Hey man! This be no webhook.');
         exit;
     }
     require_once EDD_SEGMENT_PATH . '/controllers/add-ons/freemius-sdk/Freemius.php';
     $fs = new Freemius_Api('plugin', EDD_SEG_IO_FREEMIUS_PLUGIN_ID, EDD_SEG_IO_FREEMIUS_PUBLIC_KEY, EDD_SEG_IO_FREEMIUS_PRIVATE_KEY);
     $fs_event = $fs->Api("/events/{$event_json->id}.json");
     $props = array('email' => $fs_event->objects->user->email, 'name' => $fs_event->objects->user->first . ' ' . $fs_event->objects->user->last, 'site_url' => $fs_event->objects->install->url);
     switch ($fs_event->type) {
         case 'install.installed':
             self::new_install($props);
             break;
         case 'install.uninstalled':
             $fs_uninstall = $fs->Api("/installs/{$fs_event->install_id}/uninstall.json");
             $props['uninstall_code'] = $fs_uninstall->reason_id;
             $props['uninstall_reason'] = $fs_uninstall->reason;
             $props['uninstall_reason_info'] = $fs_uninstall->reason_info;
             self::new_uninstall($props);
             break;
     }
     http_response_code(200);
     exit;
 }
Exemplo n.º 2
0
 /**
  * Override API call to enable retry with servers' clock auto sync method.
  *
  * @param string $path
  * @param string $method
  * @param array  $params
  * @param bool   $retry Is in retry or first call attempt.
  *
  * @return array|mixed|string|void
  */
 private function _call($path, $method = 'GET', $params = array(), $retry = false)
 {
     $this->_logger->entrance();
     $result = $this->_api->Api($path, $method, $params);
     if (null !== $result && isset($result->error) && 'request_expired' === $result->error->code) {
         if (!$retry) {
             // Try to sync clock diff.
             if (false !== $this->_sync_clock_diff()) {
                 return $this->_call($path, $method, $params, true);
             }
         }
     }
     if (null !== $result && isset($result->error)) {
         // Log API errors.
         $this->_logger->error($result->error->message);
     }
     return $result;
 }
Exemplo n.º 3
0
 /**
  * Override API call to enable retry with servers' clock auto sync method.
  *
  * @param string $path
  * @param string $method
  * @param array  $params
  * @param bool   $retry Is in retry or first call attempt.
  *
  * @return array|mixed|string|void
  */
 private function _call($path, $method = 'GET', $params = array(), $retry = false)
 {
     $this->_logger->entrance($method . ':' . $path);
     if (self::is_temporary_down()) {
         $result = $this->get_temporary_unavailable_error();
     } else {
         $result = $this->_api->Api($path, $method, $params);
         if (null !== $result && isset($result->error) && isset($result->error->code) && 'request_expired' === $result->error->code) {
             if (!$retry) {
                 $diff = isset($result->error->timestamp) ? time() - strtotime($result->error->timestamp) : false;
                 // Try to sync clock diff.
                 if (false !== $this->_sync_clock_diff($diff)) {
                     // Retry call with new synced clock.
                     return $this->_call($path, $method, $params, true);
                 }
             }
         }
     }
     if (null !== $result && isset($result->error) && isset($result->error->message)) {
         // Log API errors.
         $this->_logger->error($result->error->message);
     }
     return $result;
 }
 * @since       1.0.3
 */
// Retrieve the request's body and parse it as JSON
$input = @file_get_contents("php://input");
$event_json = json_decode($input);
if (!isset($event_json->id)) {
    http_response_code(200);
    exit;
}
/**
 * Freemius PHP SDK can be downloaded from GitHub:
 *  https://github.com/Freemius/php-sdk
 */
require_once '/path/to/freemius/sdk/Freemius.php';
$fs = new Freemius_Api('plugin', 'YOUR_PLUGIN_ID', 'YOUR_PLUGIN_PUBLIC_KEY', 'YOUR_PLUGIN_SECRET_KEY');
$fs_event = $fs->Api("/events/{$event_json->id}.json");
switch ($fs_event->type) {
    case 'install.installed':
        $user = $fs_event->objects->user;
        $email = $user->email;
        $first = $user->first;
        $last = $user->last;
        /**
         * MailChimp SDK for API v3  can be downloaded from here:
         *  https://github.com/drewm/mailchimp-api
         */
        require_once '/path/to/mailchimp-api/api-v3/MailChimp.php';
        // Subscribe to mailchimp list.
        $blog_subscribers_list = 'LIST_ID';
        $mc = new MailChimp('API_KEY');
        $result = $mc->post("lists/{$blog_subscribers_list}/members", array('email_address' => $email, 'status' => 'subscribed', 'merge_fields' => array('FNAME' => $first, 'LNAME' => $last)));