PluginProbe
Booking Calendar / 10.11.2
Booking Calendar v10.11.2
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.2, at includes/ui_settings/class-menu-structure.php

510 lines 21.3 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 ) { // Get First Tab Element, which MUST be subtab element, all other tabs, can be links, not really showing content!!!
234 break;
235 }
236
237 if ( empty( $this_tab ) ) {
238 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.
239 }
240
241 $this_subtab_tag = 0;
242 $this_subtab = array( 'default' => false );
243
244 if ( isset( $this_tab['subtabs'] ) ) {
245 foreach ( $this_tab['subtabs'] as $temp_this_subtab_tag => $temp_this_subtab ) {
246
247 // Get First Subtab element from subtabs array.
248 if ( 'subtab' === $temp_this_subtab['type'] ) {
249 $this_subtab_tag = $temp_this_subtab_tag;
250 $this_subtab = $temp_this_subtab;
251 break;
252 }
253 }
254 }
255
256 if ( ( isset( $request_arr['page'] ) ) && ( $this_page === $request_arr['page'] ) ) { // We are inside of this page. Menu item selected.
257
258 if (
259 ( ! isset( $request_arr['tab'] ) ) // the TAB NOT selected and Default.
260 // && ( ! isset( $request_arr['subtab'] ) ) // the SubTab NOT selected.
261 && ( isset( $this_tab['default'] ) ) && ( $this_tab['default'] ) ) {
262 $is_page_selected = true;
263 }
264
265 if (
266 ( isset( $request_arr['tab'] ) ) // TAB Selected.
267 && ( ! isset( $request_arr['subtab'] ) ) // SubTab NOT selected && ! exist || Default.
268 && ( $request_arr['tab'] === $this_tab_tag ) && ( ( 0 === $this_subtab_tag ) || ( $this_subtab['default'] ) ) ) {
269 $is_page_selected = true;
270 }
271
272 if (
273 ( isset( $request_arr['tab'] ) ) // TAB Selected.
274 && ( isset( $request_arr['subtab'] ) ) // SubTab Selected.
275 && ( $request_arr['tab'] === $this_tab_tag )
276 && ( $request_arr['subtab'] === $this_subtab_tag ) ) {
277 $is_page_selected = true;
278 }
279 }
280
281 // If this page activated, then define Current Page parameters.
282 if ( $is_page_selected ) {
283 $this->define_current_page_parameters( $this_tab_tag, $this_tab, $this_subtab_tag, $this_subtab );
284 }
285
286 if ( $is_page_selected ) {
287 break;
288 }
289 }
290
291 return $is_page_selected;
292 }
293
294
295 /**
296 * Define parameters for current selected page
297 *
298 * @param string $this_tab_tag = 'email'.
299 * @param array $this_tab = [ 'title' => 'Emails', 'font_icon' => 'wpbc_icn_mail_outline', 'subtabs' => [ 'new-admin' => [ 'type' => 'subtab', 'title' => 'New Booking (admin)', ... ], ].
300 * @param string $this_subtab_tag = 'new-admin'.
301 * @param array $this_subtab = [ 'type' => 'subtab', 'title' => 'New Booking (admin)', 'page_title' => 'Emails Settings',... ].
302 *
303 * @return void
304 */
305 protected function define_current_page_parameters( $this_tab_tag, $this_tab, $this_subtab_tag, $this_subtab ) {
306
307 $this->current_page_params = array(
308 'tab' => array_merge( $this_tab, array( 'tag' => $this_tab_tag ) ),
309 'subtab' => array_merge( $this_subtab, array( 'tag' => $this_subtab_tag ) ),
310 );
311 }
312
313
314 /**
315 * Get all SubTabs of current opened page Tab
316 *
317 * @param string $menu_in_page_tag - Optional. Menu Tag, the same as $this->in_page ();.
318 *
319 * @return array
320 */
321 protected function get_all_sub_tabs_of_selected_tab( $menu_in_page_tag = false ) {
322
323 if ( false === $menu_in_page_tag ) {
324
325 $this_page = $this->in_page();
326 $this_page_arr = ( is_array( $this_page ) ) ? $this_page : array( $this_page );
327
328 $menu_in_page_tag = $this_page_arr[0];
329 }
330
331 $all_sub_tabs_of_selected_tab = self::$nav_tabs[ $menu_in_page_tag ][ $this->current_page_params['tab']['tag'] ]['subtabs'];
332
333 return $all_sub_tabs_of_selected_tab;
334 }
335
336
337
338 // -----------------------------------------------------------------------------------------------------------------
339 // T A B s - Define
340 // -----------------------------------------------------------------------------------------------------------------
341
342 /**
343 * Define TABS structure. - General structure of tabs for every plugin menu page.
344 *
345 * Function executed after creation menu in class WPBC_Admin_Menus.
346 */
347 public function wpbc_create_plugin_menu_structure_arr() {
348
349 /**
350 * Array (
351 * [wpbc-resources] => Array ()
352 * [wpbc-settings] => Array
353 * (
354 * [general] => Array
355 * (
356 * [title] => General
357 * [page_title] => General Settings
358 * ...
359 * [subtabs] => Array ()
360 * )
361 * [help] => Array
362 * (
363 * [title] => Help
364 * [page_title] =>
365 * ...
366 * [subtabs] => Array ()
367 * )
368 * [form] => Array
369 * (
370 * [title] => Form
371 * [hint] => Customization of Form Fields
372 * [page_title] => Form Fields
373 * ...
374 * [subtabs] => Array
375 * (
376 * [goto-form] => Array
377 * (
378 * [type] => goto-link
379 * [title] => Booking Form Fields
380 * ...
381 * [content] => content
382 * [update] => update
383 * )
384 *
385 * [goto-content-data] => Array
386 * (
387 * [type] => button
388 * [title] => Save Changes
389 * [form] => wpbc_form
390 * ...
391 * )
392 *
393 * )
394 *
395 * )
396 * [payment] => Array
397 * (
398 * [title] => Payments
399 * [hint] => Customization of Payment
400 * [page_title] => Payment Gateways
401 * ...
402 * [subtabs] => Array
403 * (
404 * [paypal] => Array
405 * (
406 * [type] => subtab
407 * [title] => PayPal
408 * ...
409 * )
410 *
411 * [sage] => Array
412 * (
413 * [type] => subtab
414 * [title] => Sage
415 * ...
416 * )
417 *
418 * )
419 *
420 * )
421 *
422 * )
423 *
424 * )
425 */
426 /**
427 * The self::$nav_tabs =
428 *
429 * WP Left Menu | Top Horiz Menu | Vert Left Menu or top submenu
430 * ? page =wpbc-settings & tab=email & subtab=new-admin
431 *
432 * [
433 * wpbc-settings = [
434 * general = [...]
435 * form = [...]
436 * email = [...,
437 * subtabs = [
438 * new-admin = [
439 * type = "subtab"
440 * , ...
441 */
442
443 $this_page = $this->in_page(); // e.g. 'wpbc-settings'.
444 $this_page_arr = ( is_array( $this_page ) ) ? $this_page : array( $this_page ); // it can be like: [ 'wpbc-settings' ].
445
446 // Menu Structure.
447 foreach ( $this_page_arr as $this_page ) {
448
449 // WP Left Menu.
450 if ( ! isset( self::$nav_tabs[ $this_page ] ) ) {
451 self::$nav_tabs[ $this_page ] = array();
452 }
453
454 // Top Horiz Menu - e.g. [ 'calendar_appearance' ] => [ ... ] ].
455 $local_top_main_menu_arr = $this->tabs();
456
457 // Vert Left Menu - or top submenu.
458 $local_vert_left_menu_arr = array();
459
460 foreach ( $local_top_main_menu_arr as $tab_tag => $tab_array ) {
461
462 if ( isset( $tab_array['subtabs'] ) ) {
463 $local_vert_left_menu_arr[ $tab_tag ] = $tab_array['subtabs']; // Create new Subtabs array.
464
465 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.
466 } else {
467 $local_vert_left_menu_arr[ $tab_tag ] = array();
468 }
469 }
470
471 foreach ( $local_top_main_menu_arr as $tab_tag => $tab_array ) {
472
473 if ( ! isset( self::$nav_tabs[ $this_page ][ $tab_tag ] ) ) { // If this tab ( for exmaple "payment") declared previously, then does not do anything.
474
475 self::$nav_tabs[ $this_page ][ $tab_tag ] = $local_top_main_menu_arr[ $tab_tag ];
476 self::$nav_tabs[ $this_page ][ $tab_tag ]['subtabs'] = array();
477 }
478
479 if ( isset( self::$nav_tabs[ $this_page ] ) ) {
480 // Merge subtabs (Ex: PayPal and Sage) and attach to current tab: (Ex: payment).
481 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 ] );
482 }
483 }
484 }
485 }
486
487
488 /**
489 * Get array of visible TABs
490 * Tabs that do not hided or disbaled
491 *
492 * @param string $menu_in_page_tag - Menu Tag, the same as $this->in_page ();.
493 *
494 * @return type
495 */
496 protected function get_visible_tabs( $menu_in_page_tag ) {
497
498 $visible_tabs = array();
499
500 foreach ( self::$nav_tabs[ $menu_in_page_tag ] as $tab_tag => $tab ) {
501
502 if ( empty( $tab['disabled'] ) && empty( $tab['hided'] ) ) {
503 $visible_tabs[ $tab_tag ] = $tab;
504 }
505 }
506
507 return $visible_tabs;
508 }
509 }
510