PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.6.6
LatePoint – Calendar Booking Plugin for Appointments and Events v5.6.6
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 3 months ago agent_helper.php 3 months ago analytics_helper.php 1 week ago auth_helper.php 6 days ago blocks_helper.php 3 weeks ago booking_helper.php 4 days ago bricks_helper.php 3 months ago bundles_helper.php 4 days ago calendar_helper.php 2 days ago carts_helper.php 3 months ago connector_helper.php 3 months ago csv_helper.php 3 months ago customer_helper.php 1 month ago customer_import_helper.php 1 month ago database_helper.php 1 week ago debug_helper.php 3 months ago defaults_helper.php 3 months ago elementor_helper.php 3 months ago email_helper.php 3 months ago encrypt_helper.php 3 months ago events_helper.php 3 months ago form_helper.php 3 months ago icalendar_helper.php 3 months ago image_helper.php 3 months ago invoices_helper.php 3 weeks ago license_helper.php 3 months ago location_helper.php 3 months ago marketing_systems_helper.php 3 months ago meeting_systems_helper.php 3 months ago menu_helper.php 3 weeks ago meta_helper.php 3 months ago migrations_helper.php 3 months ago money_helper.php 3 months ago notifications_helper.php 3 months ago nps_survey_helper.php 3 months ago order_intent_helper.php 2 months ago orders_helper.php 3 months ago otp_helper.php 3 months ago pages_helper.php 3 months ago params_helper.php 3 months ago payments_helper.php 2 months ago plugin_version_update_helper.php 2 months ago price_breakdown_helper.php 3 months ago process_jobs_helper.php 3 months ago processes_helper.php 3 months ago razorpay_connect_helper.php 1 week ago replacer_helper.php 3 months ago resource_helper.php 4 days ago roles_helper.php 3 weeks ago router_helper.php 3 months ago service_helper.php 3 months ago sessions_helper.php 3 months ago settings_helper.php 1 week ago short_links_systems_helper.php 3 months ago shortcodes_helper.php 3 weeks ago sms_helper.php 3 months ago steps_helper.php 1 week ago stripe_connect_helper.php 1 week ago styles_helper.php 3 months ago support_topics_helper.php 3 months ago time_helper.php 2 months ago timeline_helper.php 2 months ago transaction_helper.php 1 month ago transaction_intent_helper.php 3 months ago util_helper.php 1 month ago version_specific_updates_helper.php 3 months ago whatsapp_helper.php 1 month ago work_periods_helper.php 3 months ago wp_datetime.php 3 months ago wp_user_helper.php 3 months ago
menu_helper.php
427 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 ) ) {
35 return self::$side_menu_items;
36 }
37 $is_update_available = false;
38 $menus = [];
39 $user_role = OsAuthHelper::get_current_user()->backend_user_type;
40 switch ( $user_role ) {
41 case LATEPOINT_USER_TYPE_ADMIN:
42 case LATEPOINT_USER_TYPE_CUSTOM:
43 // ---------------
44 // ADMINISTRATOR MENU
45 // ---------------
46 $menus = array(
47 array(
48 'id' => 'dashboard',
49 'label' => __( 'Dashboard', 'latepoint' ),
50 'icon' => 'latepoint-icon latepoint-icon-dashboard',
51 'link' => OsRouterHelper::build_link( [ 'dashboard', 'index' ] ),
52 ),
53 array(
54 'id' => 'calendar',
55 'label' => __( 'Calendar', 'latepoint' ),
56 'icon' => 'latepoint-icon latepoint-icon-calendar2',
57 'link' => OsRouterHelper::build_link( [ 'calendars', 'view' ] ),
58 ),
59 array(
60 'id' => 'appointments',
61 'label' => __( 'Appointments', 'latepoint' ),
62 'icon' => 'latepoint-icon latepoint-icon-box1',
63 'link' => OsRouterHelper::build_link( [ 'bookings', 'index' ] ),
64 ),
65 array(
66 'id' => 'orders',
67 'label' => __( 'Orders', 'latepoint' ),
68 'icon' => 'latepoint-icon latepoint-icon-book2',
69 'link' => OsRouterHelper::build_link( [ 'orders', 'index' ] ),
70 ),
71 array(
72 'id' => 'payments',
73 'label' => __( 'Payments', 'latepoint' ),
74 'icon' => 'latepoint-icon latepoint-icon-cart',
75 'link' => OsRouterHelper::build_link( [ 'transactions', 'index' ] ),
76 ),
77 array(
78 'id' => 'customers',
79 'label' => __( 'Customers', 'latepoint' ),
80 'icon' => 'latepoint-icon latepoint-icon-user1',
81 'link' => OsRouterHelper::build_link( [ 'customers', 'index' ] ),
82 ),
83 array(
84 'label' => '',
85 'small_label' => __( 'Resources', 'latepoint' ),
86 'menu_section' => 'records',
87 ),
88 array(
89 'id' => 'services',
90 'label' => __( 'Services', 'latepoint' ),
91 'icon' => 'latepoint-icon latepoint-icon-folder',
92 'link' => OsRouterHelper::build_link( [ 'services', 'index' ] ),
93 'children' => array(
94 array(
95 'id' => 'index',
96 'label' => __( 'Services', 'latepoint' ),
97 'icon' => '',
98 'link' => OsRouterHelper::build_link( [ 'services', 'index' ] ),
99 ),
100 array(
101 'id' => 'bundles',
102 'label' => __( 'Bundles', 'latepoint' ),
103 'icon' => '',
104 'link' => OsRouterHelper::build_link( [ 'pro', 'bundles' ] ),
105 ),
106 array(
107 'id' => 'categories',
108 'label' => __( 'Categories', 'latepoint' ),
109 'icon' => '',
110 'link' => OsRouterHelper::build_link( [ 'pro', 'categories' ] ),
111 ),
112 array(
113 'id' => 'service_extras',
114 'label' => __( 'Service Extras', 'latepoint' ),
115 'icon' => '',
116 'link' => OsRouterHelper::build_link( [ 'pro', 'service_extras' ] ),
117 ),
118 ),
119 ),
120 array(
121 'id' => 'agents',
122 'label' => __( 'Agents', 'latepoint' ),
123 'icon' => 'latepoint-icon latepoint-icon-user1',
124 'link' => OsRouterHelper::build_link( [ 'default_agent', 'edit_form' ] ),
125 ),
126 array(
127 'id' => 'locations',
128 'label' => __( 'Locations', 'latepoint' ),
129 'icon' => 'latepoint-icon latepoint-icon-map-marker',
130 'link' => OsRouterHelper::build_link( [ 'pro', 'locations' ] ),
131 ),
132 array(
133 'id' => 'assets',
134 'label' => __( 'Assets', 'latepoint' ),
135 'icon' => 'latepoint-icon latepoint-icon-layers',
136 'link' => OsRouterHelper::build_link( [ 'pro', 'assets' ] ),
137 ),
138 array(
139 'id' => 'coupons',
140 'label' => __( 'Coupons', 'latepoint' ),
141 'icon' => 'latepoint-icon latepoint-icon-tag1',
142 'link' => OsRouterHelper::build_link( [ 'pro', 'coupons' ] ),
143 ),
144 array(
145 'label' => '',
146 'small_label' => __( 'Settings', 'latepoint' ),
147 'menu_section' => 'settings',
148 ),
149 array(
150 'id' => 'settings',
151 'show_notice' => $is_update_available,
152 'label' => __( 'Settings', 'latepoint' ),
153 'icon' => 'latepoint-icon latepoint-icon-cog1',
154 'link' => OsRouterHelper::build_link( [ 'settings', 'general' ] ),
155 'children' => array(
156 array(
157 'id' => 'general',
158 'label' => __( 'General', 'latepoint' ),
159 'icon' => '',
160 'link' => OsRouterHelper::build_link( [ 'settings', 'general' ] ),
161 ),
162 array(
163 'id' => 'schedule',
164 'label' => __( 'Schedule', 'latepoint' ),
165 'icon' => '',
166 'link' => OsRouterHelper::build_link( [ 'settings', 'work_periods' ] ),
167 ),
168 array(
169 'id' => 'taxes',
170 'label' => __( 'Tax', 'latepoint' ),
171 'icon' => '',
172 'link' => OsRouterHelper::build_link( [ 'pro', 'taxes' ] ),
173 ),
174 array(
175 'id' => 'booking_form',
176 'label' => __( 'Booking Form', 'latepoint' ),
177 'icon' => '',
178 'link' => OsRouterHelper::build_link( [ 'booking_form_settings', 'show' ] ),
179 ),
180 array(
181 'id' => 'payments',
182 'label' => __( 'Payments', 'latepoint' ),
183 'icon' => '',
184 'link' => OsRouterHelper::build_link( [ 'settings', 'payments' ] ),
185 ),
186 array(
187 'id' => 'notifications',
188 'label' => __( 'Notifications', 'latepoint' ),
189 'icon' => '',
190 'link' => OsRouterHelper::build_link( [ 'settings', 'notifications' ] ),
191 ),
192 array(
193 'id' => 'roles',
194 'label' => __( 'Roles', 'latepoint' ),
195 'icon' => '',
196 'link' => OsRouterHelper::build_link( [ 'pro', 'roles' ] ),
197 ),
198 array(
199 'id' => 'white_label',
200 'label' => __( 'White Label', 'latepoint' ),
201 'icon' => '',
202 'link' => OsRouterHelper::build_link( [ 'pro', 'white_label' ] ),
203 ),
204 ),
205 ),
206 array(
207 'id' => 'processes',
208 'label' => __( 'Automation', 'latepoint' ),
209 'icon' => 'latepoint-icon latepoint-icon-play',
210 'link' => OsRouterHelper::build_link( [ 'processes', 'index' ] ),
211 'children' => array(
212 array(
213 'label' => __( 'Workflows', 'latepoint' ),
214 'icon' => '',
215 'link' => OsRouterHelper::build_link( [ 'processes', 'index' ] ),
216 ),
217 array(
218 'label' => __( 'Scheduled Jobs', 'latepoint' ),
219 'icon' => '',
220 'link' => OsRouterHelper::build_link( [ 'process_jobs', 'index' ] ),
221 ),
222 array(
223 'label' => __( 'Activity Log', 'latepoint' ),
224 'icon' => '',
225 'link' => OsRouterHelper::build_link( [ 'activities', 'index' ] ),
226 ),
227 ),
228 ),
229 array(
230 'id' => 'integrations',
231 'label' => __( 'Integrations', 'latepoint' ),
232 'icon' => 'latepoint-icon latepoint-icon-windows',
233 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_meeting_systems' ] ),
234 'children' => array(
235 array(
236 'id' => 'meetings',
237 'label' => __( 'Meetings', 'latepoint' ),
238 'icon' => '',
239 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_meeting_systems' ] ),
240 ),
241 array(
242 'id' => 'calendars',
243 'label' => __( 'Calendars', 'latepoint' ),
244 'icon' => '',
245 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_calendars' ] ),
246 ),
247 array(
248 'id' => 'meetings',
249 'label' => __( 'Marketing', 'latepoint' ),
250 'icon' => '',
251 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_marketing_systems' ] ),
252 ),
253 array(
254 'id' => 'short_links',
255 'label' => __( 'Short Links', 'latepoint' ),
256 'icon' => '',
257 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_short_links_systems' ] ),
258 ),
259 ),
260 ),
261 array(
262 'id' => 'form_fields',
263 'label' => __( 'Form Fields', 'latepoint' ),
264 'icon' => 'latepoint-icon latepoint-icon-browser',
265 'link' => OsRouterHelper::build_link( [ 'form_fields', 'default_form_fields' ] ),
266 ),
267 );
268 break;
269 case LATEPOINT_USER_TYPE_AGENT:
270 // ---------------
271 // AGENT MENU
272 // ---------------
273 $menus = array(
274 array(
275 'id' => 'dashboard',
276 'label' => __( 'Dashboard', 'latepoint' ),
277 'icon' => 'latepoint-icon latepoint-icon-dashboard',
278 'link' => OsRouterHelper::build_link( [ 'dashboard', 'index' ] ),
279 ),
280 array(
281 'id' => 'calendar',
282 'label' => __( 'Calendar', 'latepoint' ),
283 'icon' => 'latepoint-icon latepoint-icon-calendar2',
284 'link' => OsRouterHelper::build_link( [ 'calendars', 'view' ] ),
285 ),
286 array(
287 'id' => 'appointments',
288 'label' => __( 'Appointments', 'latepoint' ),
289 'icon' => 'latepoint-icon latepoint-icon-box1',
290 'link' => OsRouterHelper::build_link( [ 'bookings', 'index' ] ),
291 ),
292 array(
293 'id' => 'orders',
294 'label' => __( 'Orders', 'latepoint' ),
295 'icon' => 'latepoint-icon latepoint-icon-book2',
296 'link' => OsRouterHelper::build_link( [ 'orders', 'index' ] ),
297 ),
298 array(
299 'id' => 'payments',
300 'label' => __( 'Payments', 'latepoint' ),
301 'icon' => 'latepoint-icon latepoint-icon-cart',
302 'link' => OsRouterHelper::build_link( [ 'transactions', 'index' ] ),
303 ),
304 array(
305 'id' => 'customers',
306 'label' => __( 'Customers', 'latepoint' ),
307 'icon' => 'latepoint-icon latepoint-icon-user1',
308 'link' => OsRouterHelper::build_link( [ 'customers', 'index' ] ),
309 ),
310 array(
311 'id' => 'services',
312 'label' => __( 'Services', 'latepoint' ),
313 'icon' => 'latepoint-icon latepoint-icon-folder',
314 'link' => OsRouterHelper::build_link( [ 'services', 'index' ] ),
315 'children' => array(
316 array(
317 'id' => 'index',
318 'label' => __( 'Services', 'latepoint' ),
319 'icon' => '',
320 'link' => OsRouterHelper::build_link( [ 'services', 'index' ] ),
321 ),
322 array(
323 'id' => 'bundles',
324 'label' => __( 'Bundles', 'latepoint' ),
325 'icon' => '',
326 'link' => OsRouterHelper::build_link( [ 'pro', 'bundles' ] ),
327 ),
328 array(
329 'id' => 'categories',
330 'label' => __( 'Categories', 'latepoint' ),
331 'icon' => '',
332 'link' => OsRouterHelper::build_link( [ 'pro', 'categories' ] ),
333 ),
334 array(
335 'id' => 'service_extras',
336 'label' => __( 'Service Extras', 'latepoint' ),
337 'icon' => '',
338 'link' => OsRouterHelper::build_link( [ 'pro', 'service_extras' ] ),
339 ),
340 ),
341 ),
342 array(
343 'id' => 'locations',
344 'label' => __( 'Locations', 'latepoint' ),
345 'icon' => 'latepoint-icon latepoint-icon-map-marker',
346 'link' => OsRouterHelper::build_link( [ 'pro', 'locations' ] ),
347 ),
348 array(
349 'id' => 'assets',
350 'label' => __( 'Assets', 'latepoint' ),
351 'icon' => 'latepoint-icon latepoint-icon-layers',
352 'link' => OsRouterHelper::build_link( [ 'pro', 'assets' ] ),
353 ),
354 array(
355 'id' => 'coupons',
356 'label' => __( 'Coupons', 'latepoint' ),
357 'icon' => 'latepoint-icon latepoint-icon-tag1',
358 'link' => OsRouterHelper::build_link( [ 'pro', 'coupons' ] ),
359 ),
360 array(
361 'id' => 'settings',
362 'label' => __( 'Settings', 'latepoint' ),
363 'icon' => 'latepoint-icon latepoint-icon-cog1',
364 'link' => OsRouterHelper::build_link( [ 'agents', 'edit_form' ], array( 'id' => OsAuthHelper::get_logged_in_agent_id() ) ),
365 ),
366 );
367 break;
368 }
369 /**
370 * Filters side menu items
371 *
372 * @since 4.7.0
373 * @hook latepoint_side_menu
374 *
375 * @param {array} $menus Array of side menu items in a format ['id' => '', 'label' => '', 'icon' => '', 'link' => '', 'children' => [ ['label' => '', 'icon' => '', 'link' => ''] ]
376 * @returns {array} Filtered array of side menu items
377 */
378 $menus = apply_filters( 'latepoint_side_menu', $menus, $user_role );
379 self::$side_menu_items = self::filter_by_user_capabilities( $menus );
380 return self::$side_menu_items;
381 }
382
383 public static function filter_by_user_capabilities( array $menus ): array {
384 $total_menu_items = count( $menus );
385 for ( $i = 0; $i < $total_menu_items; $i++ ) {
386 if ( ! empty( $menus[ $i ]['children'] ) ) {
387 $menus[ $i ]['children'] = self::filter_by_user_capabilities( $menus[ $i ]['children'] );
388 }
389 if ( ! empty( $menus[ $i ]['link'] ) ) {
390 parse_str( wp_parse_url( $menus[ $i ]['link'] )['query'] ?? '', $params );
391 if ( empty( $params['route_name'] ) ) {
392 continue; // not a controller__action route, could be custom URL
393 }
394
395 $split_route_name = explode( '__', $params['route_name'] );
396 if ( empty( $split_route_name ) || count( $split_route_name ) != 2 ) {
397 continue; // not a controller__action route, could be custom URL
398 }
399
400 $controller_name = $split_route_name[0];
401 $action = $split_route_name[1];
402
403 if ( empty( $controller_name ) || empty( $action ) ) {
404 continue; // not a controller__action route, could be custom URL
405 }
406 $controller_name = str_replace( '_', '', ucwords( $controller_name, '_' ) );
407 $controller_class_name = 'Os' . $controller_name . 'Controller';
408 $capabilities = OsRolesHelper::get_capabilities_required_for_controller_action( $controller_class_name, $action );
409 if ( ! OsAuthHelper::get_current_user()->has_capability( $capabilities ) ) {
410 unset( $menus[ $i ] );
411 }
412 }
413 }
414 // clean out label items that have no actual items left after them
415 $menus = array_values( $menus );
416 $total_menu_items = count( $menus );
417 $clean_menu_items = [];
418 for ( $i = 0; $i < $total_menu_items; $i++ ) {
419 if ( ! empty( $menus[ $i ]['small_label'] ) && ( ! empty( $menus[ $i + 1 ]['small_label'] ) || $i + 1 == $total_menu_items ) ) {
420 continue;
421 }
422 $clean_menu_items[] = $menus[ $i ];
423 }
424 return $clean_menu_items;
425 }
426 }
427