PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.38
Timetics – Appointment Booking Calendar & Scheduling v1.0.38
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 / staffs / hooks.php

hooks.php in Timetics – Appointment Booking Calendar & Scheduling 1.0.38, at core/staffs/hooks.php

223 lines 6.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Handling Staff Related Hooks
4 *
5 * @package Timetics
6 */
7 namespace Timetics\Core\Staffs;
8
9 use Timetics\Core\Staffs\Onboard;
10 use Timetics\Utils\Singleton;
11
12 class Hooks {
13 use Singleton;
14
15 /**
16 * Intialie
17 *
18 * @return void
19 */
20 public function init() {
21 add_filter( 'retrieve_password_notification_email', [$this, 'reset_email_content'], 10, 4 );
22 add_filter( 'retrieve_password_title', [$this, 'reset_email_title'] );
23
24 add_action( 'after_password_reset', [$this, 'update_staff_status'] );
25
26 add_filter( 'user_row_actions', [$this, 'user_row_action'], 10, 2 );
27
28 add_action( 'admin_init', [$this, 'make_staff'] );
29
30 add_action( 'init', [$this, 'setup_staff_onboard'] );
31
32 add_filter( 'login_redirect', [$this, 'login_redirect'], 10, 3 );
33
34 add_action( 'wp_ajax_timetics_staff_onboard_skip', [$this, 'timetics_staff_onboard_skip'] );
35 }
36
37 /**
38 * Reset user activation and reset password link
39 *
40 * @param array $config [$config description]
41 * @param string $key [$key description]
42 * @param [type] $user_login [$user_login description]
43 * @param [type] $user_data [$user_data description]
44 *
45 * @return [type] [return description]
46 */
47 public function reset_email_content( $config, $key, $user_login, $user_data ) {
48 $headers = 'MIME-Version: 1.0' . "\r\n";
49 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
50
51 $local = get_locale();
52 $reset_url = site_url( "wp-login.php?action=rp&key={$key}&login={$user_login}&wp_lang={$local}" );
53
54 $reset_url = apply_filters( 'timetics_staff_password_reset_url', $reset_url, $key, $user_login, $local );
55
56 ob_start();
57 include TIMETICS_PLUGIN_DIR . '/templates/emails/email-header.php';
58 include TIMETICS_PLUGIN_DIR . '/templates/emails/new-staff.php';
59 include TIMETICS_PLUGIN_DIR . '/templates/emails/email-footer.php';
60 $message = ob_get_clean();
61
62 $config['message'] = $message;
63 $config['headers'] = $headers;
64
65 return $config;
66 }
67
68 /**
69 * Update staff status after updating password
70 *
71 * @param Object $user
72 *
73 * @return void
74 */
75 public function update_staff_status( $user ) {
76 $staff = new Staff( $user->ID );
77
78 if ( ! $staff->is_staff() ) {
79 return;
80 }
81
82 $staff->update(
83 [
84 'status' => 1,
85 ]
86 );
87 }
88
89 /**
90 * Show row actions for make staff
91 *
92 * @param array $actions
93 * @param Object $user_object
94 *
95 * @return void
96 */
97 public function user_row_action( $actions, $user_object ) {
98 $is_staff = user_can( $user_object, 'timetics-staff' );
99 $button_text = $is_staff ? esc_html__( 'Remove from staff', 'timetics' ) : esc_html__( 'Make staff', 'timetics' );
100 $action = $is_staff ? 'removestaff' : 'makestaff';
101
102 $actions['staff'] = "<a class='staff' href='" . wp_nonce_url( "users.php?action=$action&amp;users=$user_object->ID", 'bulk-users' ) . "'>" . $button_text . '</a>';
103
104 return $actions;
105 }
106
107 /**
108 * Make staff
109 *
110 * @return mixed
111 */
112 public function make_staff() {
113
114 $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
115 $user_id = isset( $_GET['users'] ) ? intval( $_GET['users'] ) : 0;
116 $nonce = isset( $_GET['_wpnonce'] ) ? sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ) : '';
117 $user = get_userdata( $user_id );
118
119 if ( 'makestaff' === $action ) {
120
121 if ( !wp_verify_nonce( $nonce, 'bulk-users' ) ) {
122 return;
123 }
124
125 $capability = current_user_can( 'manage_options' );
126 if( !$capability) return;
127
128 $user->add_role( 'timetics-staff' );
129 $staff = new Staff( $user_id );
130 $staff->update(
131 [
132 'status' => 1,
133 ]
134 );
135 }
136
137 if ( 'removestaff' === $action ) {
138
139 if ( !wp_verify_nonce( $nonce, 'bulk-users' ) ) {
140 return;
141 }
142
143 $capability = current_user_can( 'manage_options' );
144 if( !$capability ) return;
145
146 $user->remove_role( 'timetics-staff' );
147 }
148 }
149
150 /**
151 * Setup staff onboard page
152 *
153 * @return void
154 */
155 public function setup_staff_onboard() {
156 $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
157
158 if ( 'staff-onboard' === $page ) {
159 Onboard::instance()->init();
160 }
161 }
162
163 /**
164 * Setup redirect uri
165 *
166 * @param string $reidrect_to
167 * @param string $requeted_redirect
168 * @param WP_User $user Login user
169 *
170 * @return void
171 */
172 public function login_redirect( $reidrect_to, $requeted_redirect, $user ) {
173 global $user;
174
175 $roles = isset( $user->roles ) ? $user->roles : [];
176
177 if ( is_wp_error( $user ) ) {
178 return $reidrect_to;
179 }
180
181 $onboard_skip = get_user_meta( $user->ID, 'timetics_staff_onboard_skip', true );
182
183 if ( $onboard_skip ) {
184 return $reidrect_to;
185 }
186
187 if ( ! in_array( 'timetics-staff', $roles ) ) {
188 return $reidrect_to;
189 }
190
191 $integrations = timetics_get_staff_integrations( $user->ID );
192
193 if ( ! $integrations[0]['connected'] ) {
194 $reidrect_to = admin_url( 'admin.php?page=staff-onboard' );
195 }
196
197 return $reidrect_to;
198 }
199
200 /**
201 * Update password reset email title
202 *
203 * @param string $title
204 *
205 * @return string
206 */
207 public function reset_email_title( $title ) {
208 $title = sprintf( esc_html__( 'Welcome to %s onboarding!', 'timetics' ), get_bloginfo( 'name' ) );
209
210 return $title;
211 }
212
213 /**
214 * Staff onboard skip
215 *
216 * @return void
217 */
218 public function timetics_staff_onboard_skip() {
219 update_user_meta( get_current_user_id(), 'timetics_staff_onboard_skip', true );
220
221 wp_send_json_success( __( 'Staff onboard skipped successfully.', 'timetics' ) );
222 }
223 }