| @@ -83,8 +83,17 @@ | ||
| 83 | 83 | ); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
| 87 | + /** | |
| 88 | + * Parsers and sanitizes staff data to array. | |
| 89 | + * | |
| 90 | + * @since 1.0.0 | |
| 91 | + * | |
| 92 | + * @param array<int, array<string, mixed>> $staff Staff data to parse. | |
| 93 | + * | |
| 94 | + * @return array<int, array<string, mixed>> | |
| 95 | + */ | |
| 87 | 96 | public static function parseStaff( $staff ) { |
| 88 | 97 | $result = array(); |
| 89 | 98 | foreach ( $staff as $key => $employee ) { |
| 90 | 99 | $item = (array) $employee; |
| @@ -90,8 +99,22 @@ | ||
| 90 | 99 | $item = (array) $employee; |
| 91 | 100 | $item['full_name'] = stripslashes( $employee['full_name'] ); |
| 92 | 101 | $item['staff_services'] = json_decode( $employee['staff_services'] ?? '', true ) ?: []; |
| 93 | 102 | $item['working_hours'] = json_decode( $employee['working_hours'] ?? '', true ) ?: []; |
| 103 | + | |
| 104 | + // Ensure gc_token is always an object with auth_url property to prevent frontend errors. | |
| 105 | + if ( | |
| 106 | + ! isset( $item['gc_token'] ) | |
| 107 | + || null === $item['gc_token'] | |
| 108 | + || ! is_array( $item['gc_token'] ) | |
| 109 | + ) { | |
| 110 | + $item['gc_token'] = [ | |
| 111 | + 'auth_url' => '', | |
| 112 | + ]; | |
| 113 | + } elseif ( ! isset( $item['gc_token']['auth_url'] ) ) { | |
| 114 | + $item['gc_token']['auth_url'] = ''; | |
| 115 | + } | |
| 116 | + | |
| 94 | 117 | array_push( $result, $item ); |
| 95 | 118 | } |
| 96 | 119 | unset( $staff ); |
| 97 | 120 | return $result; |
| @@ -281,14 +304,15 @@ | ||
| 281 | 304 | $wpUser = get_user_by( 'ID', $data['wp_user_id'] ); |
| 282 | 305 | $wpUser->set_role( User::$staff_role ); |
| 283 | 306 | } |
| 284 | 307 | |
| 285 | - /** if google calendar addon is installed */ | |
| 308 | + // Always return staff data so frontend can use cleaned phone number. | |
| 309 | + $staff = (array) Staff::get( 'id', $id ); | |
| 310 | + | |
| 311 | + // Required for Google Calendar addon is installed. | |
| 286 | 312 | if ( Plugin::isAddonInstalledAndEnabled( self::$proAddon ) && has_filter( 'bookit_filter_connect_employee_google_calendar' ) ) { |
| 287 | - $staff = (array) Staff::get( 'id', $id ); | |
| 288 | 313 | $staff = apply_filters( 'bookit_filter_connect_employee_google_calendar', $staff ); |
| 289 | 314 | } |
| 290 | - /** if google calendar addon is installed | end */ | |
| 291 | 315 | |
| 292 | 316 | do_action( 'bookit_staff_saved', $id ); |
| 293 | 317 | |
| 294 | 318 | wp_send_json_success( |