PluginProbe
Booking Calendar / 10.10
Booking Calendar v10.10
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.10, at includes/page-setup/setup_steps.php

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