PluginProbe
Booking Calendar / 11.9
Booking Calendar v11.9
11.9 11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 All 205 releases
← All changes | includes/page-form-builder/assets/template-records/bfb-activate-templates.php +106 -8 11.2 → 11.9 View file →
@@ -1,4 +1,4 @@
1 1 <?php
2 2 /**
3 3 * Booking Form Builder - Bundled templates activation/update helpers.
4 4 *
@@ -105,9 +105,9 @@
105 105 * - upsert = insert if missing, update existing row when seed_version increases.
106 106 *
107 107 * @return array
108 108 */
109 -function wpbc_bfb_activation__get_templates_registry() {
109 +function wpbc_bfb_activation__get_templates_registry() {
110 110
111 111 $templates = array();
112 112 $template_files = array(
113 113
@@ -136,20 +136,51 @@
136 136 wpbc_bfb_activation__get_templates_dir_path() . '/dates_form_with_calendar_next_to_form.php',
137 137 wpbc_bfb_activation__get_templates_dir_path() . '/dates_form_with_vertical_layout.php',
138 138 wpbc_bfb_activation__get_templates_dir_path() . '/dates_form_wizard_2_steps.php',
139 139
140 - // Hints
141 - wpbc_bfb_activation__get_templates_dir_path() . '/time_slots_20_min_3_steps_review_with_hints.php',
142 - wpbc_bfb_activation__get_templates_dir_path() . '/time_appointments_3_steps_review_with_hints.php',
143 - wpbc_bfb_activation__get_templates_dir_path() . '/dates_advanced_3_steps_review_with_hints.php',
144 - wpbc_bfb_activation__get_templates_dir_path() . '/dates_2_columns_sidebar_hints.php',
145 140
141 + // Hints
142 + wpbc_bfb_activation__get_templates_dir_path() . '/time_slots_20_min_3_steps_review_with_hints.php',
143 + wpbc_bfb_activation__get_templates_dir_path() . '/time_appointments_3_steps_review_with_hints.php',
144 + wpbc_bfb_activation__get_templates_dir_path() . '/dates_advanced_3_steps_review_with_hints.php',
145 + wpbc_bfb_activation__get_templates_dir_path() . '/dates_2_columns_sidebar_hints.php',
146 +
146 147 // Example future records:
147 148 // wpbc_bfb_activation__get_templates_dir_path() . '/template-contact-inquiry.php',
148 149 // wpbc_bfb_activation__get_templates_dir_path() . '/template-event-registration.php',
149 150 );
150 151
151 - foreach ( $template_files as $template_file ) {
152 + // Keep private live-demo fixtures out of customer template libraries.
153 + if ( function_exists( 'wpbc_is_this_demo' ) && wpbc_is_this_demo() ) {
154 + $template_files = array_merge(
155 + $template_files,
156 + array(
157 + wpbc_bfb_activation__get_templates_dir_path() . '/demo_personal.php',
158 + wpbc_bfb_activation__get_templates_dir_path() . '/demo_business_small.php',
159 + wpbc_bfb_activation__get_templates_dir_path() . '/demo_business_medium.php',
160 + wpbc_bfb_activation__get_templates_dir_path() . '/demo_business_large.php',
161 + wpbc_bfb_activation__get_templates_dir_path() . '/demo_multiuser.php',
162 + wpbc_bfb_activation__get_templates_dir_path() . '/demo_multiuser_owner_1.php',
163 + wpbc_bfb_activation__get_templates_dir_path() . '/demo_multiuser_owner_2.php',
164 + wpbc_bfb_activation__get_templates_dir_path() . '/demo_multiuser_owner_3.php',
165 + )
166 + );
167 + }
168 +
169 + /*
170 + * Template cards are listed newest-first, with the row ID as the final
171 + * tie-breaker. Append preferred templates in increasing display priority.
172 + * The last bundled template seeded is therefore the first library card after
173 + * activation. The insert-only records below never overwrite installed rows.
174 + */
175 + $template_files[] = wpbc_bfb_activation__get_templates_dir_path() . '/appointments_services_flow.php';
176 + $template_files[] = wpbc_bfb_activation__get_templates_dir_path() . '/appointments_services_selection_summary.php';
177 + $template_files[] = wpbc_bfb_activation__get_templates_dir_path() . '/dates_form_with_inline_hints.php';
178 + $template_files[] = wpbc_bfb_activation__get_templates_dir_path() . '/dates_vertical_hints_full_days.php';
179 + $template_files[] = wpbc_bfb_activation__get_templates_dir_path() . '/dates_2_columns_hints_full_days.php';
180 + $template_files[] = wpbc_bfb_activation__get_templates_dir_path() . '/time_slots_2_columns_hints.php';
181 +
182 + foreach ( $template_files as $template_file ) {
152 183 if ( file_exists( $template_file ) ) {
153 184 $template_config = require $template_file;
154 185
155 186 if ( is_array( $template_config ) ) {
@@ -162,9 +193,75 @@
162 193 * Allow third-party code or future modules to register bundled templates.
163 194 */
164 195 $templates = apply_filters( 'wpbc_bfb_activation__templates_registry', $templates );
165 196
166 - return $templates;
197 + return $templates;
198 +}
199 +
200 +/**
201 + * Keep the replacement Appointment template adjacent to its legacy predecessor.
202 + *
203 + * The shared list endpoint owns the neutral ordering mechanic. This domain
204 + * registration supplies only the two stable template slugs and does not change
205 + * either insert-only row or its saved timestamp.
206 + *
207 + * @param array $adjacencies Registered template-library adjacency pairs.
208 + *
209 + * @return array Filtered adjacency pairs.
210 + */
211 +function wpbc_bfb_activation__register_template_library_adjacencies( $adjacencies ) {
212 +
213 + if ( ! is_array( $adjacencies ) ) {
214 + $adjacencies = array();
215 + }
216 +
217 + $adjacencies[] = array(
218 + 'before' => 'appointments_services_selection_summary',
219 + 'after' => 'appointments_services_flow',
220 + );
221 +
222 + return $adjacencies;
223 +}
224 +add_filter( 'wpbc_bfb_template_library_adjacencies', 'wpbc_bfb_activation__register_template_library_adjacencies' );
225 +
226 +/**
227 + * Add default form appearance settings to bundled template settings_json.
228 + *
229 + * Individual templates can override any key in their own settings_json; this only fills missing values.
230 + *
231 + * @param string $settings_json Template settings JSON.
232 + *
233 + * @return string
234 + */
235 +function wpbc_bfb_activation__add_default_form_appearance_settings( $settings_json ) {
236 +
237 + $settings = array();
238 + if ( is_string( $settings_json ) && '' !== trim( $settings_json ) ) {
239 + $decoded = json_decode( (string) $settings_json, true );
240 + if ( is_array( $decoded ) ) {
241 + $settings = $decoded;
242 + }
243 + }
244 +
245 + if ( empty( $settings['options'] ) || ! is_array( $settings['options'] ) ) {
246 + $settings['options'] = array();
247 + }
248 +
249 + if ( function_exists( 'wpbc_bfb_settings__strip_form_style_options_from_form_settings' ) ) {
250 + $settings = wpbc_bfb_settings__strip_form_style_options_from_form_settings( $settings );
251 + }
252 +
253 + if ( empty( $settings['css_vars'] ) || ! is_array( $settings['css_vars'] ) ) {
254 + $settings['css_vars'] = array();
255 + }
256 +
257 + if ( empty( $settings['bfb_options'] ) || ! is_array( $settings['bfb_options'] ) ) {
258 + $settings['bfb_options'] = array( 'advanced_mode_source' => 'builder' );
259 + }
260 +
261 + return function_exists( 'wpbc_form_config__encode_json' )
262 + ? wpbc_form_config__encode_json( $settings )
263 + : wp_json_encode( $settings );
167 264 }
168 265
169 266 /**
170 267 * Normalize bundled template config.
@@ -221,8 +318,9 @@
221 318 $template_config['record']['engine_version'] = (string) $template_config['record']['engine_version'];
222 319 $template_config['record']['title'] = (string) $template_config['record']['title'];
223 320 $template_config['record']['description'] = (string) $template_config['record']['description'];
224 321 $template_config['record']['picture_url'] = (string) $template_config['record']['picture_url'];
322 + $template_config['record']['settings_json'] = wpbc_bfb_activation__add_default_form_appearance_settings( (string) $template_config['record']['settings_json'] );
225 323
226 324 if ( null !== $template_config['record']['booking_resource_id'] ) {
227 325 $template_config['record']['booking_resource_id'] = (int) $template_config['record']['booking_resource_id'];
228 326 }