PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.5.0
LatePoint – Calendar Booking Plugin for Appointments and Events v5.5.0
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 2 months ago auth_helper.php 2 months ago blocks_helper.php 3 months ago booking_helper.php 2 months ago bricks_helper.php 3 months ago bundles_helper.php 3 months ago calendar_helper.php 3 months ago carts_helper.php 3 months ago connector_helper.php 3 months ago csv_helper.php 3 months ago customer_helper.php 3 months ago customer_import_helper.php 3 months ago database_helper.php 3 months 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 2 months 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 2 months 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 3 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 replacer_helper.php 3 months ago resource_helper.php 3 months ago roles_helper.php 3 months ago router_helper.php 3 months ago service_helper.php 3 months ago sessions_helper.php 3 months ago settings_helper.php 2 months ago short_links_systems_helper.php 3 months ago shortcodes_helper.php 2 months ago sms_helper.php 3 months ago steps_helper.php 3 months ago stripe_connect_helper.php 2 months 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 3 months ago transaction_intent_helper.php 3 months ago util_helper.php 3 months ago version_specific_updates_helper.php 3 months ago whatsapp_helper.php 3 months ago work_periods_helper.php 3 months ago wp_datetime.php 3 months ago wp_user_helper.php 3 months ago
menu_helper.php
421 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 ),
199 ),
200 array(
201 'id' => 'processes',
202 'label' => __( 'Automation', 'latepoint' ),
203 'icon' => 'latepoint-icon latepoint-icon-play',
204 'link' => OsRouterHelper::build_link( [ 'processes', 'index' ] ),
205 'children' => array(
206 array(
207 'label' => __( 'Workflows', 'latepoint' ),
208 'icon' => '',
209 'link' => OsRouterHelper::build_link( [ 'processes', 'index' ] ),
210 ),
211 array(
212 'label' => __( 'Scheduled Jobs', 'latepoint' ),
213 'icon' => '',
214 'link' => OsRouterHelper::build_link( [ 'process_jobs', 'index' ] ),
215 ),
216 array(
217 'label' => __( 'Activity Log', 'latepoint' ),
218 'icon' => '',
219 'link' => OsRouterHelper::build_link( [ 'activities', 'index' ] ),
220 ),
221 ),
222 ),
223 array(
224 'id' => 'integrations',
225 'label' => __( 'Integrations', 'latepoint' ),
226 'icon' => 'latepoint-icon latepoint-icon-windows',
227 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_meeting_systems' ] ),
228 'children' => array(
229 array(
230 'id' => 'meetings',
231 'label' => __( 'Meetings', 'latepoint' ),
232 'icon' => '',
233 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_meeting_systems' ] ),
234 ),
235 array(
236 'id' => 'calendars',
237 'label' => __( 'Calendars', 'latepoint' ),
238 'icon' => '',
239 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_calendars' ] ),
240 ),
241 array(
242 'id' => 'meetings',
243 'label' => __( 'Marketing', 'latepoint' ),
244 'icon' => '',
245 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_marketing_systems' ] ),
246 ),
247 array(
248 'id' => 'short_links',
249 'label' => __( 'Short Links', 'latepoint' ),
250 'icon' => '',
251 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_short_links_systems' ] ),
252 ),
253 ),
254 ),
255 array(
256 'id' => 'form_fields',
257 'label' => __( 'Form Fields', 'latepoint' ),
258 'icon' => 'latepoint-icon latepoint-icon-browser',
259 'link' => OsRouterHelper::build_link( [ 'form_fields', 'default_form_fields' ] ),
260 ),
261 );
262 break;
263 case LATEPOINT_USER_TYPE_AGENT:
264 // ---------------
265 // AGENT MENU
266 // ---------------
267 $menus = array(
268 array(
269 'id' => 'dashboard',
270 'label' => __( 'Dashboard', 'latepoint' ),
271 'icon' => 'latepoint-icon latepoint-icon-dashboard',
272 'link' => OsRouterHelper::build_link( [ 'dashboard', 'index' ] ),
273 ),
274 array(
275 'id' => 'calendar',
276 'label' => __( 'Calendar', 'latepoint' ),
277 'icon' => 'latepoint-icon latepoint-icon-calendar2',
278 'link' => OsRouterHelper::build_link( [ 'calendars', 'view' ] ),
279 ),
280 array(
281 'id' => 'appointments',
282 'label' => __( 'Appointments', 'latepoint' ),
283 'icon' => 'latepoint-icon latepoint-icon-box1',
284 'link' => OsRouterHelper::build_link( [ 'bookings', 'index' ] ),
285 ),
286 array(
287 'id' => 'orders',
288 'label' => __( 'Orders', 'latepoint' ),
289 'icon' => 'latepoint-icon latepoint-icon-book2',
290 'link' => OsRouterHelper::build_link( [ 'orders', 'index' ] ),
291 ),
292 array(
293 'id' => 'payments',
294 'label' => __( 'Payments', 'latepoint' ),
295 'icon' => 'latepoint-icon latepoint-icon-cart',
296 'link' => OsRouterHelper::build_link( [ 'transactions', 'index' ] ),
297 ),
298 array(
299 'id' => 'customers',
300 'label' => __( 'Customers', 'latepoint' ),
301 'icon' => 'latepoint-icon latepoint-icon-user1',
302 'link' => OsRouterHelper::build_link( [ 'customers', 'index' ] ),
303 ),
304 array(
305 'id' => 'services',
306 'label' => __( 'Services', 'latepoint' ),
307 'icon' => 'latepoint-icon latepoint-icon-folder',
308 'link' => OsRouterHelper::build_link( [ 'services', 'index' ] ),
309 'children' => array(
310 array(
311 'id' => 'index',
312 'label' => __( 'Services', 'latepoint' ),
313 'icon' => '',
314 'link' => OsRouterHelper::build_link( [ 'services', 'index' ] ),
315 ),
316 array(
317 'id' => 'bundles',
318 'label' => __( 'Bundles', 'latepoint' ),
319 'icon' => '',
320 'link' => OsRouterHelper::build_link( [ 'pro', 'bundles' ] ),
321 ),
322 array(
323 'id' => 'categories',
324 'label' => __( 'Categories', 'latepoint' ),
325 'icon' => '',
326 'link' => OsRouterHelper::build_link( [ 'pro', 'categories' ] ),
327 ),
328 array(
329 'id' => 'service_extras',
330 'label' => __( 'Service Extras', 'latepoint' ),
331 'icon' => '',
332 'link' => OsRouterHelper::build_link( [ 'pro', 'service_extras' ] ),
333 ),
334 ),
335 ),
336 array(
337 'id' => 'locations',
338 'label' => __( 'Locations', 'latepoint' ),
339 'icon' => 'latepoint-icon latepoint-icon-map-marker',
340 'link' => OsRouterHelper::build_link( [ 'pro', 'locations' ] ),
341 ),
342 array(
343 'id' => 'assets',
344 'label' => __( 'Assets', 'latepoint' ),
345 'icon' => 'latepoint-icon latepoint-icon-layers',
346 'link' => OsRouterHelper::build_link( [ 'pro', 'assets' ] ),
347 ),
348 array(
349 'id' => 'coupons',
350 'label' => __( 'Coupons', 'latepoint' ),
351 'icon' => 'latepoint-icon latepoint-icon-tag1',
352 'link' => OsRouterHelper::build_link( [ 'pro', 'coupons' ] ),
353 ),
354 array(
355 'id' => 'settings',
356 'label' => __( 'Settings', 'latepoint' ),
357 'icon' => 'latepoint-icon latepoint-icon-cog1',
358 'link' => OsRouterHelper::build_link( [ 'agents', 'edit_form' ], array( 'id' => OsAuthHelper::get_logged_in_agent_id() ) ),
359 ),
360 );
361 break;
362 }
363 /**
364 * Filters side menu items
365 *
366 * @since 4.7.0
367 * @hook latepoint_side_menu
368 *
369 * @param {array} $menus Array of side menu items in a format ['id' => '', 'label' => '', 'icon' => '', 'link' => '', 'children' => [ ['label' => '', 'icon' => '', 'link' => ''] ]
370 * @returns {array} Filtered array of side menu items
371 */
372 $menus = apply_filters( 'latepoint_side_menu', $menus, $user_role );
373 self::$side_menu_items = self::filter_by_user_capabilities( $menus );
374 return self::$side_menu_items;
375 }
376
377 public static function filter_by_user_capabilities( array $menus ): array {
378 $total_menu_items = count( $menus );
379 for ( $i = 0; $i < $total_menu_items; $i++ ) {
380 if ( ! empty( $menus[ $i ]['children'] ) ) {
381 $menus[ $i ]['children'] = self::filter_by_user_capabilities( $menus[ $i ]['children'] );
382 }
383 if ( ! empty( $menus[ $i ]['link'] ) ) {
384 parse_str( wp_parse_url( $menus[ $i ]['link'] )['query'] ?? '', $params );
385 if ( empty( $params['route_name'] ) ) {
386 continue; // not a controller__action route, could be custom URL
387 }
388
389 $split_route_name = explode( '__', $params['route_name'] );
390 if ( empty( $split_route_name ) || count( $split_route_name ) != 2 ) {
391 continue; // not a controller__action route, could be custom URL
392 }
393
394 $controller_name = $split_route_name[0];
395 $action = $split_route_name[1];
396
397 if ( empty( $controller_name ) || empty( $action ) ) {
398 continue; // not a controller__action route, could be custom URL
399 }
400 $controller_name = str_replace( '_', '', ucwords( $controller_name, '_' ) );
401 $controller_class_name = 'Os' . $controller_name . 'Controller';
402 $capabilities = OsRolesHelper::get_capabilities_required_for_controller_action( $controller_class_name, $action );
403 if ( ! OsAuthHelper::get_current_user()->has_capability( $capabilities ) ) {
404 unset( $menus[ $i ] );
405 }
406 }
407 }
408 // clean out label items that have no actual items left after them
409 $menus = array_values( $menus );
410 $total_menu_items = count( $menus );
411 $clean_menu_items = [];
412 for ( $i = 0; $i < $total_menu_items; $i++ ) {
413 if ( ! empty( $menus[ $i ]['small_label'] ) && ( ! empty( $menus[ $i + 1 ]['small_label'] ) || $i + 1 == $total_menu_items ) ) {
414 continue;
415 }
416 $clean_menu_items[] = $menus[ $i ];
417 }
418 return $clean_menu_items;
419 }
420 }
421