示例#1
0
        // Setup variable for wp_remote_post.
        $post = array('headers' => $headers, 'body' => $body);
        // Perform the query and retrieve the response.
        $response = wp_remote_post('http://optinmonster.com/', $post);
        $response_code = wp_remote_retrieve_response_code($response);
        $response_body = wp_remote_retrieve_body($response);
        // Bail out early if there are any errors.
        if (200 != $response_code || is_wp_error($response_body)) {
            return false;
        }
        // Return the json decoded content.
        return json_decode($response_body);
    }
    /**
     * Returns the singleton instance of the class.
     *
     * @since 2.0.0
     *
     * @return object The Optin_Monster_License object.
     */
    public static function get_instance()
    {
        if (!isset(self::$instance) && !self::$instance instanceof Optin_Monster_License) {
            self::$instance = new Optin_Monster_License();
        }
        return self::$instance;
    }
}
// Load the license class.
$optin_monster_license = Optin_Monster_License::get_instance();
示例#2
0
文件: menu.php 项目: venturepact/blog
 /**
  * Pings the remote server for addons data.
  *
  * @since 2.0.0
  *
  * @param string $key The user license key.
  * @return bool|array False if no key or failure, array of addon data otherwise.
  */
 public function get_addons_data($key)
 {
     $addons = Optin_Monster_License::get_instance()->perform_remote_request('get-addons-data', array('tgm-updater-key' => $key));
     // If there was an API error, set transient for only 10 minutes.
     if (!$addons) {
         set_transient('_om_addons', false, 10 * MINUTE_IN_SECONDS);
         return false;
     }
     // If there was an error retrieving the addons, set the error.
     if (isset($addons->error)) {
         set_transient('_om_addons', false, 10 * MINUTE_IN_SECONDS);
         return false;
     }
     // Otherwise, our request worked. Save the data and return it.
     set_transient('_om_addons', $addons, DAY_IN_SECONDS);
     return $addons;
 }