PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.21
Timetics – Appointment Booking Calendar & Scheduling v1.0.21
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.21, at core/admin/hooks.php

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