PluginProbe ʕ •ᴥ•ʔ
Zenchef widget integration / 1.2.0
Zenchef widget integration v1.2.0
1.3.0 1.0.1 1.2.0 trunk 1.0.0
zenchef-widget-integration / src / Widget / Backoffice / add_settings_page.php
zenchef-widget-integration / src / Widget / Backoffice Last commit date
add_settings_page.php 2 months ago load_settings_page_assets.php 2 months ago register_settings.php 2 months ago remove_settings.php 2 years ago
add_settings_page.php
223 lines
1 <?php
2
3 namespace Zenchef\Widget\Widget\Backoffice;
4
5 use function _x;
6 use function add_options_page;
7 use function add_settings_field;
8 use function add_settings_section;
9 use function array_merge;
10 use function Zenchef\Widget\Backoffice\resolve_field_type_template;
11 use function Zenchef\Widget\View\render;
12 use function Zenchef\Widget\Widget\get_widget_settings;
13 use const Zenchef\Widget\SETTINGS_GROUP_SLUG;
14 use const Zenchef\Widget\SETTINGS_OPTION_NAME;
15
16 /**
17 * @return void
18 */
19 function add_settings_page()
20 {
21 $page_slug = 'zenchef.widget.settings_page';
22
23 add_options_page(
24 _x('Zenchef widget settings', 'widget.backoffice.settings_page.title', 'zenchef-widget-integration'),
25 _x('Zenchef widget', 'widget.backoffice.settings_page.menu_label', 'zenchef-widget-integration'),
26 'manage_options',
27 $page_slug,
28 static function () use ($page_slug) {
29 return render('backoffice/settings_page', [
30 'settings_group_slug' => SETTINGS_GROUP_SLUG,
31 'page_slug' => $page_slug,
32 ]);
33 }
34 );
35
36 $sections = build_settings_sections();
37 $current_settings_values = get_widget_settings();
38
39 foreach ($sections as $section_id => $section) {
40
41 add_settings_section(
42 $section_id,
43 $section['title'],
44 static function () {},
45 $page_slug
46 );
47
48 foreach ($section['fields'] as $id => $field) {
49 $template = resolve_field_type_template($field['type']);
50
51 $template_parameters = array_merge(
52 ['description' => '', 'checkbox_label' => ''],
53 $field['template_parameters'],
54 [
55 'id' => $id,
56 'value' => $current_settings_values[$id],
57 ]
58 );
59
60 add_settings_field(
61 $id,
62 $field['label'],
63 static function () use ($template, $template_parameters) {
64 return render($template, $template_parameters);
65 },
66 $page_slug,
67 $section_id
68 );
69 }
70 }
71 }
72
73 /**
74 * @return array
75 */
76 function build_settings_sections()
77 {
78 return [
79 'zenchef.widget.restaurant_section' => [
80 'title' => _x('Restaurant', 'widget.backoffice.settings_page.restaurant_section_title', 'zenchef-widget-integration'),
81 'fields' => [
82 'restaurant_id' => [
83 'label' => _x('Restaurant ID', 'widget.backoffice.settings_page.restaurant_input_label', 'zenchef-widget-integration'),
84 'type' => 'text',
85 'template_parameters' => [
86 'description' => _x(
87 'ID of your Zenchef restaurant. You can find this ID in the Zenchef dashboard.',
88 'widget.backoffice.settings_page.restaurant_input_description',
89 'zenchef-widget-integration'
90 ),
91 ],
92 ],
93 'language' => [
94 'label' => _x('Language', 'widget.backoffice.settings_page.language_input_label', 'zenchef-widget-integration'),
95 'type' => 'select',
96 'template_parameters' => [
97 'description' => _x(
98 'Force a language for the booking widget. Leave on "Use Zenchef OS default" to follow the restaurant\'s configured language.',
99 'widget.backoffice.settings_page.language_input_description',
100 'zenchef-widget-integration'
101 ),
102 'options' => [
103 '' => _x('Use Zenchef OS default', 'widget.backoffice.settings_page.language.default_option_label', 'zenchef-widget-integration'),
104 'en' => 'English',
105 'fr' => 'Français',
106 'es' => 'Español',
107 'it' => 'Italiano',
108 'de' => 'Deutsch',
109 'pt' => 'Português',
110 'nl' => 'Nederlands',
111 ],
112 ],
113 ],
114 ],
115 ],
116 'zenchef.widget.appearance_section' => [
117 'title' => _x('Appearance', 'widget.backoffice.settings_page.appearance_section_title', 'zenchef-widget-integration'),
118 'fields' => [
119 'use_default_color' => [
120 'label' => _x('Brand colour', 'widget.backoffice.settings_page.use_default_color_input_label', 'zenchef-widget-integration'),
121 'type' => 'checkbox',
122 'template_parameters' => [
123 'checkbox_label' => _x('Use the brand colour set in Zenchef OS', 'widget.backoffice.settings_page.use_default_color_checkbox_label', 'zenchef-widget-integration'),
124 'description' => _x(
125 'When unchecked, the colour selected below overrides the colour set in your Zenchef OS dashboard.',
126 'widget.backoffice.settings_page.use_default_color_input_description',
127 'zenchef-widget-integration'
128 ),
129 ],
130 ],
131 'primary_color' => [
132 'label' => _x('Custom colour', 'widget.backoffice.settings_page.primary_color_input_label', 'zenchef-widget-integration'),
133 'type' => 'color',
134 'template_parameters' => [
135 'description' => _x(
136 'Hex colour used for the booking widget\'s primary buttons and accents (only applied when "Use the brand colour set in Zenchef OS" is unchecked).',
137 'widget.backoffice.settings_page.primary_color_input_description',
138 'zenchef-widget-integration'
139 ),
140 ],
141 ],
142 'position' => [
143 'label' => _x('Widget position', 'widget.backoffice.settings_page.widget_position_input_label', 'zenchef-widget-integration'),
144 'type' => 'select',
145 'template_parameters' => [
146 'description' => _x('Select the position of the widget on the page.', 'widget.backoffice.settings_page.widget_position_input_description', 'zenchef-widget-integration'),
147 'options' => [
148 'center' => _x('Center', 'widget.backoffice.settings_page.widget_position.center_option_label', 'zenchef-widget-integration'),
149 'left' => _x('Left', 'widget.backoffice.settings_page.widget_position.left_option_label', 'zenchef-widget-integration'),
150 'right' => _x('Right', 'widget.backoffice.settings_page.widget_position.right_option_label', 'zenchef-widget-integration'),
151 ],
152 ],
153 ],
154 ],
155 ],
156 'zenchef.widget.behaviour_section' => [
157 'title' => _x('Behaviour', 'widget.backoffice.settings_page.behaviour_section_title', 'zenchef-widget-integration'),
158 'fields' => [
159 'auto_open' => [
160 'label' => _x('Auto-open', 'widget.backoffice.settings_page.auto_open_input_label', 'zenchef-widget-integration'),
161 'type' => 'checkbox',
162 'template_parameters' => [
163 'checkbox_label' => _x('Open the booking widget automatically when the page loads', 'widget.backoffice.settings_page.auto_open_checkbox_label', 'zenchef-widget-integration'),
164 'description' => _x(
165 'When disabled, the widget only opens when the visitor clicks the floating button or any element that triggers it (e.g. a button with data-zc-action="open").',
166 'widget.backoffice.settings_page.auto_open_input_description',
167 'zenchef-widget-integration'
168 ),
169 ],
170 ],
171 'open_delay' => [
172 'label' => _x('Open delay (in ms)', 'widget.backoffice.settings_page.open_input_label', 'zenchef-widget-integration'),
173 'type' => 'number',
174 'template_parameters' => [
175 'description' => _x('The delay in milliseconds before the widget opens automatically. Only applies when auto-open is enabled.', 'widget.backoffice.settings_page.open_input_description', 'zenchef-widget-integration'),
176 ],
177 ],
178 'hide_button' => [
179 'label' => _x('Floating button', 'widget.backoffice.settings_page.hide_button_input_label', 'zenchef-widget-integration'),
180 'type' => 'checkbox',
181 'template_parameters' => [
182 'checkbox_label' => _x('Hide the default floating booking button', 'widget.backoffice.settings_page.hide_button_checkbox_label', 'zenchef-widget-integration'),
183 'description' => _x(
184 'Useful when you trigger the widget from your own buttons (e.g. an Elementor button with data-zc-action="open") and don\'t want the default floating button.',
185 'widget.backoffice.settings_page.hide_button_input_description',
186 'zenchef-widget-integration'
187 ),
188 ],
189 ],
190 ],
191 ],
192 'zenchef.widget.analytics_section' => [
193 'title' => _x('Analytics', 'widget.backoffice.settings_page.analytics_section_title', 'zenchef-widget-integration'),
194 'fields' => [
195 'disable_gtm' => [
196 'label' => _x('Google Tag Manager', 'widget.backoffice.settings_page.disable_gtm_input_label', 'zenchef-widget-integration'),
197 'type' => 'checkbox',
198 'template_parameters' => [
199 'checkbox_label' => _x('Disable the widget\'s GTM integration', 'widget.backoffice.settings_page.disable_gtm_checkbox_label', 'zenchef-widget-integration'),
200 'description' => _x(
201 'Enable this if your site already tracks bookings through its own GTM container and you want to avoid duplicate events.',
202 'widget.backoffice.settings_page.disable_gtm_input_description',
203 'zenchef-widget-integration'
204 ),
205 ],
206 ],
207 'disable_ga4' => [
208 'label' => _x('Google Analytics 4', 'widget.backoffice.settings_page.disable_ga4_input_label', 'zenchef-widget-integration'),
209 'type' => 'checkbox',
210 'template_parameters' => [
211 'checkbox_label' => _x('Disable the widget\'s GA4 integration', 'widget.backoffice.settings_page.disable_ga4_checkbox_label', 'zenchef-widget-integration'),
212 'description' => _x(
213 'Enable this if your site already sends booking events to GA4 and you want to avoid duplicate events.',
214 'widget.backoffice.settings_page.disable_ga4_input_description',
215 'zenchef-widget-integration'
216 ),
217 ],
218 ],
219 ],
220 ],
221 ];
222 }
223