PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.56
Timetics – Appointment Booking Calendar & Scheduling v1.0.56
1.0.61 1.0.60 1.0.59 1.0.58 1.0.57 1.0.56 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 All 62 releases
timetics / core / admin / hooks.php

hooks.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.56, at core/admin/hooks.php

288 lines 10.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin hooks
4 *
5 * @package Timetics
6 */
7 namespace Timetics\Core\Admin;
8
9 defined( 'ABSPATH' ) || exit;
10
11 use Timetics\Utils\Singleton;
12
13
14 class Hooks {
15 use Singleton;
16
17 /**
18 * Initialize admin hooks
19 *
20 * @return void
21 */
22 public function init() {
23 add_action('admin_notices', [ $this, 'add_woocommerce_notice_on_admin_dashboard' ] );
24
25 // Dismiss the notice
26 add_action('wp_ajax_dismiss_woocommerce_notice', [ $this, 'dismiss_woocommerce_notice'] );
27
28 add_filter('plugin_action_links', [ $this, 'add_settings_plugin_tab' ], 10, 2);
29
30 add_action( 'admin_init', [ $this, 'redirect_onboard' ] );
31
32 // Update user roles and permissions for multisite.
33 add_action( 'wp_initialize_site', [ $this, 'update_user_role_on_insert_new_site' ], 110 );
34
35 add_action( 'set_user_role', [ $this, 'set_roles' ], 10, 2 );
36
37 add_filter( 'timetics_menu', [ $this, 'update_busyness_menu' ] );
38
39 add_filter( 'timetics_settings', [ $this, 'set_google_auth_url' ] );
40
41 add_filter( 'timetics_get_settings', [ $this, 'set_email_default_content' ] );
42
43 /**
44 * Added temporary for leagacy sass. It will remove in future.
45 */
46 do_action('timetics_admin_init');
47 }
48
49 /**
50 * Add admin notice for
51 *
52 * @return void
53 */
54 public function add_woocommerce_notice_on_admin_dashboard() {
55
56 $woocommerce_notice_dismiss = get_user_meta( get_current_user_id(), 'timetics_woocommerce_notice_dismissed', true );
57
58 if ( $woocommerce_notice_dismiss ) {
59 return;
60 }
61
62 if ( ! timetics_get_option( 'wc_integration' ) ) {
63 return;
64 }
65
66 if ( function_exists( 'WC' ) ) {
67 return;
68 }
69
70 $notice = '<div class="notice notice-danger is-dismissible error">';
71 $notice .= sprintf('<p><strong>%s</strong></p>', __( 'Timetics requires WooCommerce to enable woocommerce integration. You can download <a href="https://wordpress.org/plugins/woocommerce/" target="_blank">WooCommerce</a> here.', 'timetics' ) );
72 $notice .= '</div>';
73
74 echo wp_kses_post( $notice );
75
76 $admin_ajax_url = admin_url('admin-ajax.php');
77
78 ?>
79 <script>
80 jQuery(document).ready(function($) {
81 $('.notice.is-dismissible').on('click', '.notice-dismiss', function() {
82 var data = {
83 action: 'dismiss_woocommerce_notice',
84 };
85
86 $.post('<?php echo esc_url( $admin_ajax_url ); ?>', data, function(response) {
87 console.log(response);
88 });
89 });
90 });
91 </script>
92 <?php
93 }
94
95 /**
96 * Update admin notice
97 *
98 * @return void
99 */
100 public function dismiss_woocommerce_notice() {
101 // Store the notice state in user meta
102 update_user_meta( get_current_user_id(), 'timetics_woocommerce_notice_dismissed', true );
103
104 wp_send_json_success('Notice dismissed successfully.');
105 }
106
107 /**
108 * Add settings on plugin action row
109 *
110 * @param array $actions
111 * @param string $plugin_file
112 *
113 * @return array
114 */
115 public function add_settings_plugin_tab( $actions, $plugin_file ) {
116 // Check if the plugin file matches your target plugin
117 if ( 'timetics/timetics.php' === $plugin_file ) {
118 // Add your custom tab
119 $settings_tab = array(
120 'timetics-settings' => sprintf( '<a href="%s">%s</a>', esc_url( admin_url('admin.php?page=timetics#/settings') ), __( 'Settings', 'timetics' ) ),
121 );
122 // Merge the custom tab with existing actions
123 $actions = array_merge( $settings_tab, $actions );
124 }
125 return $actions;
126 }
127
128 /**
129 * Redirect onboarding page after activating
130 *
131 * @return void
132 */
133 public function redirect_onboard() {
134 $onboarding_setup = get_option( 'timetics_onboard_settings' );
135
136 if ( ! $onboarding_setup ) {
137 return;
138 }
139
140 update_option( 'timetics_onboard_setup', true );
141 update_option( 'timetics_onboard_settings', false );
142
143 wp_safe_redirect( admin_url('admin.php?page=timetics#/onboard') );
144 exit;
145 }
146
147 /**
148 * Update site admin roles whne new site created
149 *
150 * @param WP_Site $site_object
151 *
152 * @return void
153 */
154 public function update_user_role_on_insert_new_site( $site_object ) {
155 global $wpdb;
156
157 $roles = wp_roles()->roles;
158 $blog_id = $site_object->blog_id;
159 $roles_option_key = $wpdb->get_blog_prefix( $blog_id ) . 'user_roles';
160
161 update_blog_option( $blog_id, $roles_option_key, $roles );
162 }
163
164 /**
165 * Update user role timetics staff and customer if user is admin
166 *
167 * @param integer $user_id
168 * @param string $role
169 *
170 * @return void
171 */
172 public function set_roles( $user_id, $role ) {
173 if ( 'administrator' !== $role ) {
174 return;
175 }
176
177 $user = get_userdata( $user_id );
178 $user->add_role('timetics-staff');
179 $user->add_role('timetics-customer');
180 }
181
182 /**
183 * Update busyness menu item
184 *
185 * @param array $menu_items
186 *
187 * @return array
188 */
189 public function update_busyness_menu($menu_items) {
190 $busyness_category = timetics_get_busyness_category();
191
192 if ( ! $busyness_category ) {
193 return $menu_items;
194 }
195
196 $busyness = timetics_get_busyness( $busyness_category );
197 $new_menu_items = [];
198
199 foreach ( $menu_items as $menu ) {
200 if ( empty( $menu['id'] ) ) {
201 continue;
202 }
203
204 if ( ! empty( $busyness[$menu['id']] ) ) {
205 $menu['title'] = $busyness[$menu['id']];
206 }
207
208 $new_menu_items[] = $menu;
209 }
210
211 return $new_menu_items;
212 }
213
214 /**
215 * Set google auth url
216 *
217 * @param array $settings
218 *
219 * @return array
220 */
221 public function set_google_auth_url( $settings ) {
222 $settings['google_auth_redirect_uri'] = timetics_get_auth_redirect_uri( 'google-auth' );
223
224 return $settings;
225 }
226
227 /**
228 * Set default settings
229 *
230 * @param array $settings [$settings description]
231 *
232 * @return mixed
233 */
234 public function set_email_default_content( $settings ) {
235
236
237 $admin_email = get_option( 'admin_email' );
238
239 $defaults = [
240
241 'booking_created_customer_email_from' => $admin_email,
242 'booking_created_customer_email_title' => sprintf('%s', __( 'New meeting scheduled!', 'timetics' )),
243 /* translators: 1: Greeting with customer name, 2: Meeting scheduled message */
244 'booking_created_customer_email_body' => sprintf('<p>%s</p><p>%s</p>', __( 'Hi {%customer_name%}', 'timetics' ), __( 'A new meeting has been scheduled.', 'timetics' )),
245
246 'booking_created_host_email_from' => $admin_email,
247 'booking_created_host_email_title' => sprintf('%s', __( 'New meeting scheduled!', 'timetics' )),
248 /* translators: 1: Greeting with host name, 2: Meeting scheduled message */
249 'booking_created_host_email_body' => sprintf('<p>%s</p><p>%s</p>', __( 'Hi {%host_name%}', 'timetics' ), __( 'A new meeting has been scheduled.', 'timetics' )),
250
251
252 'booking_canceled_customer_email_from' => $admin_email,
253 'booking_canceled_customer_email_title' => sprintf('%s', __( 'Meeting cancelled', 'timetics' )),
254 /* translators: 1: Greeting with customer name, 2: Meeting cancellation message */
255 'booking_canceled_customer_email_body' => sprintf('<p>%s</p><p>%s</p>', __( 'Hi {%customer_name%}', 'timetics' ), __( '{%meeting_title%} has been canceled.', 'timetics' )),
256
257 'booking_canceled_host_email_from' => $admin_email,
258 'booking_canceled_host_email_title' => sprintf('%s', __( 'Meeting cancelled', 'timetics' )),
259 /* translators: 1: Greeting with host name, 2: Meeting cancellation message */
260 'booking_canceled_host_email_body' => sprintf('<p>%s</p><p>%s</p>', __( 'Hi {%host_name%}', 'timetics' ), __( '{%meeting_title%} has been canceled.', 'timetics' )),
261
262 'booking_rescheduled_customer_email_from' => $admin_email,
263 'booking_rescheduled_customer_email_title' => sprintf('%s', __( 'Meeting rescheduled!', 'timetics' )),
264 /* translators: 1: Greeting with host name, 2: Meeting rescheduled message */
265 'booking_rescheduled_customer_email_body' => sprintf('<p>%s</p><p>%s</p>', __( 'Hi {%host_name%}', 'timetics' ), __( '{%meeting_title%} has been rescheduled', 'timetics' )),
266
267 'booking_rescheduled_host_email_from' => $admin_email,
268 'booking_rescheduled_host_email_title' => sprintf('%s', __('Meeting rescheduled!', 'timetics' )),
269 /* translators: 1: Greeting with host name, 2: Meeting rescheduled message */
270 'booking_rescheduled_host_email_body' => sprintf('<p>%s</p><p>%s</p>', __( 'Hi {%host_name%}', 'timetics' ), __( '{%meeting_title%} has been rescheduled', 'timetics' )),
271
272 'booking_reminder_customer_email_from' => $admin_email,
273 'booking_reminder_customer_email_title' => sprintf('%s', __( 'Meeting time reminder', 'timetics' )),
274 /* translators: 1: Greeting with customer name, 2: Meeting reminder details */
275 'booking_reminder_customer_email_body' => sprintf('<p>%s</p><p>%s</p>', __( 'Hi {%customer_name%}', 'timetics' ), __( '{%meeting_title%} at {%meeting_date%} {%meeting_time%}', 'timetics' )),
276
277 'booking_reminder_host_email_from' => $admin_email,
278 'booking_reminder_host_email_title' => sprintf('%s', __( 'Meeting time reminder', 'timetics' )),
279 /* translators: 1: Greeting with host name, 2: Meeting reminder details */
280 'booking_reminder_host_email_body' => sprintf('<p>%s</p><p>%s</p>', __( 'Hi {%host_name%}', 'timetics' ), __( '{%meeting_title%} at {%meeting_date%} {%meeting_time%}', 'timetics' )),
281 ];
282
283 $settings = wp_parse_args( $settings, $defaults );
284
285 return $settings;
286 }
287 }
288