PluginProbe
Booking Calendar / 10.11.3
Booking Calendar v10.11.3
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 10.11 10.11.2 All 203 releases
booking / includes / ui_settings / class-menu-structure.php

class-menu-structure.php in Booking Calendar 10.11.3, at includes/ui_settings/class-menu-structure.php

524 lines 21.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Menu Structure in Admin Panel
4 *
5 * @version 1.0
6 * @package Any
7 * @category Plugin Menu Structure - in Admin Panel
8 * @author wpdevelop
9 *
10 * @web-site https://wpbookingcalendar.com/
11 * @email info@wpbookingcalendar.com
12 *
13 * @modified 2025-02-09
14 */
15
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit; // Exit, if accessed directly.
18 }
19
20 // FixIn: 11.0.0.1.
21
22 /**
23 * Define Settings Page Structure
24 */
25 abstract class WPBC_Menu_Structure {
26
27 /**
28 * Parameters for current page, if this page selected, otherwise its = empty array()
29 *
30 * @var array
31 */
32 protected $current_page_params;
33
34 /**
35 * Tabs array, same for all objects.
36 *
37 * @var array
38 */
39 protected static $nav_tabs;
40
41 /**
42 * Defining Name of parameter in GET request for Navigation TOP and BOTTOM tabs: - $_GET[ 'tab' ] == 'payment' - $_GET[ 'subtab' ] == 'paypal'.
43 *
44 * @var array
45 */
46 protected $tags;
47
48
49 /**
50 * Constructor
51 */
52 public function __construct() {
53
54 self::$nav_tabs = array();
55
56 $this->current_page_params = array();
57
58 $this->tags = array();
59
60 // Defining Name of parameter in GET request - $_GET[ 'tab' ] == 'payment'.
61 $this->tags['tab'] = 'tab';
62
63 // Defining Name of parameter in GET request - $_GET[ 'subtab' ] == 'paypal'.
64 $this->tags['subtab'] = 'subtab';
65
66 // This Hook fire after creation menu in class WPBC_Admin_Menus.
67 add_action( 'wpbc_define_nav_tabs', array( $this, 'wpbc_create_plugin_menu_structure_arr' ) );
68 }
69
70 // -----------------------------------------------------------------------------------------------------------------
71 // Abstract Methods
72 // -----------------------------------------------------------------------------------------------------------------
73
74 /**
75 * Define slug in what menu to show this page. // Parameter relative: $_GET['page'].
76 *
77 * @return string
78 *
79 * Example:
80 *
81 * return 'wpbc-settings';
82 */
83 abstract public function in_page();
84
85 /**
86 * Define Tabs and Subtabs of this Admin Page
87 *
88 * @return array();
89 *
90 * Example:
91 *
92 * $tabs = array();
93 * $tabs[ 'form' ] = array(
94 * 'title' => __('Form','booking') // Title of TAB
95 * , 'hint' => __('Customization of Form Fields', 'booking') // Hint
96 * , 'page_title' =>ucwords( __('Form fields', 'booking') ) // Title of Page
97 * //, 'link' => '' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link
98 * //, 'position' => '' // 'left' || 'right' || ''
99 * //, 'css_classes' => '' // CSS class(es)
100 * //, 'icon' => '' // Icon - link to the real PNG img
101 * , 'font_icon' => 'wpbc_icn_draw' // CSS definition of forn Icon
102 * , 'default' => false // Is this tab activated by default or not: true || false.
103 * , 'disabled' => false // Is this tab disbaled: true || false.
104 * , 'hided' => false // Is this tab hided: true || false.
105 * , 'subtabs' => array()
106 *
107 * );
108 * $tabs[ 'upgrade' ] = array(
109 * 'title' => __('Upgrade','booking') // Title of TAB
110 * , 'hint' => __('Upgrade to higher version', 'booking') // Hint
111 * //, 'page_title' => __('Upgrade', 'booking') // Title of Page
112 * , 'link' => 'http://server.com/' // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link
113 * , 'position' => 'right' // 'left' || 'right' || ''
114 * //, 'css_classes' => '' // CSS class(es)
115 * //, 'icon' => '' // Icon - link to the real PNG img
116 * , 'font_icon' => 'wpbc_icn_auto_graph'// CSS definition of forn Icon
117 * //, 'default' => false // Is this tab activated by default or not: true || false.
118 * //, 'subtabs' => array()
119 *
120 * );
121 *
122 * $subtabs = array();
123 *
124 * $subtabs['fields'] = array(
125 * 'type' => 'subtab' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
126 * , 'title' => __('Form','booking') // Title of TAB
127 * , 'page_title' => __('Form Settings', 'booking') // Title of Page
128 * , 'hint' => __('Customization of Form Settings', 'booking') // Hint
129 * , 'link' => '' // link
130 * , 'position' => '' // 'left' || 'right' || ''
131 * , 'css_classes' => '' // CSS class(es)
132 * //, 'icon' => 'https://www.paypalobjects.com/webstatic/icon/pp258.png' // Icon - link to the real PNG img
133 * //, 'font_icon' => 'wpbc_icn_payment' // CSS definition of Font Icon
134 * , 'default' => true // Is this sub tab activated by default or not: true || false.
135 * , 'disabled' => false // Is this sub tab deactivated: true || false.
136 * , 'checkbox' => false // or definition array for specific checkbox: array( 'checked' => true, 'name' => 'feature1_active_status' )
137 * , 'content' => 'content' // Function to load as conten of this TAB
138 * );
139 *
140 * $subtabs['form-separator'] = array(
141 * 'type' => 'separator' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
142 * );
143 * $subtabs['form-goto'] = array(
144 * 'type' => 'goto-link' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
145 * , 'title' =>ucwords( __('Form fields', 'booking') ) // Title of TAB
146 * , 'hint' => '' // Hint
147 * , 'show_section' => 'id_of_show_section' // ID of HTML element, for scroll to.
148 * );
149 *
150 * ob_start();
151 * ...
152 * $html_element_data = ob_get_clean();
153 *
154 * $subtabs['form-selection'] = array(
155 * 'type' => 'html' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
156 * , 'html' => $html_element_data
157 * );
158 *
159 * $subtabs['form-save'] = array(
160 * 'type' => 'button' // Required| Possible values: 'subtab' | 'separator' | 'button' | 'goto-link' | 'html'
161 * , 'title' => __('Save Changes','booking') // Title of TAB
162 * , 'form' => 'wpbc_form' // Required for 'button'! Name of Form to submit
163 * );
164 *
165 * $tabs[ 'form' ][ 'subtabs' ] = $subtabs;
166 *
167 * return $tabs;
168 */
169 abstract public function tabs();
170
171 /**
172 * Show Content of this page - Main function.
173 *
174 * In top of this function have to be checking ubout Update (saving POST request).
175 *
176 * Exmaple:
177 *
178 * // S u b m i t ///////////////////////////////////////////////////////
179 *
180 * $this_submit_form = 'wpbc_emails_toolbar'; // Define form name
181 *
182 * // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
183 * if ( isset( $_POST['is_form_sbmitted_'. $this_submit_form ] ) ) {
184 *
185 * // Check N o n c e
186 * check_admin_referer( 'wpbc_settings_page_' . $this_submit_form ); // Its stop show anything on submiting, if its not refear to the original page
187 *
188 * // Make Update of settings
189 * $edit_field_data = $this->update_wpbc_emails_toolbar( $menu_slug );
190 * }
191 */
192 abstract public function content();
193
194
195 public function get_current_page_params() {
196 return $this->current_page_params;
197 }
198
199 public function get_nav_tabs() {
200 return self::$nav_tabs;
201 }
202
203 // -----------------------------------------------------------------------------------------------------------------
204 // Active Page Parameters
205 // -----------------------------------------------------------------------------------------------------------------
206
207 /**
208 * Check if this page selected (active), depend from the GET parameter
209 * If selected, then define Current Page Parameters.
210 *
211 * @return boolean
212 */
213 protected function is_page_activated() {
214
215 $is_page_selected = false;
216
217 $this_page = $this->in_page();
218 $this_page_arr = ( is_array( $this_page ) ) ? $this_page : array( $this_page );
219
220 $request_arr = array();
221 $request_arr['page'] = isset( $_REQUEST['page'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
222 ? sanitize_text_field( wp_unslash( $_REQUEST['page'] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
223 : null;
224 $request_arr['tab'] = isset( $_REQUEST[ $this->tags['tab'] ] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
225 ? sanitize_text_field( wp_unslash( $_REQUEST[ $this->tags['tab'] ] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
226 : null;
227 $request_arr['subtab'] = isset( $_REQUEST[ $this->tags['subtab'] ] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
228 ? sanitize_text_field( wp_unslash( $_REQUEST[ $this->tags['subtab'] ] ) ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
229 : null;
230
231 foreach ( $this_page_arr as $this_page ) {
232
233 foreach ( $this->tabs() as $this_tab_tag => $this_tab ) {
234
235 // FixIn: 10.11.3.5
236 $skip_type_arr = array( 'separator', 'button', 'goto-link', 'html' );
237
238 if ( ( ! empty( $this_tab['type'] ) ) && ( in_array( $this_tab['type'], $skip_type_arr, true ) ) ) {
239 // Probably it is separator, and we have not content here !
240 } else {
241 break; // Get First Tab Element, which MUST be subtab element, all other tabs, can be links, not really showing content!!!
242 }
243 }
244
245 if ( empty( $this_tab ) ) {
246 return $this_page; // this page empty - tabs is empty array, probabaly its was redefined in child CLASS to $tabs = array(); for not ability to open this page.
247 }
248
249 $this_subtab_tag = 0;
250 $this_subtab = array( 'default' => false );
251
252 if ( isset( $this_tab['subtabs'] ) ) {
253 foreach ( $this_tab['subtabs'] as $temp_this_subtab_tag => $temp_this_subtab ) {
254
255 // Get First Subtab element from subtabs array.
256 if ( 'subtab' === $temp_this_subtab['type'] ) {
257 $this_subtab_tag = $temp_this_subtab_tag;
258 $this_subtab = $temp_this_subtab;
259 break;
260 }
261 }
262 }
263
264 if ( ( isset( $request_arr['page'] ) ) && ( $this_page === $request_arr['page'] ) ) { // We are inside of this page. Menu item selected.
265
266 if (
267 ( ! isset( $request_arr['tab'] ) ) // the TAB NOT selected and Default.
268 // && ( ! isset( $request_arr['subtab'] ) ) // the SubTab NOT selected.
269 && ( isset( $this_tab['default'] ) ) && ( $this_tab['default'] ) ) {
270 $is_page_selected = true;
271 }
272
273 if (
274 ( isset( $request_arr['tab'] ) ) // TAB Selected.
275 && ( ! isset( $request_arr['subtab'] ) ) // SubTab NOT selected && ! exist || Default.
276 && ( $request_arr['tab'] === $this_tab_tag ) && ( ( 0 === $this_subtab_tag ) || ( $this_subtab['default'] ) ) ) {
277 $is_page_selected = true;
278 }
279
280 if (
281 ( isset( $request_arr['tab'] ) ) // TAB Selected.
282 && ( isset( $request_arr['subtab'] ) ) // SubTab Selected.
283 && ( $request_arr['tab'] === $this_tab_tag )
284 && ( $request_arr['subtab'] === $this_subtab_tag ) ) {
285 $is_page_selected = true;
286 }
287 }
288
289 // If this page activated, then define Current Page parameters.
290 if ( $is_page_selected ) {
291 $this->define_current_page_parameters( $this_tab_tag, $this_tab, $this_subtab_tag, $this_subtab );
292 }
293
294 if ( $is_page_selected ) {
295 break;
296 }
297 }
298
299 return $is_page_selected;
300 }
301
302
303 /**
304 * Define parameters for current selected page
305 *
306 * @param string $this_tab_tag = 'email'.
307 * @param array $this_tab = [ 'title' => 'Emails', 'font_icon' => 'wpbc_icn_mail_outline', 'subtabs' => [ 'new-admin' => [ 'type' => 'subtab', 'title' => 'New Booking (admin)', ... ], ].
308 * @param string $this_subtab_tag = 'new-admin'.
309 * @param array $this_subtab = [ 'type' => 'subtab', 'title' => 'New Booking (admin)', 'page_title' => 'Emails Settings',... ].
310 *
311 * @return void
312 */
313 protected function define_current_page_parameters( $this_tab_tag, $this_tab, $this_subtab_tag, $this_subtab ) {
314
315 $this->current_page_params = array(
316 'tab' => array_merge( $this_tab, array( 'tag' => $this_tab_tag ) ),
317 'subtab' => array_merge( $this_subtab, array( 'tag' => $this_subtab_tag ) ),
318 );
319 }
320
321
322 /**
323 * Get all SubTabs of current opened page Tab
324 *
325 * @param string $menu_in_page_tag - Optional. Menu Tag, the same as $this->in_page ();.
326 *
327 * @return array
328 */
329 protected function get_all_sub_tabs_of_selected_tab( $menu_in_page_tag = false ) {
330
331 if ( false === $menu_in_page_tag ) {
332
333 $this_page = $this->in_page();
334 $this_page_arr = ( is_array( $this_page ) ) ? $this_page : array( $this_page );
335
336 $menu_in_page_tag = $this_page_arr[0];
337 }
338
339 $all_sub_tabs_of_selected_tab = self::$nav_tabs[ $menu_in_page_tag ][ $this->current_page_params['tab']['tag'] ]['subtabs'];
340
341 return $all_sub_tabs_of_selected_tab;
342 }
343
344
345
346 // -----------------------------------------------------------------------------------------------------------------
347 // T A B s - Define
348 // -----------------------------------------------------------------------------------------------------------------
349
350 /**
351 * Define TABS structure. - General structure of tabs for every plugin menu page.
352 *
353 * Function executed after creation menu in class WPBC_Admin_Menus.
354 */
355 public function wpbc_create_plugin_menu_structure_arr() {
356
357 /**
358 * Array (
359 * [wpbc-resources] => Array ()
360 * [wpbc-settings] => Array
361 * (
362 * [general] => Array
363 * (
364 * [title] => General
365 * [page_title] => General Settings
366 * ...
367 * [subtabs] => Array ()
368 * )
369 * [help] => Array
370 * (
371 * [title] => Help
372 * [page_title] =>
373 * ...
374 * [subtabs] => Array ()
375 * )
376 * [form] => Array
377 * (
378 * [title] => Form
379 * [hint] => Customization of Form Fields
380 * [page_title] => Form Fields
381 * ...
382 * [subtabs] => Array
383 * (
384 * [goto-form] => Array
385 * (
386 * [type] => goto-link
387 * [title] => Booking Form Fields
388 * ...
389 * [content] => content
390 * [update] => update
391 * )
392 *
393 * [goto-content-data] => Array
394 * (
395 * [type] => button
396 * [title] => Save Changes
397 * [form] => wpbc_form
398 * ...
399 * )
400 *
401 * )
402 *
403 * )
404 * [payment] => Array
405 * (
406 * [title] => Payments
407 * [hint] => Customization of Payment
408 * [page_title] => Payment Gateways
409 * ...
410 * [subtabs] => Array
411 * (
412 * [paypal] => Array
413 * (
414 * [type] => subtab
415 * [title] => PayPal
416 * ...
417 * )
418 *
419 * [sage] => Array
420 * (
421 * [type] => subtab
422 * [title] => Sage
423 * ...
424 * )
425 *
426 * )
427 *
428 * )
429 *
430 * )
431 *
432 * )
433 */
434 /**
435 * The self::$nav_tabs =
436 *
437 * WP Left Menu | Top Horiz Menu | Vert Left Menu or top submenu
438 * ? page =wpbc-settings & tab=email & subtab=new-admin
439 *
440 * [
441 * wpbc-settings = [
442 * general = [...]
443 * form = [...]
444 * email = [...,
445 * subtabs = [
446 * new-admin = [
447 * type = "subtab"
448 * , ...
449 */
450
451 $this_page = $this->in_page(); // e.g. 'wpbc-settings'.
452 $this_page_arr = ( is_array( $this_page ) ) ? $this_page : array( $this_page ); // it can be like: [ 'wpbc-settings' ].
453
454 // Menu Structure.
455 foreach ( $this_page_arr as $this_page ) {
456
457 // WP Left Menu.
458 if ( ! isset( self::$nav_tabs[ $this_page ] ) ) {
459 self::$nav_tabs[ $this_page ] = array();
460 }
461
462 // Top Horiz Menu - e.g. [ 'calendar_appearance' ] => [ ... ] ].
463 $local_top_main_menu_arr = $this->tabs();
464
465 // Vert Left Menu - or top submenu.
466 $local_vert_left_menu_arr = array();
467
468 foreach ( $local_top_main_menu_arr as $tab_tag => $tab_array ) {
469
470 if ( isset( $tab_array['subtabs'] ) ) {
471 $local_vert_left_menu_arr[ $tab_tag ] = $tab_array['subtabs']; // Create new Subtabs array.
472
473 unset( $local_top_main_menu_arr[ $tab_tag ]['subtabs'] ); // Detach Subtabs array from Tab array. It's required for do not overwrite subtabs with already exist subtabs in previlosly defined tab.
474 } else {
475 $local_vert_left_menu_arr[ $tab_tag ] = array();
476 }
477 }
478
479 foreach ( $local_top_main_menu_arr as $tab_tag => $tab_array ) {
480
481 if ( ! isset( self::$nav_tabs[ $this_page ][ $tab_tag ] ) ) { // If this tab ( for exmaple "payment") declared previously, then does not do anything.
482 self::$nav_tabs[ $this_page ][ $tab_tag ] = array();
483 }
484
485 foreach ( $local_top_main_menu_arr[ $tab_tag ] as $page_prop_name => $page_prop_value ) {
486 if ( 'subtabs' !== $page_prop_name ) {
487 self::$nav_tabs[ $this_page ][ $tab_tag ][ $page_prop_name ] = $page_prop_value;
488 }
489 }
490
491 if ( ! isset( self::$nav_tabs[ $this_page ][ $tab_tag ]['subtabs'] ) ) {
492 self::$nav_tabs[ $this_page ][ $tab_tag ]['subtabs'] = array();
493 }
494 // Merge subtabs (Ex: PayPal and Sage) and attach to current tab: (Ex: payment).
495 self::$nav_tabs[ $this_page ][ $tab_tag ]['subtabs'] = array_merge( self::$nav_tabs[ $this_page ][ $tab_tag ]['subtabs'], $local_vert_left_menu_arr[ $tab_tag ] );
496
497 }
498 }
499 }
500
501
502 /**
503 * Get array of visible TABs
504 * Tabs that do not hided or disbaled
505 *
506 * @param string $menu_in_page_tag - Menu Tag, the same as $this->in_page ();.
507 *
508 * @return type
509 */
510 protected function get_visible_tabs( $menu_in_page_tag ) {
511
512 $visible_tabs = array();
513
514 foreach ( self::$nav_tabs[ $menu_in_page_tag ] as $tab_tag => $tab ) {
515
516 if ( empty( $tab['disabled'] ) && empty( $tab['hided'] ) ) {
517 $visible_tabs[ $tab_tag ] = $tab;
518 }
519 }
520
521 return $visible_tabs;
522 }
523 }
524