public static function init()
 {
     $api_key = 'AIzaSyBm67QlIFxjuE34SG9Yy45mQizI4zVieUc';
     self::$api_key = $api_key;
 }
 public static function sync_Google_calendar_events()
 {
     $data = array();
     $google_events = TMM_GoogleCalendar::getEventsList();
     $custom_events = get_posts(array('numberposts' => -1, 'meta_key' => 'google_calendar_event_id', 'meta_value' => '', 'meta_compare' => '!=', 'post_type' => 'event', 'post_status' => 'publish'));
     //return $custom_events;
     if (!empty($google_events)) {
         foreach ($google_events as $key => $value) {
             $fields = array();
             $new_post_id = false;
             $new_post = array('post_title' => isset($value->summary) ? $value->summary : '', 'post_name' => isset($value->summary) ? sanitize_title($value->summary) : '', 'post_excerpt' => isset($value->description) ? $value->description : '', 'post_status' => 'publish', 'post_type' => 'event');
             $new_post_id = wp_insert_post($new_post);
             if ($new_post_id) {
                 $start = '';
                 $end = '';
                 $start_hh = 0;
                 $start_mm = 0;
                 $end_hh = 0;
                 $end_mm = 0;
                 //$duration_sec = '';
                 if (isset($value->start->date)) {
                     $start = $value->start->date;
                 } else {
                     if (isset($value->start->dateTime)) {
                         $temp_time = strtotime($value->start->dateTime);
                         $start = date('Y-m-d', $temp_time);
                         $start_hh = date('h', $temp_time);
                         $start_mm = date('i', $temp_time);
                     }
                 }
                 if (isset($value->end->date)) {
                     $end = $value->end->date;
                 } else {
                     if (isset($value->end->dateTime)) {
                         $temp_time = strtotime($value->end->dateTime);
                         $end = date('Y-m-d', $temp_time);
                         $end_hh = date('h', $temp_time);
                         $end_mm = date('i', $temp_time);
                     }
                 }
                 $start_time = strtotime($start);
                 $end_time = strtotime($end);
                 $fields['post_id'] = $new_post_id;
                 $fields['event_date'] = $start;
                 $fields['event_end_date'] = $end;
                 $fields['event_hh'] = $start_hh;
                 $fields['event_mm'] = $start_mm;
                 $fields['event_end_hh'] = $end_hh;
                 $fields['event_end_mm'] = $end_mm;
                 $fields['event_place_address'] = isset($value->location) ? $value->location : '';
                 $fields['google_calendar_event_id'] = $value->id;
                 self::save_post($fields);
                 $data[] = $fields;
             }
         }
     }
     return $data;
 }