PluginProbe
Timetics – Appointment Booking Calendar & Scheduling / 1.0.64
Timetics – Appointment Booking Calendar & Scheduling v1.0.64
1.0.64 1.0.62 1.0.63 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 All 65 releases
← All changes | core/staffs/staff.php +96 -9 1.0.0 → 1.0.64 View file →
@@ -85,9 +85,9 @@
85 85 *
86 86 * @return string
87 87 */
88 88 public function get_first_name() {
89 - return $this->get_prop( 'first_name', '' );
89 + return get_user_meta( $this->id, 'first_name', true );
90 90 }
91 91
92 92 /**
93 93 * Get last name
@@ -94,11 +94,21 @@
94 94 *
95 95 * @return string
96 96 */
97 97 public function get_last_name() {
98 - return $this->get_prop( 'last_name', '' );
98 + return get_user_meta( $this->id, 'last_name', true );
99 99 }
100 100
101 + /**
102 + * Get password
103 + *
104 + * @return string
105 + */
106 + public function get_password() {
107 + $user = get_user_by( 'id', $this->id );
108 + return $user->user_pass;
109 + }
110 +
101 111 /**
102 112 * Get staff display name
103 113 *
104 114 * @return string
@@ -119,9 +129,15 @@
119 129 *
120 130 * @return string
121 131 */
122 132 public function get_email() {
123 - return get_userdata( $this->id )->user_email;
133 + $staff = get_userdata( $this->id );
134 +
135 + if ( $staff ) {
136 + return $staff->user_email;
137 + }
138 +
139 + return '';
124 140 }
125 141
126 142 /**
127 143 * Get phone
@@ -139,10 +155,15 @@
139 155 */
140 156 public function get_image() {
141 157 $image = $this->get_prop( 'image' );
142 158
159 + if ( filter_var( $image, FILTER_VALIDATE_URL ) ) {
160 + return $image;
161 + }
162 +
163 +
143 164 if ( ! $image ) {
144 - return get_avatar_url( $this->id );
165 + return false;
145 166 }
146 167
147 168 return wp_get_attachment_image_url( $image );
148 169 }
@@ -179,12 +200,40 @@
179 200 *
180 201 * @return mixed
181 202 */
182 203 public function get_status() {
204 + $user = get_userdata( $this->id );
205 +
206 + if ( user_can( $user, 'manage_options' ) ) {
207 + return 1;
208 + }
209 +
183 210 return $this->get_prop( 'status' );
184 211 }
185 212
186 213 /**
214 + * Get full name;
215 + *
216 + * @return string
217 + */
218 + public function get_full_name() {
219 + $first_name = $this->get_first_name();
220 + $last_name = $this->get_last_name();
221 +
222 + if ( ! $first_name ) {
223 + return $this->get_display_name();
224 + }
225 +
226 + if ( ! $last_name ) {
227 + return $first_name;
228 + }
229 +
230 +
231 +
232 + return $first_name . ' ' . $last_name;
233 + }
234 +
235 + /**
187 236 * Get all data for a staff
188 237 *
189 238 * @return array
190 239 */
@@ -190,9 +239,9 @@
190 239 */
191 240 public function get_data() {
192 241 return [
193 242 'id' => $this->get_id(),
194 - 'full_name' => $this->get_display_name(),
243 + 'full_name' => $this->get_full_name(),
195 244 'first_name' => $this->get_first_name(),
196 245 'last_name' => $this->get_last_name(),
197 246 'user_name' => $this->get_user_name(),
198 247 'email' => $this->get_email(),
@@ -273,8 +322,24 @@
273 322 'role' => 'timetics-staff',
274 323 ];
275 324
276 325 $args = wp_parse_args( $args, $defaults );
326 +
327 + $email = ! empty( $args['user_email'] ) ? $args['user_email'] : '';
328 +
329 + if ( $email ) {
330 + $user['user_email'] = $email;
331 + }
332 +
333 + $user = get_user_by( 'email', $email );
334 +
335 + // An existing account with this email is a conflict, not an instruction
336 + // to promote it — silently granting the staff role let a caller take
337 + // over any account by submitting its email.
338 + if ( $user ) {
339 + return new \WP_Error( 'timetics_staff_email_exists', __( 'A user with this email address already exists.', 'timetics' ) );
340 + }
341 +
277 342 $user_id = wp_insert_user( $args );
278 343
279 344 if ( ! is_wp_error( $user_id ) ) {
280 345 $this->set_id( $user_id );
@@ -290,21 +355,33 @@
290 355 *
291 356 * @return void
292 357 */
293 358 public function update( $args = [] ) {
294 - $user = get_userdata( $this->id )->to_array();
359 + $user = get_userdata( $this->id )->to_array();
360 + $email = ! empty( $args['user_email'] ) ? $args['user_email'] : '';
295 361
296 362 if ( ! empty( $args['user_pass'] ) ) {
297 363 $user['user_pass'] = $args['user_pass'];
298 364 }
299 365
300 - if ( ! empty( $args['email'] ) ) {
301 - $user['user_email'] = $args['email'];
366 + if ( $email ) {
367 + $user['user_email'] = $email;
302 368 }
303 369
370 + $user_data = get_user_by( 'email', $email );
371 +
372 + // Only a conflict if it belongs to someone other than the staff member
373 + // being edited — otherwise every update where they keep their own
374 + // email would (incorrectly) hit this branch. See create() for why a
375 + // match must never silently grant the staff role.
376 + if ( $user_data && (int) $user_data->ID !== (int) $this->id ) {
377 + return new \WP_Error( 'timetics_staff_email_exists', __( 'A user with this email address already exists.', 'timetics' ) );
378 + }
379 +
304 380 $updated = wp_update_user( $user );
305 381
306 382 if ( ! is_wp_error( $updated ) ) {
383 +
307 384 $this->save_metadata( $args );
308 385 }
309 386
310 387 return $updated;
@@ -321,9 +398,13 @@
321 398 continue;
322 399 }
323 400
324 401 // Prepare meta key.
325 - $meta_key = $this->meta_prefix . $key;
402 + if( $key == 'first_name' || $key == 'last_name' ) {
403 + $meta_key = $key;
404 + } else {
405 + $meta_key = $this->meta_prefix . $key;
406 + }
326 407
327 408 // Update appointment meta data.
328 409 update_user_meta( $this->id, $meta_key, $value );
329 410 }
@@ -352,8 +433,14 @@
352 433 if ( count( $user->roles ) > 1 ) {
353 434 $user->remove_role('timetics-staff');
354 435
355 436 return true;
437 + }
438 +
439 + if ( is_multisite() ) {
440 + require_once ABSPATH . 'wp-admin/includes/ms.php';
441 +
442 + return wpmu_delete_user( $this->id );
356 443 }
357 444
358 445 return wp_delete_user( $this->id );
359 446 }