/**
  * Returns an array of a specific producers events formatted for the CLNDR.
  * @param  string  $client_id The Client ID of the producer you wish
  *                            to get the events of.
  * @param  boolean $dates     Get prices? Default is false.
  * @param  boolean $prices    Get Prices? Default is false.
  * @return json               The JSON string of the event Data.
  */
 public static function get_events()
 {
     $get = filter_input_array(INPUT_GET, FILTER_SANITIZE_ENCODED);
     $nonce = $get['nonce'];
     $widget_instance = $get['widgetID'];
     Utilities::check_nonce($nonce, 'bpt-calendar-widget-nonce');
     if (isset($get['clientID'])) {
         $client_id = $get['clientID'];
     } else {
         $client_id = get_option('_bpt_client_id');
     }
     if (!$client_id) {
         wp_send_json(array('success' => false, 'error' => 'No client ID.'));
     }
     if (!$widget_instance) {
         wp_send_json(array('success' => false, 'error' => 'No widget ID.'));
     }
     if (!Utilities::cache_enabled()) {
         $events = new Api();
         wp_send_json($events->get_events($client_id));
     }
     if (get_transient('_bpt_calendar_events_' . $widget_instance) === false && Utilities::cache_enabled()) {
         $events = new Api();
         set_transient('_bpt_calendar_events_' . $widget_instance, $events->get_events($client_id), Utilities::cache_time());
     }
     wp_send_json(get_transient('_bpt_calendar_events_' . $widget_instance));
 }
 public static function get_account()
 {
     $get = filter_input_array(INPUT_GET, FILTER_SANITIZE_ENCODED);
     Utilities::check_nonce($get['nonce'], self::$nonce_title);
     $account_info = false;
     if (Utilities::cache_enabled()) {
         if (!get_transient('_bpt_user_account_info')) {
             $account = new Api();
             $account_info = $account->get_account();
             set_transient('_bpt_user_account_info', $account_info, 0);
         }
         $account_info = get_transient('_bpt_user_account_info');
     } else {
         $account = new Api();
         $account_info = $account->get_account();
     }
     wp_send_json($account_info);
 }
 /**
  * Get the Events
  */
 public static function get_events()
 {
     $get = filter_input_array(INPUT_GET, FILTER_SANITIZE_ENCODED);
     $nonce = $get['nonce'];
     $post_id = null;
     $client_id = null;
     $event_id = null;
     $widget_id = null;
     if (isset($get['postID'])) {
         $post_id = $get['postID'];
     }
     if (isset($get['clientID'])) {
         $client_id = $get['clientID'];
     }
     if (isset($get['eventID'])) {
         $event_id = $get['eventID'];
     }
     if (isset($get['widgetID'])) {
         $widget_id = $post['widgetID'];
     }
     Utilities::check_nonce($nonce, self::$nonce_title);
     $events = new Api();
     if (!Utilities::cache_enabled()) {
         $events = $events->get_events($client_id, $event_id);
         $events = self::sort_events($events);
         $events = self::apply_price_options($events);
         wp_send_json($events, true);
     }
     if (!get_transient('_bpt_event_list_events' . $post_id)) {
         set_transient('_bpt_event_list_events' . $post_id, $events->get_events($client_id, $event_id), Utilities::cache_time());
     }
     $events = get_transient('_bpt_event_list_events' . $post_id);
     if ($event_id) {
         $single_event = self::get_single_event($event_id, $events);
         if (!$single_event) {
             wp_send_json(array('success' => false, 'error' => 'Could not find event.'));
         }
         $events = array($single_event);
     }
     $events = self::sort_events($events);
     $events = self::apply_price_options($events);
     wp_send_json($events);
 }