PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.64
Timetics – Appointment Booking Calendar & Scheduling v1.0.64
1.0.64 1.0.62 1.0.63 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 All 65 releases
← All changes | core/admin/hooks.php +147 -2 1.0.11 → 1.0.64 View file →
@@ -4,11 +4,13 @@
4 4 *
5 5 * @package Timetics
6 6 */
7 7 namespace Timetics\Core\Admin;
8 +
9 +defined( 'ABSPATH' ) || exit;
10 +
8 11 use Timetics\Utils\Singleton;
9 12
10 -use function Timetics\timetics;
11 13
12 14 class Hooks {
13 15 use Singleton;
14 16
@@ -31,10 +33,17 @@
31 33 add_action( 'wp_initialize_site', [ $this, 'update_user_role_on_insert_new_site' ], 110 );
32 34
33 35 add_action( 'set_user_role', [ $this, 'set_roles' ], 10, 2 );
34 36
37 + add_filter( 'show_admin_bar', [ $this, 'hide_admin_bar_for_customers' ] );
38 + add_action( 'admin_init', [ $this, 'block_admin_for_customers' ] );
39 +
35 40 add_filter( 'timetics_menu', [ $this, 'update_busyness_menu' ] );
36 41
42 + add_filter( 'timetics_settings', [ $this, 'set_google_auth_url' ] );
43 +
44 + add_filter( 'timetics_get_settings', [ $this, 'set_email_default_content' ] );
45 +
37 46 /**
38 47 * Added temporary for leagacy sass. It will remove in future.
39 48 */
40 49 do_action('timetics_admin_init');
@@ -67,8 +76,9 @@
67 76
68 77 echo wp_kses_post( $notice );
69 78
70 79 $admin_ajax_url = admin_url('admin-ajax.php');
80 + $nonce = wp_create_nonce( 'timetics_dismiss_wc_notice' );
71 81
72 82 ?>
73 83 <script>
74 84 jQuery(document).ready(function($) {
@@ -74,8 +84,9 @@
74 84 jQuery(document).ready(function($) {
75 85 $('.notice.is-dismissible').on('click', '.notice-dismiss', function() {
76 86 var data = {
77 87 action: 'dismiss_woocommerce_notice',
88 + nonce: '<?php echo esc_js( $nonce ); ?>',
78 89 };
79 90
80 91 $.post('<?php echo esc_url( $admin_ajax_url ); ?>', data, function(response) {
81 92 console.log(response);
@@ -91,8 +102,10 @@
91 102 *
92 103 * @return void
93 104 */
94 105 public function dismiss_woocommerce_notice() {
106 + check_ajax_referer( 'timetics_dismiss_wc_notice', 'nonce' );
107 +
95 108 // Store the notice state in user meta
96 109 update_user_meta( get_current_user_id(), 'timetics_woocommerce_notice_dismissed', true );
97 110
98 111 wp_send_json_success('Notice dismissed successfully.');
@@ -133,9 +146,10 @@
133 146
134 147 update_option( 'timetics_onboard_setup', true );
135 148 update_option( 'timetics_onboard_settings', false );
136 149
137 - exit( wp_redirect( admin_url('admin.php?page=timetics#/onboard') ) );
150 + wp_safe_redirect( admin_url('admin.php?page=timetics#/onboard') );
151 + exit;
138 152 }
139 153
140 154 /**
141 155 * Update site admin roles whne new site created
@@ -172,8 +186,61 @@
172 186 $user->add_role('timetics-customer');
173 187 }
174 188
175 189 /**
190 + * Hide the WP admin toolbar for customer-only users.
191 + *
192 + * @param bool $show
193 + *
194 + * @return bool
195 + */
196 + public function hide_admin_bar_for_customers( $show ) {
197 + $user = wp_get_current_user();
198 +
199 + if ( ! $user || ! $user->exists() ) {
200 + return $show;
201 + }
202 +
203 + if ( $this->is_customer_only( $user ) ) {
204 + return false;
205 + }
206 +
207 + return $show;
208 + }
209 +
210 + /**
211 + * Redirect customer-only users away from /wp-admin/.
212 + *
213 + * @return void
214 + */
215 + public function block_admin_for_customers() {
216 + if ( wp_doing_ajax() ) {
217 + return;
218 + }
219 +
220 + $user = wp_get_current_user();
221 +
222 + if ( $user && $user->exists() && $this->is_customer_only( $user ) ) {
223 + wp_safe_redirect( home_url() );
224 + exit;
225 + }
226 + }
227 +
228 + /**
229 + * Whether the given user's only Timetics-relevant role is timetics-customer.
230 + *
231 + * @param \WP_User $user
232 + *
233 + * @return bool
234 + */
235 + private function is_customer_only( $user ) {
236 + $roles = (array) $user->roles;
237 +
238 + return in_array( 'timetics-customer', $roles, true )
239 + && ! array_intersect( $roles, [ 'administrator', 'editor', 'author', 'contributor', 'timetics-staff' ] );
240 + }
241 +
242 + /**
176 243 * Update busyness menu item
177 244 *
178 245 * @param array $menu_items
179 246 *
@@ -201,6 +268,84 @@
201 268 $new_menu_items[] = $menu;
202 269 }
203 270
204 271 return $new_menu_items;
272 + }
273 +
274 + /**
275 + * Set google auth url
276 + *
277 + * @param array $settings
278 + *
279 + * @return array
280 + */
281 + public function set_google_auth_url( $settings ) {
282 + $settings['google_auth_redirect_uri'] = timetics_get_auth_redirect_uri( 'google-auth' );
283 +
284 + return $settings;
285 + }
286 +
287 + /**
288 + * Set default settings
289 + *
290 + * @param array $settings [$settings description]
291 + *
292 + * @return mixed
293 + */
294 + public function set_email_default_content( $settings ) {
295 +
296 +
297 + $admin_email = get_option( 'admin_email' );
298 +
299 + /* translators: {%customer_name%} is a token replaced at runtime with the recipient customer's name */
300 + $customer_greeting = __( 'Hi {%customer_name%}', 'timetics' );
301 + /* translators: {%host_name%} is a token replaced at runtime with the recipient host's name */
302 + $host_greeting = __( 'Hi {%host_name%}', 'timetics' );
303 + $new_meeting_msg = __( 'A new meeting has been scheduled.', 'timetics' );
304 + /* translators: {%meeting_title%} is a token replaced at runtime with the meeting title */
305 + $canceled_msg = __( '{%meeting_title%} has been canceled.', 'timetics' );
306 + /* translators: {%meeting_title%} is a token replaced at runtime with the meeting title */
307 + $rescheduled_msg = __( '{%meeting_title%} has been rescheduled', 'timetics' );
308 + /* translators: {%meeting_title%}, {%meeting_date%}, {%meeting_time%} are tokens replaced at runtime with the meeting details */
309 + $reminder_msg = __( '{%meeting_title%} at {%meeting_date%} {%meeting_time%}', 'timetics' );
310 +
311 + $defaults = [
312 +
313 + 'booking_created_customer_email_from' => $admin_email,
314 + 'booking_created_customer_email_title' => sprintf('%s', __( 'New meeting scheduled!', 'timetics' )),
315 + 'booking_created_customer_email_body' => sprintf('<p>%s</p><p>%s</p>', $customer_greeting, $new_meeting_msg),
316 +
317 + 'booking_created_host_email_from' => $admin_email,
318 + 'booking_created_host_email_title' => sprintf('%s', __( 'New meeting scheduled!', 'timetics' )),
319 + 'booking_created_host_email_body' => sprintf('<p>%s</p><p>%s</p>', $host_greeting, $new_meeting_msg),
320 +
321 +
322 + 'booking_canceled_customer_email_from' => $admin_email,
323 + 'booking_canceled_customer_email_title' => sprintf('%s', __( 'Meeting cancelled', 'timetics' )),
324 + 'booking_canceled_customer_email_body' => sprintf('<p>%s</p><p>%s</p>', $customer_greeting, $canceled_msg),
325 +
326 + 'booking_canceled_host_email_from' => $admin_email,
327 + 'booking_canceled_host_email_title' => sprintf('%s', __( 'Meeting cancelled', 'timetics' )),
328 + 'booking_canceled_host_email_body' => sprintf('<p>%s</p><p>%s</p>', $host_greeting, $canceled_msg),
329 +
330 + 'booking_rescheduled_customer_email_from' => $admin_email,
331 + 'booking_rescheduled_customer_email_title' => sprintf('%s', __( 'Meeting rescheduled!', 'timetics' )),
332 + 'booking_rescheduled_customer_email_body' => sprintf('<p>%s</p><p>%s</p>', $host_greeting, $rescheduled_msg),
333 +
334 + 'booking_rescheduled_host_email_from' => $admin_email,
335 + 'booking_rescheduled_host_email_title' => sprintf('%s', __('Meeting rescheduled!', 'timetics' )),
336 + 'booking_rescheduled_host_email_body' => sprintf('<p>%s</p><p>%s</p>', $host_greeting, $rescheduled_msg),
337 +
338 + 'booking_reminder_customer_email_from' => $admin_email,
339 + 'booking_reminder_customer_email_title' => sprintf('%s', __( 'Meeting time reminder', 'timetics' )),
340 + 'booking_reminder_customer_email_body' => sprintf('<p>%s</p><p>%s</p>', $customer_greeting, $reminder_msg),
341 +
342 + 'booking_reminder_host_email_from' => $admin_email,
343 + 'booking_reminder_host_email_title' => sprintf('%s', __( 'Meeting time reminder', 'timetics' )),
344 + 'booking_reminder_host_email_body' => sprintf('<p>%s</p><p>%s</p>', $host_greeting, $reminder_msg),
345 + ];
346 +
347 + $settings = wp_parse_args( $settings, $defaults );
348 +
349 + return $settings;
205 350 }
206 351 }