PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.2.10
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.2.10
5.6.11 5.6.10 5.6.9 5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / helpers / menu_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 1 year ago agent_helper.php 1 year ago analytics_helper.php 6 months ago auth_helper.php 6 months ago blocks_helper.php 1 year ago booking_helper.php 6 months ago bricks_helper.php 1 year ago bundles_helper.php 1 year ago calendar_helper.php 11 months ago carts_helper.php 1 year ago connector_helper.php 11 months ago csv_helper.php 6 months ago customer_helper.php 6 months ago customer_import_helper.php 6 months ago database_helper.php 11 months ago debug_helper.php 1 year ago defaults_helper.php 1 year ago elementor_helper.php 1 year ago email_helper.php 11 months ago encrypt_helper.php 1 year ago events_helper.php 11 months ago form_helper.php 6 months ago icalendar_helper.php 1 year ago image_helper.php 1 year ago invoices_helper.php 6 months ago license_helper.php 1 year ago location_helper.php 1 year ago marketing_systems_helper.php 1 year ago meeting_systems_helper.php 1 year ago menu_helper.php 11 months ago meta_helper.php 6 months ago migrations_helper.php 1 year ago money_helper.php 6 months ago notifications_helper.php 11 months ago nps_survey_helper.php 6 months ago order_intent_helper.php 11 months ago orders_helper.php 1 year ago otp_helper.php 11 months ago pages_helper.php 1 year ago params_helper.php 1 year ago payments_helper.php 1 year ago price_breakdown_helper.php 1 year ago process_jobs_helper.php 1 year ago processes_helper.php 1 year ago replacer_helper.php 1 year ago resource_helper.php 1 year ago roles_helper.php 8 months ago router_helper.php 1 year ago service_helper.php 1 year ago sessions_helper.php 6 months ago settings_helper.php 6 months ago short_links_systems_helper.php 11 months ago shortcodes_helper.php 11 months ago sms_helper.php 1 year ago steps_helper.php 6 months ago stripe_connect_helper.php 11 months ago styles_helper.php 11 months ago support_topics_helper.php 1 year ago time_helper.php 11 months ago timeline_helper.php 11 months ago transaction_helper.php 6 months ago transaction_intent_helper.php 1 year ago util_helper.php 8 months ago version_specific_updates_helper.php 11 months ago whatsapp_helper.php 1 year ago work_periods_helper.php 7 months ago wp_datetime.php 1 year ago wp_user_helper.php 1 year ago
menu_helper.php
168 lines
1 <?php
2
3 class OsMenuHelper {
4
5 public static array $side_menu_items;
6
7 public static function get_menu_items_by_id($query){
8 $menus = self::get_side_menu_items();
9 foreach($menus as $menu_item){
10 if(isset($menu_item['id']) && $menu_item['id'] == $query){
11 if(isset($menu_item['children'])){
12 // has sub items
13 return $menu_item['children'];
14 }else{
15 // no sub items
16 return $menu_item['label'];
17 }
18 }
19 }
20 return false;
21 }
22
23 public static function get_label_by_id($query){
24 $menus = self::get_side_menu_items();
25 foreach($menus as $menu_item){
26 if(isset($menu_item['id']) && $menu_item['id'] == $query){
27 return $menu_item['label'];
28 }
29 }
30 return false;
31 }
32
33 public static function get_side_menu_items() {
34 if(isset(self::$side_menu_items)) return self::$side_menu_items;
35 $is_update_available = false;
36 $menus = [];
37 $user_role = OsAuthHelper::get_current_user()->backend_user_type;
38 switch($user_role){
39 case LATEPOINT_USER_TYPE_ADMIN:
40 case LATEPOINT_USER_TYPE_CUSTOM:
41 // ---------------
42 // ADMINISTRATOR MENU
43 // ---------------
44 $menus = array(
45 array( 'id' => 'dashboard', 'label' => __( 'Dashboard', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-dashboard', 'link' => OsRouterHelper::build_link(['dashboard', 'index'])),
46 array( 'id' => 'calendar', 'label' => __( 'Calendar', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-calendar2', 'link' => OsRouterHelper::build_link(['calendars', 'view'])),
47 array( 'id' => 'appointments', 'label' => __( 'Appointments', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-box1', 'link' => OsRouterHelper::build_link(['bookings', 'index'])),
48 array( 'id' => 'orders', 'label' => __( 'Orders', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-book2', 'link' => OsRouterHelper::build_link(['orders', 'index'])),
49 array( 'id' => 'payments', 'label' => __( 'Payments', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-cart', 'link' => OsRouterHelper::build_link(['transactions', 'index'])),
50 array( 'id' => 'customers', 'label' => __( 'Customers', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-user1', 'link' => OsRouterHelper::build_link(['customers', 'index'])),
51 array('label' => '', 'small_label' => __('Resources', 'latepoint'), 'menu_section' => 'records'),
52 array( 'id' => 'services', 'label' => __( 'Services', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-folder', 'link' => OsRouterHelper::build_link(['services', 'index']),
53 'children' => array(
54 array('id' => 'index','label' => __( 'Services', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['services', 'index'])),
55 array('id' => 'bundles','label' => __( 'Bundles', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'bundles'])),
56 array('id' => 'categories','label' => __( 'Categories', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'categories'])),
57 array('id' => 'service_extras','label' => __( 'Service Extras', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'service_extras'])),
58 )
59 ),
60 array( 'id' => 'agents', 'label' => __( 'Agents', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-user1', 'link' => OsRouterHelper::build_link(['default_agent', 'edit_form'])),
61 array( 'id' => 'locations', 'label' => __( 'Locations', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-map-marker', 'link' => OsRouterHelper::build_link(['pro', 'locations'])),
62 array('id' => 'coupons', 'label' => __( 'Coupons', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-tag1', 'link' => OsRouterHelper::build_link(['pro', 'coupons'])),
63 array('label' => '', 'small_label' => __('Settings', 'latepoint'), 'menu_section' => 'settings'),
64 array( 'id' => 'settings', 'show_notice' => $is_update_available, 'label' => __( 'Settings', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-cog1', 'link' => OsRouterHelper::build_link(['settings', 'general']),
65 'children' => array(
66 array('id' => 'general', 'label' => __( 'General', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['settings', 'general'])),
67 array('id' => 'schedule', 'label' => __( 'Schedule', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['settings', 'work_periods'])),
68 array('id' => 'taxes', 'label' => __( 'Tax', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'taxes'])),
69 array('id' => 'booking_form', 'label' => __( 'Booking Form', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['booking_form_settings', 'show'])),
70 array('id' => 'payments', 'label' => __( 'Payments', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['settings', 'payments'])),
71 array('id' => 'notifications', 'label' => __( 'Notifications', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['settings', 'notifications'])),
72 array('id' => 'roles', 'label' => __( 'Roles', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'roles'])),
73 )
74 ),
75 array( 'id' => 'processes', 'label' => __( 'Automation', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-play', 'link' => OsRouterHelper::build_link(['processes', 'index']),
76 'children' => array(
77 array('label' => __('Workflows', 'latepoint'), 'icon' => '', 'link' => OsRouterHelper::build_link(['processes', 'index'])),
78 array('label' => __('Scheduled Jobs', 'latepoint'), 'icon' => '', 'link' => OsRouterHelper::build_link(['process_jobs', 'index'])),
79 array('label' => __('Activity Log', 'latepoint'), 'icon' => '', 'link' => OsRouterHelper::build_link(['activities', 'index'])),
80 )
81 ),
82 array( 'id' => 'integrations', 'label' => __( 'Integrations', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-windows', 'link' => OsRouterHelper::build_link(['integrations', 'external_meeting_systems']),
83 'children' => array(
84 array('id' => 'meetings', 'label' => __( 'Meetings', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['integrations', 'external_meeting_systems'])),
85 array('id' => 'calendars', 'label' => __( 'Calendars', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['integrations', 'external_calendars'])),
86 array('id' => 'meetings', 'label' => __( 'Marketing', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['integrations', 'external_marketing_systems'])),
87 array('id' => 'short_links', 'label' => __( 'Short Links', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['integrations', 'external_short_links_systems'])),
88 )
89 ),
90 array( 'id' => 'form_fields', 'label' => __( 'Form Fields', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-browser', 'link' => OsRouterHelper::build_link(['form_fields', 'default_form_fields'])),
91 );
92 break;
93 case LATEPOINT_USER_TYPE_AGENT:
94 // ---------------
95 // AGENT MENU
96 // ---------------
97 $menus = array(
98 array( 'id' => 'dashboard', 'label' => __( 'Dashboard', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-dashboard', 'link' => OsRouterHelper::build_link(['dashboard', 'index'])),
99 array( 'id' => 'calendar', 'label' => __( 'Calendar', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-calendar2', 'link' => OsRouterHelper::build_link(['calendars', 'view'])),
100 array( 'id' => 'appointments', 'label' => __( 'Appointments', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-box1', 'link' => OsRouterHelper::build_link(['bookings', 'index'])),
101 array( 'id' => 'orders', 'label' => __( 'Orders', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-book2', 'link' => OsRouterHelper::build_link(['orders', 'index'])),
102 array( 'id' => 'payments', 'label' => __( 'Payments', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-cart', 'link' => OsRouterHelper::build_link(['transactions', 'index'])),
103 array( 'id' => 'customers', 'label' => __( 'Customers', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-user1', 'link' => OsRouterHelper::build_link(['customers', 'index'])),
104 array( 'id' => 'services', 'label' => __( 'Services', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-folder', 'link' => OsRouterHelper::build_link(['services', 'index']),
105 'children' => array(
106 array('id' => 'index','label' => __( 'Services', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['services', 'index'])),
107 array('id' => 'bundles','label' => __( 'Bundles', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'bundles'])),
108 array('id' => 'categories','label' => __( 'Categories', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'categories'])),
109 array('id' => 'service_extras','label' => __( 'Service Extras', 'latepoint' ), 'icon' => '', 'link' => OsRouterHelper::build_link(['pro', 'service_extras'])),
110 )
111 ),
112 array( 'id' => 'locations', 'label' => __( 'Locations', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-map-marker', 'link' => OsRouterHelper::build_link(['pro', 'locations'])),
113 array('id' => 'coupons', 'label' => __( 'Coupons', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-tag1', 'link' => OsRouterHelper::build_link(['pro', 'coupons'])),
114 array( 'id' => 'settings', 'label' => __( 'Settings', 'latepoint' ), 'icon' => 'latepoint-icon latepoint-icon-cog1', 'link' => OsRouterHelper::build_link(['agents', 'edit_form'], array('id' => OsAuthHelper::get_logged_in_agent_id()) ))
115 );
116 break;
117 }
118 /**
119 * Filters side menu items
120 *
121 * @since 4.7.0
122 * @hook latepoint_side_menu
123 *
124 * @param {array} $menus Array of side menu items in a format ['id' => '', 'label' => '', 'icon' => '', 'link' => '', 'children' => [ ['label' => '', 'icon' => '', 'link' => ''] ]
125 * @returns {array} Filtered array of side menu items
126 */
127 $menus = apply_filters('latepoint_side_menu', $menus, $user_role);
128 self::$side_menu_items = self::filter_by_user_capabilities($menus);
129 return self::$side_menu_items;
130 }
131
132 public static function filter_by_user_capabilities(array $menus): array{
133 $total_menu_items = count($menus);
134 for($i = 0; $i < $total_menu_items; $i++){
135 if(!empty($menus[$i]['children'])){
136 $menus[$i]['children'] = self::filter_by_user_capabilities($menus[$i]['children']);
137 }
138 if(!empty($menus[$i]['link'])){
139 parse_str(wp_parse_url($menus[$i]['link'])['query'] ?? '',$params);
140 if(empty($params['route_name'])) continue; // not a controller__action route, could be custom URL
141
142 $split_route_name = explode('__', $params['route_name']);
143 if(empty($split_route_name) || count($split_route_name) != 2) continue; // not a controller__action route, could be custom URL
144
145 $controller_name = $split_route_name[0];
146 $action = $split_route_name[1];
147
148 if(empty($controller_name) || empty($action)) continue; // not a controller__action route, could be custom URL
149 $controller_name = str_replace('_', '', ucwords($controller_name, '_'));
150 $controller_class_name = 'Os'.$controller_name.'Controller';
151 $capabilities = OsRolesHelper::get_capabilities_required_for_controller_action($controller_class_name, $action);
152 if(!OsAuthHelper::get_current_user()->has_capability($capabilities)) unset($menus[$i]);
153 }
154 }
155 // clean out label items that have no actual items left after them
156 $menus = array_values($menus);
157 $total_menu_items = count($menus);
158 $clean_menu_items = [];
159 for($i = 0; $i < $total_menu_items; $i++){
160 if(!empty($menus[$i]['small_label']) && (!empty($menus[$i + 1]['small_label']) || $i + 1 == $total_menu_items)){
161 continue;
162 }
163 $clean_menu_items[] = $menus[$i];
164 }
165 return $clean_menu_items;
166 }
167
168 }