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 / staffs / hooks.php

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

205 lines 5.7 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 void
111 */
112 public function make_staff() {
113 $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
114 $user_id = isset( $_GET['users'] ) ? intval( $_GET['users'] ) : 0;
115 $user = get_userdata( $user_id );
116
117 if ( 'makestaff' === $action ) {
118 $user->add_role( 'timetics-staff' );
119 $staff = new Staff( $user_id );
120 $staff->update(
121 [
122 'status' => 1,
123 ]
124 );
125 }
126
127 if ( 'removestaff' === $action ) {
128 $user->remove_role( 'timetics-staff' );
129 }
130 }
131
132 /**
133 * Setup staff onboard page
134 *
135 * @return void
136 */
137 public function setup_staff_onboard() {
138 $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
139
140 if ( 'staff-onboard' === $page ) {
141 Onboard::instance()->init();
142 }
143 }
144
145 /**
146 * Setup redirect uri
147 *
148 * @param string $reidrect_to
149 * @param string $requeted_redirect
150 * @param WP_User $user Login user
151 *
152 * @return void
153 */
154 public function login_redirect( $reidrect_to, $requeted_redirect, $user ) {
155 global $user;
156
157 $roles = isset( $user->roles ) ? $user->roles : [];
158
159 if ( is_wp_error( $user ) ) {
160 return $reidrect_to;
161 }
162
163 $onboard_skip = get_user_meta( $user->ID, 'timetics_staff_onboard_skip', true );
164
165 if ( $onboard_skip ) {
166 return $reidrect_to;
167 }
168
169 if ( ! in_array( 'timetics-staff', $roles ) ) {
170 return $reidrect_to;
171 }
172
173 $integrations = timetics_get_staff_integrations( $user->ID );
174
175 if ( ! $integrations[0]['connected'] ) {
176 $reidrect_to = admin_url( 'admin.php?page=staff-onboard' );
177 }
178
179 return $reidrect_to;
180 }
181
182 /**
183 * Update password reset email title
184 *
185 * @param string $title
186 *
187 * @return string
188 */
189 public function reset_email_title( $title ) {
190 $title = sprintf( esc_html__( 'Welcome to %s onboarding!', 'timetics' ), get_bloginfo( 'name' ) );
191
192 return $title;
193 }
194
195 /**
196 * Staff onboard skip
197 *
198 * @return void
199 */
200 public function timetics_staff_onboard_skip() {
201 update_user_meta( get_current_user_id(), 'timetics_staff_onboard_skip', true );
202
203 wp_send_json_success( __( 'Staff onboard skipped successfully.', 'timetics' ) );
204 }
205 }