wp_create_nonce('calendar_events_nonce'), 'ajaxurl' => admin_url('admin-ajax.php'), 'svgIcon' => App::getInstance('url.assets') . 'images/fluentbooking.svg' )); } private function getCalendarEvents($selectedCalId = '') { if (empty($selectedCalId)) { return []; } $calendar = Calendar::with(['events' => function ($query) { $query->where('status', 'active'); }])->find($selectedCalId); if (!$calendar) { return []; } $formattedData = []; foreach ($calendar->events as $event) { $formattedData[$event->id] = $event->title; } return $formattedData; } public function addElementorCategory() { \Elementor\Plugin::instance()->elements_manager->add_category('fluentbooking', [ 'title' => __('FluentBooking', 'fluent-booking-pro'), ], 1); } /** * @throws \Exception */ public function registerWidget() { $this->includeWidgets(); $this->registerWidgets(); } /** * @throws \Exception */ public function includeWidgets() { $this->loadFile('/Widgets/FcalCalendarEvent.php'); $this->loadFile('/Widgets/FcalBookings.php'); $this->loadFile('/Widgets/FcalCalendar.php'); } /** * @throws \Exception */ public function registerControl($controls_manager) { $this->loadFile('/Controls/FluentBookingCustomGroupSelect.php'); $this->registerFluentBookingCustomGroupSelect($controls_manager); } public function ajaxGetCalendarEvents() { if (!isset($_POST['security']) || !wp_verify_nonce($_POST['security'], 'calendar_events_nonce')) { wp_send_json_error(['message' => __('Nonce verification failed', 'fluent-booking-pro')]); exit; } if (!isset($_POST['cal_id'])) { wp_send_json_error(['message' => __('No calendar ID provided', 'fluent-booking-pro')]); } $calId = intval($_POST['cal_id']); $events = []; // Fetch events using your getCalendarEvents method or similar // Example of fetching events (you need to replace this with your actual method) $events = $this->getCalendarEvents($calId); wp_send_json_success($events); } public function registerWidgets() { \Elementor\Plugin::instance()->widgets_manager->register(new \FluentBooking\App\Services\Integrations\Elementor\Widgets\FcalCalendarEvent()); \Elementor\Plugin::instance()->widgets_manager->register(new \FluentBooking\App\Services\Integrations\Elementor\Widgets\FcalBookings()); \Elementor\Plugin::instance()->widgets_manager->register(new \FluentBooking\App\Services\Integrations\Elementor\Widgets\FcalCalendar()); } /** * @throws \Exception */ private function loadFile($relativePath) { $filePath = __DIR__ . $relativePath; if (file_exists($filePath)) { require_once($filePath); } else { throw new \Exception(sprintf(__("File not found: %s", "fluent-booking-pro"), $filePath)); } } private function registerFluentBookingCustomGroupSelect($controls_manager) { $control = new \FluentBookingCustomGroupSelect(); \Elementor\Plugin::instance()->controls_manager->register($control, 'fcal_group_select'); } }