PluginProbe
Yatra – Travel Booking & Tour Operator Software / 3.0.3
Yatra – Travel Booking & Tour Operator Software v3.0.3
3.0.16 3.0.15 3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 All 84 releases
yatra / app / Hooks / UtilsHooks.php

UtilsHooks.php in Yatra – Travel Booking & Tour Operator Software 3.0.3, at app/Hooks/UtilsHooks.php

135 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Hooks;
6
7 /**
8 * Utility Hooks
9 *
10 * Handles various utility functionality like admin bar modifications
11 */
12 class UtilsHooks
13 {
14 /**
15 * Initialize utility hooks
16 */
17 public static function init(): void
18 {
19 // Add "Edit Trip" to admin bar on single trip page
20 add_action('admin_bar_menu', [self::class, 'addEditTripAdminBarLink'], 80);
21
22 // Add admin bar CSS for trip edit link
23 add_action('wp_head', [self::class, 'addAdminBarTripEditCSS']);
24 }
25
26 /**
27 * Add "Edit Trip" link to admin bar on single trip page
28 * Add "Edit Destination/Activity/Category" links on taxonomy pages
29 *
30 * @param \WP_Admin_Bar $admin_bar
31 */
32 public static function addEditTripAdminBarLink($admin_bar): void
33 {
34 // Debug logging at function start
35
36 // Only for logged-in users who can edit Yatra items
37 if (!is_user_logged_in() || (!current_user_can('manage_options'))) {
38
39 return;
40 }
41
42 // Check if we're on a single trip page
43 global $trip;
44 if (!empty($trip) && !empty($trip->id)) {
45 // Build the edit URL for the trip
46 $edit_url = admin_url('admin.php?page=yatra&subpage=trips&action=edit&id=' . (int) $trip->id);
47
48 // Add the Edit Trip node
49 $admin_bar->add_node([
50 'id' => 'yatra-edit-trip',
51 'title' => __('Edit Trip', 'yatra'),
52 'href' => $edit_url,
53 'meta' => [
54 'title' => __('Edit this trip in Yatra admin', 'yatra'),
55 ],
56 ]);
57 }
58
59 // Check if we're on a taxonomy page
60 $taxonomy_data = $GLOBALS['yatra_taxonomy_data'] ?? null;
61
62
63
64 if (!empty($taxonomy_data) && !empty($taxonomy_data->id)) {
65 // Build the edit URL based on taxonomy type
66 $type = $taxonomy_data->type ?? '';
67 $id = (int) $taxonomy_data->id;
68
69 $tabs = '';
70 $title = '';
71
72 switch ($type) {
73 case 'destination':
74 $tabs = 'destinations';
75 $title = __('Edit Destination', 'yatra');
76 break;
77 case 'activity':
78 $tabs = 'activities';
79 $title = __('Edit Activity', 'yatra');
80 break;
81 case 'category':
82 $tabs = 'categories';
83 $title = __('Edit Category', 'yatra');
84 break;
85 }
86
87 if ($tabs && $title) {
88 $edit_url = admin_url('admin.php?page=yatra&subpage=trips&tab=' . $tabs . '&action=edit&id=' . $id);
89
90 $node_id = 'yatra-edit-' . $type;
91
92
93 $admin_bar->add_node([
94 'id' => $node_id,
95 'title' => $title,
96 'href' => $edit_url,
97 'meta' => [
98 'title' => sprintf(__('Edit this %s in Yatra admin', 'yatra'), $type),
99 ],
100 ]);
101 }
102 }
103 }
104
105 /**
106 * Add CSS for the Edit Trip/Taxonomy admin bar links
107 */
108 public static function addAdminBarTripEditCSS(): void
109 {
110 // Only output CSS if user can see admin bar
111 if (!is_user_logged_in() || !is_admin_bar_showing()) {
112 return;
113 }
114
115 // Check if we're on a trip page or taxonomy page
116 global $trip;
117 $taxonomy_data = $GLOBALS['yatra_taxonomy_data'] ?? null;
118
119 if (empty($trip) && empty($taxonomy_data)) {
120 return;
121 }
122
123 echo '<style>
124 #wpadminbar #wp-admin-bar-yatra-edit-trip > .ab-item:before,
125 #wpadminbar #wp-admin-bar-yatra-edit-destination > .ab-item:before,
126 #wpadminbar #wp-admin-bar-yatra-edit-activity > .ab-item:before,
127 #wpadminbar #wp-admin-bar-yatra-edit-category > .ab-item:before {
128 content: "\f464";
129 font-family: dashicons;
130 margin-right: 5px;
131 }
132 </style>';
133 }
134 }
135