| @@ -33,8 +33,11 @@ | ||
| 33 | 33 | add_action( 'wp_initialize_site', [ $this, 'update_user_role_on_insert_new_site' ], 110 ); |
| 34 | 34 | |
| 35 | 35 | add_action( 'set_user_role', [ $this, 'set_roles' ], 10, 2 ); |
| 36 | 36 | |
| 37 | + add_filter( 'show_admin_bar', [ $this, 'hide_admin_bar_for_customers' ] ); | |
| 38 | + add_action( 'admin_init', [ $this, 'block_admin_for_customers' ] ); | |
| 39 | + | |
| 37 | 40 | add_filter( 'timetics_menu', [ $this, 'update_busyness_menu' ] ); |
| 38 | 41 | |
| 39 | 42 | add_filter( 'timetics_settings', [ $this, 'set_google_auth_url' ] ); |
| 40 | 43 | |
| @@ -73,8 +76,9 @@ | ||
| 73 | 76 | |
| 74 | 77 | echo wp_kses_post( $notice ); |
| 75 | 78 | |
| 76 | 79 | $admin_ajax_url = admin_url('admin-ajax.php'); |
| 80 | + $nonce = wp_create_nonce( 'timetics_dismiss_wc_notice' ); | |
| 77 | 81 | |
| 78 | 82 | ?> |
| 79 | 83 | <script> |
| 80 | 84 | jQuery(document).ready(function($) { |
| @@ -80,8 +84,9 @@ | ||
| 80 | 84 | jQuery(document).ready(function($) { |
| 81 | 85 | $('.notice.is-dismissible').on('click', '.notice-dismiss', function() { |
| 82 | 86 | var data = { |
| 83 | 87 | action: 'dismiss_woocommerce_notice', |
| 88 | + nonce: '<?php echo esc_js( $nonce ); ?>', | |
| 84 | 89 | }; |
| 85 | 90 | |
| 86 | 91 | $.post('<?php echo esc_url( $admin_ajax_url ); ?>', data, function(response) { |
| 87 | 92 | console.log(response); |
| @@ -97,8 +102,10 @@ | ||
| 97 | 102 | * |
| 98 | 103 | * @return void |
| 99 | 104 | */ |
| 100 | 105 | public function dismiss_woocommerce_notice() { |
| 106 | + check_ajax_referer( 'timetics_dismiss_wc_notice', 'nonce' ); | |
| 107 | + | |
| 101 | 108 | // Store the notice state in user meta |
| 102 | 109 | update_user_meta( get_current_user_id(), 'timetics_woocommerce_notice_dismissed', true ); |
| 103 | 110 | |
| 104 | 111 | wp_send_json_success('Notice dismissed successfully.'); |
| @@ -179,8 +186,61 @@ | ||
| 179 | 186 | $user->add_role('timetics-customer'); |
| 180 | 187 | } |
| 181 | 188 | |
| 182 | 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 | + /** | |
| 183 | 243 | * Update busyness menu item |
| 184 | 244 | * |
| 185 | 245 | * @param array $menu_items |
| 186 | 246 | * |
| @@ -235,50 +295,54 @@ | ||
| 235 | 295 | |
| 236 | 296 | |
| 237 | 297 | $admin_email = get_option( 'admin_email' ); |
| 238 | 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 | + | |
| 239 | 311 | $defaults = [ |
| 240 | 312 | |
| 241 | 313 | 'booking_created_customer_email_from' => $admin_email, |
| 242 | 314 | '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' )), | |
| 315 | + 'booking_created_customer_email_body' => sprintf('<p>%s</p><p>%s</p>', $customer_greeting, $new_meeting_msg), | |
| 245 | 316 | |
| 246 | 317 | 'booking_created_host_email_from' => $admin_email, |
| 247 | 318 | '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' )), | |
| 319 | + 'booking_created_host_email_body' => sprintf('<p>%s</p><p>%s</p>', $host_greeting, $new_meeting_msg), | |
| 250 | 320 | |
| 251 | 321 | |
| 252 | 322 | 'booking_canceled_customer_email_from' => $admin_email, |
| 253 | 323 | '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' )), | |
| 324 | + 'booking_canceled_customer_email_body' => sprintf('<p>%s</p><p>%s</p>', $customer_greeting, $canceled_msg), | |
| 256 | 325 | |
| 257 | 326 | 'booking_canceled_host_email_from' => $admin_email, |
| 258 | 327 | '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' )), | |
| 328 | + 'booking_canceled_host_email_body' => sprintf('<p>%s</p><p>%s</p>', $host_greeting, $canceled_msg), | |
| 261 | 329 | |
| 262 | 330 | 'booking_rescheduled_customer_email_from' => $admin_email, |
| 263 | 331 | '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' )), | |
| 332 | + 'booking_rescheduled_customer_email_body' => sprintf('<p>%s</p><p>%s</p>', $host_greeting, $rescheduled_msg), | |
| 266 | 333 | |
| 267 | 334 | 'booking_rescheduled_host_email_from' => $admin_email, |
| 268 | 335 | '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' )), | |
| 336 | + 'booking_rescheduled_host_email_body' => sprintf('<p>%s</p><p>%s</p>', $host_greeting, $rescheduled_msg), | |
| 271 | 337 | |
| 272 | 338 | 'booking_reminder_customer_email_from' => $admin_email, |
| 273 | 339 | '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' )), | |
| 340 | + 'booking_reminder_customer_email_body' => sprintf('<p>%s</p><p>%s</p>', $customer_greeting, $reminder_msg), | |
| 276 | 341 | |
| 277 | 342 | 'booking_reminder_host_email_from' => $admin_email, |
| 278 | 343 | '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' )), | |
| 344 | + 'booking_reminder_host_email_body' => sprintf('<p>%s</p><p>%s</p>', $host_greeting, $reminder_msg), | |
| 281 | 345 | ]; |
| 282 | 346 | |
| 283 | 347 | $settings = wp_parse_args( $settings, $defaults ); |
| 284 | 348 | |