PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.0
Timetics – Appointment Booking Calendar & Scheduling v1.0.0
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.0, at core/staffs/hooks.php

182 lines 4.9 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\Utils\Singleton;
10 use Timetics\Core\Staffs\Onboard;
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 }
35
36 /**
37 * Reset user activation and reset password link
38 *
39 * @param array $config [$config description]
40 * @param string $key [$key description]
41 * @param [type] $user_login [$user_login description]
42 * @param [type] $user_data [$user_data description]
43 *
44 * @return [type] [return description]
45 */
46 public function reset_email_content( $config, $key, $user_login, $user_data ) {
47 $headers = 'MIME-Version: 1.0' . "\r\n";
48 $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
49
50 $local = get_locale();
51 $reset_url = site_url( "wp-login.php?action=rp&key={$key}&login={$user_login}&wp_lang={$local}" );
52
53 ob_start();
54 include TIMETICS_PLUGIN_DIR . '/templates/emails/email-header.php';
55 include TIMETICS_PLUGIN_DIR . '/templates/emails/new-staff.php';
56 include TIMETICS_PLUGIN_DIR . '/templates/emails/email-footer.php';
57 $message = ob_get_clean();
58
59 $config['message'] = $message;
60 $config['headers'] = $headers;
61
62 return $config;
63 }
64
65 /**
66 * Update staff status after updating password
67 *
68 * @param Object $user
69 *
70 * @return void
71 */
72 public function update_staff_status( $user ) {
73 $staff = new Staff( $user->ID );
74
75 if ( ! $staff->is_staff() ) {
76 return;
77 }
78
79 $staff->update(
80 [
81 'status' => 1,
82 ]
83 );
84 }
85
86 /**
87 * Show row actions for make staff
88 *
89 * @param array $actions
90 * @param Object $user_object
91 *
92 * @return void
93 */
94 public function user_row_action( $actions, $user_object ) {
95 $is_staff = user_can( $user_object, 'timetics-staff' );
96 $button_text = $is_staff ? __( 'Remove from staff', 'timetics' ) : __( 'Make staff', 'timetics' );
97 $action = $is_staff ? 'removestaff' : 'makestaff';
98
99 $actions['staff'] = "<a class='staff' href='" . wp_nonce_url( "users.php?action=$action&amp;users=$user_object->ID", 'bulk-users' ) . "'>" . $button_text . '</a>';
100
101 return $actions;
102 }
103
104 /**
105 * Make staff
106 *
107 * @return void
108 */
109 public function make_staff() {
110 $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
111 $user_id = isset( $_GET['users'] ) ? intval( $_GET['users'] ) : 0;
112 $user = get_userdata( $user_id );
113
114 if ( 'makestaff' === $action ) {
115 $user->add_role( 'timetics-staff' );
116 $staff = new Staff( $user_id );
117 $staff->update(
118 [
119 'status' => 1,
120 ]
121 );
122 }
123
124 if ( 'removestaff' === $action ) {
125 $user->remove_role( 'timetics-staff' );
126 }
127 }
128
129 /**
130 * Setup staff onboard page
131 *
132 * @return void
133 */
134 public function setup_staff_onboard() {
135 $page = isset( $_GET['page'] ) ? sanitize_text_field( $_GET['page'] ) : '';
136
137 if ( 'staff-onboard' === $page ) {
138 Onboard::instance()->init();
139 }
140 }
141
142 /**
143 * Setup redirect uri
144 *
145 * @param string $reidrect_to
146 * @param string $requeted_redirect
147 * @param WP_User $user Login user
148 *
149 * @return void
150 */
151 public function login_redirect( $reidrect_to, $requeted_redirect, $user ) {
152 global $user;
153
154 $roles = isset( $user->roles ) ? $user->roles : [];
155
156 if ( ! in_array('timetics-staff', $roles) ) {
157 return $reidrect_to;
158 }
159
160 $integrations = timetics_get_staff_integrations( $user->ID );
161
162 if ( ! $integrations[0]['connected'] ) {
163 $reidrect_to = admin_url( 'admin.php?page=staff-onboard' );
164 }
165
166 return $reidrect_to;
167 }
168
169 /**
170 * Update password reset email title
171 *
172 * @param string $title
173 *
174 * @return string
175 */
176 public function reset_email_title( $title ) {
177 $title = sprintf( __( 'Welcome to %s oboarding !', 'timetics'), get_bloginfo('name') );
178
179 return $title;
180 }
181 }
182