PluginProbe
Booking Calendar / 10.15.7
Booking Calendar v10.15.7
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 10.11 10.11.2 10.11.3 All 202 releases
booking / includes / page-setup / setup_steps.php

setup_steps.php in Booking Calendar 10.15.7, at includes/page-setup/setup_steps.php

532 lines 17.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /**
2 * @version 1.0
3 * @description Steps Structure for Setup Wizard Page
4 * @category Setup Class
5 * @author wpdevelop
6 *
7 * @web-site http://oplugins.com/
8 * @email info@oplugins.com
9 *
10 * @modified 2024-09-06
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15
16 class WPBC_SETUP_WIZARD_STEPS {
17
18 private $steps_arr = array();
19
20 public function __construct() {
21
22 if ( WPBC()->is_wp_inited() ) {
23 $this->init_steps_data();
24 } else {
25 add_action( 'init', array( $this, 'init_steps_data' ) );
26 }
27
28 add_action( 'wpbc_after_wpbc_page_top__header_tabs', array( $this, 'show_top_right_wizard_button' ), 10, 3 );
29
30 }
31
32
33 /**
34 * Define Steps Data Structure - Init
35 *
36 * @return void
37 */
38 public function init_steps_data(){
39
40 $step_default_params = array(
41 'show_section_left' => false,
42 'show_section_right' => false,
43 'is_done' => false,
44 'do_action' => 'none',
45 'prior' => '',
46 'next' => '',
47 'prior_title' => __( 'Go Back', 'booking' ),
48 'next_title' => __( 'Save and Continue', 'booking' )
49 );
50 $steps_arr = array();
51
52
53 // Step #1
54 $step_name = 'welcome';
55 $steps_arr[ $step_name ] = $step_default_params;
56 $steps_arr[ $step_name ]['do_action'] = 'save_and_continue__welcome';
57 $steps_arr[ $step_name ]['next'] = ( wpbc_is_this_demo() ) ? 'date_time_formats' : 'general_info';
58 //$steps_arr[ $step_name ]['next_title'] = __( 'Let\'s Get Started', 'booking' );
59
60 if ( ! wpbc_is_this_demo() ) {
61 // Step #2
62 $step_name = 'general_info';
63 $steps_arr[ $step_name ] = $step_default_params;
64 $steps_arr[ $step_name ]['do_action'] = 'save_and_continue__general_info';
65 //$steps_arr[ $step_name ]['prior'] = 'bookings_types';
66 $steps_arr[ $step_name ]['next'] = 'date_time_formats';
67 }
68
69 // Step #3
70 $step_name = 'date_time_formats';
71 $steps_arr[ $step_name ] = $step_default_params;
72 $steps_arr[ $step_name ]['do_action'] = 'save_and_continue__date_time_formats';
73 if ( ! wpbc_is_this_demo() ) {
74 $steps_arr[ $step_name ]['prior'] = 'general_info';
75 }
76 $steps_arr[ $step_name ]['next'] = 'bookings_types';
77
78 // Step #4
79 $step_name = 'bookings_types';
80 $steps_arr[ $step_name ] = $step_default_params;
81 $steps_arr[ $step_name ]['do_action'] = 'save_and_continue__bookings_types';
82 $steps_arr[ $step_name ]['prior'] = 'date_time_formats';
83 $is_bfb_enabled = (bool) WPBC_Frontend_Settings::is_bfb_enabled( null );
84 if ( $is_bfb_enabled ) {
85 $steps_arr[ $step_name ]['next'] = 'cal_availability';
86 } else {
87 $steps_arr[ $step_name ]['next'] = 'form_structure';
88 }
89
90
91 // Step #5
92 $step_name = 'form_structure';
93 $steps_arr[ $step_name ] = $step_default_params;
94 $steps_arr[ $step_name ]['do_action'] = 'save_and_continue__form_structure';
95 $steps_arr[ $step_name ]['prior'] = 'bookings_types';
96 $steps_arr[ $step_name ]['next'] = 'cal_availability';
97 $steps_arr[ $step_name ]['next_title'] = __( 'Continue', 'booking' );
98
99 // Step #6
100 $step_name = 'cal_availability';
101 $steps_arr[ $step_name ] = $step_default_params;
102 $steps_arr[ $step_name ]['do_action'] = 'save_and_continue__cal_availability';
103 if ( $is_bfb_enabled ) {
104 $steps_arr[ $step_name ]['prior'] = 'bookings_types';
105 } else {
106 $steps_arr[ $step_name ]['prior'] = 'form_structure';
107 }
108 $steps_arr[ $step_name ]['next'] = 'color_theme';
109 $steps_arr[ $step_name ]['next_title'] = __( 'Continue', 'booking' );
110
111 // Step #7
112 $step_name = 'color_theme';
113 $steps_arr[ $step_name ] = $step_default_params;
114 $steps_arr[ $step_name ]['do_action'] = 'save_and_continue__color_theme';
115 $steps_arr[ $step_name ]['prior'] = 'cal_availability';
116 $steps_arr[ $step_name ]['next'] = 'optional_other_settings';
117
118 // Step #8
119 $step_name = 'optional_other_settings';
120 $steps_arr[ $step_name ] = $step_default_params;
121 //$steps_arr[ $step_name ]['show_section_left'] = true;
122 //$steps_arr[ $step_name ]['show_section_right'] = true;
123 $steps_arr[ $step_name ]['do_action'] = 'save_and_continue__optional_other_settings';
124 $steps_arr[ $step_name ]['prior'] = 'color_theme';
125 $steps_arr[ $step_name ]['next'] = ( wpbc_is_this_demo() ) ? 'get_started' : 'wizard_publish';
126 $steps_arr[ $step_name ]['next_title'] = __( 'Continue', 'booking' );
127
128 if ( ! wpbc_is_this_demo() ) {
129 // Step #9
130 $step_name = 'wizard_publish';
131 $steps_arr[ $step_name ] = $step_default_params;
132 //$steps_arr[ $step_name ]['show_section_left'] = true;
133 //$steps_arr[ $step_name ]['show_section_right'] = true;
134 $steps_arr[ $step_name ]['do_action'] = 'save_and_continue__wizard_publish';
135 $steps_arr[ $step_name ]['prior'] = 'optional_other_settings';
136 $steps_arr[ $step_name ]['next'] = 'get_started';
137 $steps_arr[ $step_name ]['next_title'] = __( 'Continue', 'booking' );
138 }
139
140 // Step #10
141 $step_name = 'get_started';
142 $steps_arr[ $step_name ] = $step_default_params;
143 //$steps_arr[ $step_name ]['show_section_left'] = true;
144 //$steps_arr[ $step_name ]['show_section_right'] = true;
145 $steps_arr[ $step_name ]['do_action'] = 'save_and_continue__get_started';
146 $steps_arr[ $step_name ]['prior'] = ( wpbc_is_this_demo() ) ? 'optional_other_settings' : 'wizard_publish';
147 $steps_arr[ $step_name ]['next'] = 'welcome';
148 //$steps_arr[ $step_name ]['next_title'] = __( 'Complete', 'booking' );
149
150 $this->steps_arr = $steps_arr;
151 }
152
153 /**
154 * Get Steps Data Structure
155 * @return array
156 */
157 public function get_steps_arr(){
158 return $this->steps_arr;
159 }
160
161
162 // =================================================================================================================
163 // == Steps STRUCTURE ==
164 // =================================================================================================================
165
166 /**
167 * Actual Step Number -> 'general_info' or 'optional_other_settings'
168 *
169 * @return int
170 */
171 public function get_active_step_name() {
172
173 $steps_arr = $this->db__get_steps_is_done();
174
175 $first_step_name = '';
176 foreach ( $steps_arr as $step_name => $step ) {
177
178 $first_step_name = (empty($first_step_name)) ? $step_name : $first_step_name;
179
180 if ( empty( $step ) ) {
181 return $step_name;
182 }
183 }
184 return $first_step_name;
185 }
186
187
188 /**
189 * Actual Step Number -> 2
190 *
191 * @return int
192 */
193 public function get_active_step_num() {
194
195 $steps_arr = $this->db__get_steps_is_done();
196 $active_step = 0;
197 foreach ( $steps_arr as $step ) {
198
199 if ( ! empty( $step ) ) {
200 $active_step++;
201 }
202 }
203 return $active_step;
204 }
205
206
207 /**
208 * Get Steps Count -> 9
209 *
210 * @return int
211 */
212 public function get_total_steps_count(){
213
214 $steps_arr = $this->db__get_steps_is_done();
215
216 return count($steps_arr);
217 }
218
219
220 /**
221 * Get % Progress for Setup Steps -> 30
222 * @return int
223 */
224 public function get_progess_value() {
225
226 $progess_value = ( ($this->get_active_step_num()-0) * 100 ) / $this->get_total_steps_count();
227 $progess_value = intval( $progess_value );
228
229 return $progess_value;
230 }
231
232
233 // =================================================================================================================
234 // == DB :: "Set Wizard Steps as Done" ==
235 // =================================================================================================================
236
237 /**
238 * Get all Steps from DB and from Structure,
239 *
240 * If not saved yet to DB, then get default structure
241 *
242 * And if later Wizard structure ->init_steps_data() was extended, then system get such steps as uncompleted.
243 *
244 * @return array|mixed
245 */
246 public function db__get_steps_is_done() {
247
248 $steps_is_done = get_bk_option( 'booking_setup_wizard_page_steps_is_done' );
249
250 if ( empty( $steps_is_done ) ) {
251 // Get Default Steps from the Steps structure
252
253 $steps_names = $this->get_steps_arr();
254 $steps_names = array_keys( $steps_names );
255
256 $steps_values = array_fill( 0, count( $steps_names ), false );
257 $steps_is_done = array_combine( $steps_names, $steps_values );
258 } else {
259
260 // Check if some new steps here ?
261 $possible_new_steps_names = $this->get_steps_arr();
262 $possible_new_steps_names = array_keys( $possible_new_steps_names );
263 foreach ( $possible_new_steps_names as $possible_new_steps_name ) {
264 if ( ! isset( $steps_is_done[ $possible_new_steps_name ] ) ) {
265 $steps_is_done[ $possible_new_steps_name ] = false;
266 }
267 }
268
269 }
270
271 return $steps_is_done;
272 }
273
274
275 /**
276 * Save statuses to all steps
277 *
278 * @param $steps_arr
279 *
280 * @return void
281 */
282 public function db__save_steps_is_done( $steps_arr ) {
283 update_bk_option( 'booking_setup_wizard_page_steps_is_done', $steps_arr );
284 }
285
286 /**
287 * Set specific step as Completed
288 *
289 * @param $step_name
290 *
291 * @return void
292 */
293 public function db__set_step_as_completed( $step_name ) {
294
295 $steps_arr = $this->db__get_steps_is_done();
296
297 $steps_arr[ $step_name ] = true;
298
299 $this->db__save_steps_is_done( $steps_arr );
300 }
301
302 /**
303 * Set specific step as Uncompleted
304 *
305 * @param $step_name
306 *
307 * @return void
308 */
309 public function db__set_step_as_uncompleted( $step_name ) {
310
311 $steps_arr = $this->db__get_steps_is_done();
312
313 $steps_arr[ $step_name ] = false;
314
315 $this->db__save_steps_is_done( $steps_arr );
316 }
317
318 /**
319 * Check if specific step 'Is completed' ?
320 *
321 * @param string $step_name
322 *
323 * @return bool
324 */
325 public function db__is_step_completed( $step_name ) {
326
327 $steps_arr = $this->db__get_steps_is_done();
328
329 if ( empty( $steps_arr[ $step_name ] ) ) {
330 return false;
331 } else {
332 return true;
333 }
334 }
335
336
337 /**
338 * Mark All Steps as Completed or Uncompleted
339 *
340 * @param $is_completed bool (default true)
341 *
342 * @return void
343 */
344 public function db__set_all_steps_as( $is_completed = true ) {
345
346 if ( false === $is_completed ) {
347 delete_bk_option( 'booking_setup_wizard_page_steps_is_done' );
348 }
349
350 $steps_names = $this->db__get_steps_is_done();
351
352 $steps_names = array_keys( $steps_names );
353 $steps_values = array_fill( 0, count( $steps_names ), $is_completed );
354 $steps_is_done = array_combine( $steps_names, $steps_values );
355
356 // Set all steps as not completed
357 $this->db__save_steps_is_done( $steps_is_done );
358 }
359
360 /**
361 * Check Is all steps Completed
362 * @return bool
363 */
364 public function db__is_all_steps_completed() {
365
366 $steps_arr = $this->db__get_steps_is_done();
367
368 foreach ( $steps_arr as $step_name => $steps_val ) {
369 if ( empty( $steps_val ) ) {
370 return false;
371 }
372 }
373
374 return true;
375 }
376
377
378
379 // =================================================================================================================
380 // == C O N T E N T ==
381 // =================================================================================================================
382
383 // ----------------------------------------------------------
384 // == Left Plugin Menu --> "Setup" with Progress Bar ==
385 // ----------------------------------------------------------
386
387 /**
388 * Main Left Menu Title - "Setup" with Progress Bar
389 *
390 * @return false|string
391 */
392 public function get_plugin_menu_title__setup_progress(){
393
394
395 ob_start();
396
397 ?><div class="setup_wizard_page_container" style="display: flex;flex-flow: row wrap;justify-content: flex-start;align-items: center;color: #fff;margin: 0 -5px 0 0;overflow: visible;">
398 <div class="name_item" style="margin-top: 0;white-space: nowrap;padding: 0 0 0 0;"><?php esc_html_e( 'Setup', 'booking' ); ?></div>
399 <div style="margin:3px 0px 0 0;margin-left: auto;font-size: 9px;background: var(--wpbc_admin-theme-color, #2271b1);height: 15px;" class="wpbc_badge_count name_item update-plugins">
400 <span class="update-count" style="white-space: nowrap;word-wrap: normal;"><?php
401 echo esc_html( $this->get_active_step_num() . ' / ' . $this->get_total_steps_count() );
402 ?></span>
403 </div>
404 <div class="progress_line_container" style="width: 100%;border: 0px solid #757575;height: 3px;border-radius: 6px;margin: 7px 0 -3px -3px;overflow: hidden;background: #555;">
405 <div class="progress_line" style="font-size: 6px;font-weight: 600;word-wrap: normal;border-radius: 6px;white-space: nowrap;background: #8ECE01;width: <?php
406 echo esc_html( $this->get_progess_value() ); ?>%;height: 3px;"></div>
407 </div>
408 </div><?php
409
410 return ob_get_clean();
411 }
412
413 // ----------------------------------------------------------
414 // == Content Top Wizard Button ==
415 // ----------------------------------------------------------
416
417 /**
418 * Black Button at Top Right Side in WPBC plugin menu ( except Wizard page )
419 *
420 * Show Continue Setup Wizard Button
421 * @return void
422 */
423 public function show_top_right_wizard_button() {
424
425 if ( ! wpbc_is_setup_wizard_page() ){
426
427 if (
428 ( ! wpbc_is_user_can_access_wizard_page() ) ||
429 ( $this->db__is_all_steps_completed() )
430 ){
431 return false;
432 }
433
434 // FixIn: 10.12.1.1.
435 ?><style tye="text/css">
436 @media screen and (max-width: 782px) {
437 .ui_element.wpbc_page_top__wizard_button {
438 /*top: 49px !important;*/
439 }
440 }
441 .wp-admin.wpbc_admin_full_screen .wpbc_header_news {
442 display: none !important;
443 }
444 .wpbc_admin_full_screen .wpbc_page_top__wizard_button {
445 display: none;
446 }
447 .wpbc_page_top__wizard_button {
448 width: auto;
449 position: fixed;
450 z-index: 90000;
451 box-shadow: 0 0 10px #c1c1c1;
452 border-radius: 9px;
453 background: transparent;
454 right: 69px;
455 top: 40px;
456
457 right: 15px;
458 top: auto !important;
459 bottom: 15px !important;
460 }
461 div .wpbc_admin_page__tab__builder_booking_form .wpbc_page_top__wizard_button {
462 top: calc(var(--wpbc_ui_top_nav__wp_top_menu_height) + var(--wpbc_ui_top_nav__height) + 10px) !important;
463 top: auto !important;
464 }
465 .ui_element.wpbc_page_top__wizard_button .wpbc_page_top__wizard_button_content,
466 .ui_element.wpbc_page_top__wizard_button .wpbc_page_top__wizard_button_content:hover {
467 border-radius: 5px;
468 border: none;
469 background: #535353; /* #6c9e00 #0b9300;*/
470 box-shadow: 0 0 10px #dbdbdb;
471 text-shadow: none;
472 color: #fff;
473 font-weight: 600;
474 padding: 8px 10px 8px 15px;
475 display: flex;
476 flex-flow: row nowrap;
477 justify-content: flex-start;
478 align-items: center;
479 }
480 </style>
481 <div style="min-width: 240px;top: 35px;font-size: 15px;" class="ui_element wpbc_page_top__wizard_button">
482 <div class="wpbc_ui_control wpbc_page_top__wizard_button_content">
483 <div class="in-button-text"
484 style="width: 100%;margin: 0;display: flex;flex-flow: row nowrap;justify-content: flex-start;align-items: center;">
485 <div class="setup_wizard_page_container"
486 style="display: flex;flex-flow: row wrap;justify-content: flex-start;align-items: center;color: #fff;overflow: visible;flex: 1 1 auto;">
487 <div class="name_item" style="margin-top: 0;white-space: nowrap;padding: 0;margin-right: 20px;">
488 <i style="margin-right: 4px;" class="menu_icon icon-1x wpbc_icn_donut_large wpbc_icn_adjust0"></i> <?php esc_html_e( 'Finish Setup', 'booking' ); ?>
489 </div>
490 <div
491 style="margin:2px 0px 0 9px;font-size: 9px;background: #3e3e3e;height: auto;border-radius: 5px;padding: 0px 7px 0px;margin-left: auto;"
492 class="wpbc_badge_count name_item update-plugins">
493 <span class="update-count"
494 style="white-space: nowrap;word-wrap: normal;"><?php echo esc_html( $this->get_active_step_num() . ' / ' . $this->get_total_steps_count() ); ?></span>
495 </div>
496
497 <div class="progress_line_container"
498 style="width: 100%;border: 0px solid #757575;height: 3px;border-radius: 6px;margin: 7px 0 0 0;overflow: hidden;background: #202020;">
499 <div class="progress_line"
500 style="font-size: 6px;font-weight: 600;border-radius: 6px;word-wrap: normal;white-space: nowrap;background: #8ECE01;width: <?php echo esc_attr( $this->get_progess_value() ); ?>%;height: 3px;"></div>
501 </div>
502 </div>
503 <a <?php // onclick="javascript:jQuery( '.wpbc_page_top__wizard_button').remove();" href="javascript:void(0);" ?>
504 href="<?php echo esc_url( wpbc_get_setup_wizard_page_url() ); ?>"
505 class="button button-primary"
506 style="margin-left: auto;font-size: 11px;min-height: 10px;margin-left: 25px;">Continue</a></div>
507 </div>
508 </div><?php
509 }
510 }
511
512 }
513 function wpbc_init_setup_wizard(){
514 $setup_steps = new WPBC_SETUP_WIZARD_STEPS();
515 }
516 // $setup_steps = new WPBC_SETUP_WIZARD_STEPS();
517 add_action( 'init', 'wpbc_init_setup_wizard' );
518
519
520
521 /**
522 * On plugin activation set all steps as completed in Live Demos
523 * @return void
524 */
525 function wpbc_booking_activate_plugin__wizard() {
526 if ( wpbc_is_this_demo() ) {
527 $setup_steps = new WPBC_SETUP_WIZARD_STEPS();
528 $is_completed = true;
529 $setup_steps->db__set_all_steps_as( $is_completed );
530 }
531 }
532 add_bk_action( 'wpbc_other_versions_activation', 'wpbc_booking_activate_plugin__wizard' );