get_error_code(), $createdCalendar->get_error_message()); } return $createdCalendar; } /* * Import host data from JSON URL * @param string $jsonUrl JSON URL * @param bool $useCurrentUser If true, the current user will be used as the host * @return \FluentBooking\App\Models\Calendar|\WP_Error */ public function importHostByJSONUrl($jsonUrl, $useCurrentUser = true) { $response = wp_safe_remote_get($jsonUrl, [ 'timeout' => 30, 'headers' => [ 'Accept' => 'application/json' ] ]); if (is_wp_error($response)) { return $response; } // check if the status code is not 200 if (wp_remote_retrieve_response_code($response) !== 200) { return new \WP_Error('invalid_response', 'Invalid response from the server'); } $body = json_decode(wp_remote_retrieve_body($response), true); return $this->importHostJson($body, $useCurrentUser); } }