# fluent-booking/2.4.0/app/Hooks/Handlers/DataImporter.php

Fluent Booking – The Ultimate Appointments Scheduling, Events Booking, Events Calendar Solution, version 2.4.0. 81 lines.

- Page: https://pluginprobe.com/plugins/fluent-booking/2.4.0/code/app/Hooks/Handlers/DataImporter.php
- Raw: https://pluginprobe.com/plugins/fluent-booking/2.4.0/raw/app/Hooks/Handlers/DataImporter.php
- Modified: 2026-09-09T13:29:18+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/fluent-booking/2.4.0/code/app/Hooks/Handlers/DataImporter.php#L10-L20`.

```php
<?php

namespace FluentBooking\App\Hooks\Handlers;

use FluentBooking\App\App;
use FluentBooking\App\Services\CalendarService;
use FluentBooking\App\Services\PermissionManager;

class DataImporter
{
    public function importCalendar()
    {
        if (!$this->verifyNonce()) {
            wp_send_json_error([
                'message' => __('Security check failed. Please refresh and try again.', 'fluent-booking'),
            ]);
        }

        if (!PermissionManager::userCan(['manage_all_data', 'manage_other_calendars'])) {
            wp_send_json_error([
                'message' => __('You are not authorized to import calendar', 'fluent-booking'),
            ]);
        }

        $app = App::getInstance();

        $data = $app->request->all();

        if (empty($data['type']) || empty($data['user_id']) || empty($data['author_timezone'])) {
            wp_send_json_error([
                'message' => __('Please provide all required data', 'fluent-booking'),
            ]);
        }

        $file = $app->request->file('file');

        if (empty($file) || $file->getClientOriginalExtension() != 'json') {
            wp_send_json_error([
                'message' => __('Invalid file. Please provide a valid JSON file', 'fluent-booking'),
            ]);
        }

        $fileContent = $file->getContents();

        $calendarData = wp_parse_args($data, json_decode($fileContent, true));

        if (empty($calendarData)) {
            wp_send_json_error([
                'message' => __('Invalid file. Please provide a valid JSON file', 'fluent-booking'),
            ]);
        }

        $useCurrentUser = !PermissionManager::userCan('manage_all_data');

        $calendar = CalendarService::createCalendar($calendarData, $useCurrentUser, true);

        if (is_wp_error($calendar)) {
            wp_send_json_error([
                'message' => $calendar->get_error_message(),
            ]);
        }

        wp_send_json([
            'success'  => true,
            'message'  => __('Calendar imported successfully', 'fluent-booking'),
        ]);
    }

    /**
     * Verify the request nonce for AJAX actions.
     *
     * @return bool
     */
    private function verifyNonce()
    {
        $nonce = isset($_REQUEST['nonce']) ? sanitize_text_field(wp_unslash($_REQUEST['nonce'])) : '';

        return !empty($nonce) && wp_verify_nonce($nonce, 'fluent-booking');
    }
}

```
