PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.2.11
LatePoint – Calendar Booking Plugin for Appointments and Events v5.2.11
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 4 months ago auth_helper.php 3 months ago blocks_helper.php 3 months ago booking_helper.php 3 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 3 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 3 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 3 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 3 months ago short_links_systems_helper.php 3 months ago shortcodes_helper.php 3 months ago sms_helper.php 3 months ago steps_helper.php 3 months ago stripe_connect_helper.php 3 months ago styles_helper.php 3 months ago support_topics_helper.php 3 months ago time_helper.php 3 months ago timeline_helper.php 3 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
409 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' => 'coupons',
134 'label' => __( 'Coupons', 'latepoint' ),
135 'icon' => 'latepoint-icon latepoint-icon-tag1',
136 'link' => OsRouterHelper::build_link( [ 'pro', 'coupons' ] ),
137 ),
138 array(
139 'label' => '',
140 'small_label' => __( 'Settings', 'latepoint' ),
141 'menu_section' => 'settings',
142 ),
143 array(
144 'id' => 'settings',
145 'show_notice' => $is_update_available,
146 'label' => __( 'Settings', 'latepoint' ),
147 'icon' => 'latepoint-icon latepoint-icon-cog1',
148 'link' => OsRouterHelper::build_link( [ 'settings', 'general' ] ),
149 'children' => array(
150 array(
151 'id' => 'general',
152 'label' => __( 'General', 'latepoint' ),
153 'icon' => '',
154 'link' => OsRouterHelper::build_link( [ 'settings', 'general' ] ),
155 ),
156 array(
157 'id' => 'schedule',
158 'label' => __( 'Schedule', 'latepoint' ),
159 'icon' => '',
160 'link' => OsRouterHelper::build_link( [ 'settings', 'work_periods' ] ),
161 ),
162 array(
163 'id' => 'taxes',
164 'label' => __( 'Tax', 'latepoint' ),
165 'icon' => '',
166 'link' => OsRouterHelper::build_link( [ 'pro', 'taxes' ] ),
167 ),
168 array(
169 'id' => 'booking_form',
170 'label' => __( 'Booking Form', 'latepoint' ),
171 'icon' => '',
172 'link' => OsRouterHelper::build_link( [ 'booking_form_settings', 'show' ] ),
173 ),
174 array(
175 'id' => 'payments',
176 'label' => __( 'Payments', 'latepoint' ),
177 'icon' => '',
178 'link' => OsRouterHelper::build_link( [ 'settings', 'payments' ] ),
179 ),
180 array(
181 'id' => 'notifications',
182 'label' => __( 'Notifications', 'latepoint' ),
183 'icon' => '',
184 'link' => OsRouterHelper::build_link( [ 'settings', 'notifications' ] ),
185 ),
186 array(
187 'id' => 'roles',
188 'label' => __( 'Roles', 'latepoint' ),
189 'icon' => '',
190 'link' => OsRouterHelper::build_link( [ 'pro', 'roles' ] ),
191 ),
192 ),
193 ),
194 array(
195 'id' => 'processes',
196 'label' => __( 'Automation', 'latepoint' ),
197 'icon' => 'latepoint-icon latepoint-icon-play',
198 'link' => OsRouterHelper::build_link( [ 'processes', 'index' ] ),
199 'children' => array(
200 array(
201 'label' => __( 'Workflows', 'latepoint' ),
202 'icon' => '',
203 'link' => OsRouterHelper::build_link( [ 'processes', 'index' ] ),
204 ),
205 array(
206 'label' => __( 'Scheduled Jobs', 'latepoint' ),
207 'icon' => '',
208 'link' => OsRouterHelper::build_link( [ 'process_jobs', 'index' ] ),
209 ),
210 array(
211 'label' => __( 'Activity Log', 'latepoint' ),
212 'icon' => '',
213 'link' => OsRouterHelper::build_link( [ 'activities', 'index' ] ),
214 ),
215 ),
216 ),
217 array(
218 'id' => 'integrations',
219 'label' => __( 'Integrations', 'latepoint' ),
220 'icon' => 'latepoint-icon latepoint-icon-windows',
221 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_meeting_systems' ] ),
222 'children' => array(
223 array(
224 'id' => 'meetings',
225 'label' => __( 'Meetings', 'latepoint' ),
226 'icon' => '',
227 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_meeting_systems' ] ),
228 ),
229 array(
230 'id' => 'calendars',
231 'label' => __( 'Calendars', 'latepoint' ),
232 'icon' => '',
233 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_calendars' ] ),
234 ),
235 array(
236 'id' => 'meetings',
237 'label' => __( 'Marketing', 'latepoint' ),
238 'icon' => '',
239 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_marketing_systems' ] ),
240 ),
241 array(
242 'id' => 'short_links',
243 'label' => __( 'Short Links', 'latepoint' ),
244 'icon' => '',
245 'link' => OsRouterHelper::build_link( [ 'integrations', 'external_short_links_systems' ] ),
246 ),
247 ),
248 ),
249 array(
250 'id' => 'form_fields',
251 'label' => __( 'Form Fields', 'latepoint' ),
252 'icon' => 'latepoint-icon latepoint-icon-browser',
253 'link' => OsRouterHelper::build_link( [ 'form_fields', 'default_form_fields' ] ),
254 ),
255 );
256 break;
257 case LATEPOINT_USER_TYPE_AGENT:
258 // ---------------
259 // AGENT MENU
260 // ---------------
261 $menus = array(
262 array(
263 'id' => 'dashboard',
264 'label' => __( 'Dashboard', 'latepoint' ),
265 'icon' => 'latepoint-icon latepoint-icon-dashboard',
266 'link' => OsRouterHelper::build_link( [ 'dashboard', 'index' ] ),
267 ),
268 array(
269 'id' => 'calendar',
270 'label' => __( 'Calendar', 'latepoint' ),
271 'icon' => 'latepoint-icon latepoint-icon-calendar2',
272 'link' => OsRouterHelper::build_link( [ 'calendars', 'view' ] ),
273 ),
274 array(
275 'id' => 'appointments',
276 'label' => __( 'Appointments', 'latepoint' ),
277 'icon' => 'latepoint-icon latepoint-icon-box1',
278 'link' => OsRouterHelper::build_link( [ 'bookings', 'index' ] ),
279 ),
280 array(
281 'id' => 'orders',
282 'label' => __( 'Orders', 'latepoint' ),
283 'icon' => 'latepoint-icon latepoint-icon-book2',
284 'link' => OsRouterHelper::build_link( [ 'orders', 'index' ] ),
285 ),
286 array(
287 'id' => 'payments',
288 'label' => __( 'Payments', 'latepoint' ),
289 'icon' => 'latepoint-icon latepoint-icon-cart',
290 'link' => OsRouterHelper::build_link( [ 'transactions', 'index' ] ),
291 ),
292 array(
293 'id' => 'customers',
294 'label' => __( 'Customers', 'latepoint' ),
295 'icon' => 'latepoint-icon latepoint-icon-user1',
296 'link' => OsRouterHelper::build_link( [ 'customers', 'index' ] ),
297 ),
298 array(
299 'id' => 'services',
300 'label' => __( 'Services', 'latepoint' ),
301 'icon' => 'latepoint-icon latepoint-icon-folder',
302 'link' => OsRouterHelper::build_link( [ 'services', 'index' ] ),
303 'children' => array(
304 array(
305 'id' => 'index',
306 'label' => __( 'Services', 'latepoint' ),
307 'icon' => '',
308 'link' => OsRouterHelper::build_link( [ 'services', 'index' ] ),
309 ),
310 array(
311 'id' => 'bundles',
312 'label' => __( 'Bundles', 'latepoint' ),
313 'icon' => '',
314 'link' => OsRouterHelper::build_link( [ 'pro', 'bundles' ] ),
315 ),
316 array(
317 'id' => 'categories',
318 'label' => __( 'Categories', 'latepoint' ),
319 'icon' => '',
320 'link' => OsRouterHelper::build_link( [ 'pro', 'categories' ] ),
321 ),
322 array(
323 'id' => 'service_extras',
324 'label' => __( 'Service Extras', 'latepoint' ),
325 'icon' => '',
326 'link' => OsRouterHelper::build_link( [ 'pro', 'service_extras' ] ),
327 ),
328 ),
329 ),
330 array(
331 'id' => 'locations',
332 'label' => __( 'Locations', 'latepoint' ),
333 'icon' => 'latepoint-icon latepoint-icon-map-marker',
334 'link' => OsRouterHelper::build_link( [ 'pro', 'locations' ] ),
335 ),
336 array(
337 'id' => 'coupons',
338 'label' => __( 'Coupons', 'latepoint' ),
339 'icon' => 'latepoint-icon latepoint-icon-tag1',
340 'link' => OsRouterHelper::build_link( [ 'pro', 'coupons' ] ),
341 ),
342 array(
343 'id' => 'settings',
344 'label' => __( 'Settings', 'latepoint' ),
345 'icon' => 'latepoint-icon latepoint-icon-cog1',
346 'link' => OsRouterHelper::build_link( [ 'agents', 'edit_form' ], array( 'id' => OsAuthHelper::get_logged_in_agent_id() ) ),
347 ),
348 );
349 break;
350 }
351 /**
352 * Filters side menu items
353 *
354 * @since 4.7.0
355 * @hook latepoint_side_menu
356 *
357 * @param {array} $menus Array of side menu items in a format ['id' => '', 'label' => '', 'icon' => '', 'link' => '', 'children' => [ ['label' => '', 'icon' => '', 'link' => ''] ]
358 * @returns {array} Filtered array of side menu items
359 */
360 $menus = apply_filters( 'latepoint_side_menu', $menus, $user_role );
361 self::$side_menu_items = self::filter_by_user_capabilities( $menus );
362 return self::$side_menu_items;
363 }
364
365 public static function filter_by_user_capabilities( array $menus ): array {
366 $total_menu_items = count( $menus );
367 for ( $i = 0; $i < $total_menu_items; $i++ ) {
368 if ( ! empty( $menus[ $i ]['children'] ) ) {
369 $menus[ $i ]['children'] = self::filter_by_user_capabilities( $menus[ $i ]['children'] );
370 }
371 if ( ! empty( $menus[ $i ]['link'] ) ) {
372 parse_str( wp_parse_url( $menus[ $i ]['link'] )['query'] ?? '', $params );
373 if ( empty( $params['route_name'] ) ) {
374 continue; // not a controller__action route, could be custom URL
375 }
376
377 $split_route_name = explode( '__', $params['route_name'] );
378 if ( empty( $split_route_name ) || count( $split_route_name ) != 2 ) {
379 continue; // not a controller__action route, could be custom URL
380 }
381
382 $controller_name = $split_route_name[0];
383 $action = $split_route_name[1];
384
385 if ( empty( $controller_name ) || empty( $action ) ) {
386 continue; // not a controller__action route, could be custom URL
387 }
388 $controller_name = str_replace( '_', '', ucwords( $controller_name, '_' ) );
389 $controller_class_name = 'Os' . $controller_name . 'Controller';
390 $capabilities = OsRolesHelper::get_capabilities_required_for_controller_action( $controller_class_name, $action );
391 if ( ! OsAuthHelper::get_current_user()->has_capability( $capabilities ) ) {
392 unset( $menus[ $i ] );
393 }
394 }
395 }
396 // clean out label items that have no actual items left after them
397 $menus = array_values( $menus );
398 $total_menu_items = count( $menus );
399 $clean_menu_items = [];
400 for ( $i = 0; $i < $total_menu_items; $i++ ) {
401 if ( ! empty( $menus[ $i ]['small_label'] ) && ( ! empty( $menus[ $i + 1 ]['small_label'] ) || $i + 1 == $total_menu_items ) ) {
402 continue;
403 }
404 $clean_menu_items[] = $menus[ $i ];
405 }
406 return $clean_menu_items;
407 }
408 }
409