PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / extensions / divi_5_amelia / divi-5-amelia.php
ameliabooking / extensions / divi_5_amelia Last commit date
server 2 days ago visual-builder 2 days ago divi-5-amelia.php 2 days ago
divi-5-amelia.php
211 lines
1 <?php
2
3 /*
4 Plugin Name: Divi 5 Amelia Booking
5 Plugin URI: https://wpamelia.com
6 Description: Divi 5 integration for Amelia Booking Plugin
7 Version: 1.0.0
8 Author: Melograno Ventures
9 Author URI: https://wpamelia.com
10 License: GPL2
11 License URI: https://www.gnu.org/licenses/gpl-2.0.html
12 phpcs:disable PSR1.Files.SideEffects
13 */
14
15 use AmeliaBooking\Infrastructure\Licence\Licence;
16 use AmeliaBooking\Infrastructure\WP\GutenbergBlock\GutenbergBlock;
17 use AmeliaBooking\Infrastructure\WP\ShortcodeService\ShortcodeAliasService;
18
19 if (!defined('ABSPATH')) {
20 die('Direct access forbidden.');
21 }
22
23 // Setup constants.
24 define('DIVI5_AMELIA_PATH', plugin_dir_path(__FILE__));
25 define('DIVI5_AMELIA_URL', plugin_dir_url(__FILE__));
26 define('DIVI5_AMELIA_VERSION', '1.0.0');
27
28
29 /**
30 * Load Divi 5 modules on init
31 * This ensures modules are registered for both Visual Builder and Frontend
32 */
33 function divi5_amelia_load_modules()
34 {
35 // Only load if Divi 5 is available
36 if (function_exists('et_builder_d5_enabled') && et_builder_d5_enabled()) {
37 // Load Divi 5 modules - this registers them for conversion and rendering
38 require_once DIVI5_AMELIA_PATH . 'server/index.php';
39 }
40 }
41
42 // Load modules early so they're available for conversion
43 add_action('after_setup_theme', 'divi5_amelia_load_modules', 20);
44
45 /**
46 * Enqueue Divi 5 Visual Builder Assets
47 */
48 function divi5_amelia_enqueue_visual_builder_assets()
49 {
50 if (et_core_is_fb_enabled() && function_exists('et_builder_d5_enabled') && et_builder_d5_enabled()) {
51 \ET\Builder\VisualBuilder\Assets\PackageBuildManager::register_package_build(
52 [
53 'name' => 'divi-5-amelia-visual-builder',
54 'version' => DIVI5_AMELIA_VERSION,
55 'script' => [
56 'src' => DIVI5_AMELIA_URL . 'visual-builder/build/divi-5-amelia.js',
57 'deps' => [
58 'react',
59 'jquery',
60 'divi-module-library',
61 'wp-hooks',
62 'divi-rest',
63 ],
64 'enqueue_top_window' => false,
65 'enqueue_app_window' => true,
66 ],
67 ]
68 );
69 }
70 }
71
72 add_action('divi_visual_builder_assets_before_enqueue_scripts', 'divi5_amelia_enqueue_visual_builder_assets');
73
74 /**
75 * Add Amelia data to Visual Builder window
76 */
77 function divi5_amelia_add_inline_data()
78 {
79 if (et_core_is_fb_enabled() && function_exists('et_builder_d5_enabled') && et_builder_d5_enabled()) {
80 // Get Amelia entities data
81 $ameliaData = GutenbergBlock::getEntitiesData();
82 $entitiesData = isset($ameliaData['data']) ? $ameliaData['data'] : [];
83
84 // Prepare options for the Visual Builder
85 $ameliaOptions = [
86 'categories' => [['value' => '0', 'label' => 'Show All Categories']],
87 'services' => [['value' => '0', 'label' => 'Show All Services']],
88 'employees' => [['value' => '0', 'label' => 'Show All Employees']],
89 'locations' => [['value' => '0', 'label' => 'Show All Locations']],
90 'packages' => [['value' => '0', 'label' => 'Show All Packages']],
91 'events' => [['value' => '0', 'label' => 'Show All Events']],
92 'tags' => [['value' => '0', 'label' => 'Show All Tags']],
93 ];
94
95 // Add categories
96 if (!empty($entitiesData['categories'])) {
97 foreach ($entitiesData['categories'] as $category) {
98 $ameliaOptions['categories'][] = [
99 'value' => (string)$category['id'],
100 'label' => $category['name'] . ' (id: ' . $category['id'] . ')'
101 ];
102 }
103 }
104
105 // Add services
106 if (!empty($entitiesData['servicesList'])) {
107 foreach ($entitiesData['servicesList'] as $service) {
108 if ($service) {
109 $ameliaOptions['services'][] = [
110 'value' => (string)$service['id'],
111 'label' => $service['name'] . ' (id: ' . $service['id'] . ')'
112 ];
113 }
114 }
115 }
116
117 // Add employees
118 if (!empty($entitiesData['employees'])) {
119 foreach ($entitiesData['employees'] as $employee) {
120 $ameliaOptions['employees'][] = [
121 'value' => (string)$employee['id'],
122 'label' => $employee['firstName'] . ' ' . $employee['lastName'] . ' (id: ' . $employee['id'] . ')'
123 ];
124 }
125 }
126
127 // Add locations
128 if (!empty($entitiesData['locations'])) {
129 foreach ($entitiesData['locations'] as $location) {
130 $ameliaOptions['locations'][] = [
131 'value' => (string)$location['id'],
132 'label' => $location['name'] . ' (id: ' . $location['id'] . ')'
133 ];
134 }
135 }
136
137 // Add packages
138 if (!empty($entitiesData['packages'])) {
139 foreach ($entitiesData['packages'] as $package) {
140 $ameliaOptions['packages'][] = [
141 'value' => (string)$package['id'],
142 'label' => $package['name'] . ' (id: ' . $package['id'] . ')'
143 ];
144 }
145 }
146
147 // Add events
148 if (!empty($entitiesData['events'])) {
149 foreach ($entitiesData['events'] as $event) {
150 $ameliaOptions['events'][] = [
151 'value' => (string)$event['id'],
152 'label' => $event['name'] . ' (id: ' . $event['id'] . ') - ' . $event['formattedPeriodStart']
153 ];
154 }
155 }
156
157 // Add tags
158 if (!empty($entitiesData['tags'])) {
159 foreach ($entitiesData['tags'] as $tag) {
160 $ameliaOptions['tags'][] = [
161 'value' => $tag['name'],
162 'label' => $tag['name']
163 ];
164 }
165 }
166
167 // Add ivy forms
168 if (!empty($entitiesData['ivy'])) {
169 foreach ($entitiesData['ivy'] as $ivy) {
170 $ameliaOptions['ivy'][] = [
171 'value' => (string)$ivy['value'],
172 'label' => $ivy['label']
173 ];
174 }
175 }
176
177 // Output inline script that will run in the Visual Builder iframe
178 ?>
179 <script type="text/javascript">
180 window.ameliaDivi5Data = <?php echo wp_json_encode($ameliaOptions); ?>;
181 window.wpAmeliaLabels = <?php echo wp_json_encode(GutenbergBlock::getBlockStrings()); ?>;
182 window.wpAmeliaUseNeutralShortcodes = <?php echo wp_json_encode(ShortcodeAliasService::shouldUseNeutralShortcodes()); ?>;
183 window.wpAmeliaShortcodeAliases = <?php echo wp_json_encode(ShortcodeAliasService::getAliases()); ?>;
184 window.wpAmeliaPluginName = <?php echo wp_json_encode(ShortcodeAliasService::getWhiteLabelPluginName()); ?>;
185 window.wpAmeliaBuilderBrandName = <?php echo wp_json_encode(ShortcodeAliasService::getBuilderBrandName()); ?>;
186 window.wpAmeliaPluginImage = <?php echo wp_json_encode(ShortcodeAliasService::getWhiteLabelPluginImage()); ?>;
187 window.isAmeliaLite = <?php echo wp_json_encode(!Licence::$premium); ?>;
188 window.ameliaLicence = <?php echo wp_json_encode(Licence::getLicence()); ?>;
189 window.ameliaStepBookingPreview = <?php echo wp_json_encode([
190 'desktop' => AMELIA_URL . 'public/img/shortcode/sbs-preview.svg',
191 'mobile' => AMELIA_URL . 'public/img/shortcode/sbs-mobile-preview.svg',
192 ]); ?>;
193 window.ameliaCatalogBookingPreview = <?php echo wp_json_encode([
194 'desktop' => AMELIA_URL . 'public/img/shortcode/cbf-preview.svg',
195 'mobile' => AMELIA_URL . 'public/img/shortcode/cbf-mobile-preview.svg',
196 ]); ?>;
197 window.ameliaEventsListBookingPreview = <?php echo wp_json_encode([
198 'desktop' => AMELIA_URL . 'public/img/shortcode/elf-preview.svg',
199 'mobile' => AMELIA_URL . 'public/img/shortcode/elf-mobile-preview.svg',
200 ]); ?>;
201 window.ameliaEventsCalendarBookingPreview = <?php echo wp_json_encode([
202 'desktop' => AMELIA_URL . 'public/img/shortcode/ecf-preview.svg',
203 'mobile' => AMELIA_URL . 'public/img/shortcode/ecf-mobile-preview.svg',
204 ]); ?>;
205 </script>
206 <?php
207 }
208 }
209
210 add_action('et_fb_framework_loaded', 'divi5_amelia_add_inline_data');
211