getInputs(); $id = (int) ( $inputs['staff_id'] ?? 0 ); $name = $id > 0 ? get_the_author_meta( 'display_name', $id ) : ''; $label = '' !== $name ? "\"{$name}\" (ID: {$id})" : "#{$id}"; return "Resend the invitation email to staff {$label}"; } public function get_approval_inputs(): array { $inputs = $this->getInputs(); if ( isset( $inputs['staff_id'] ) ) { $id = (int) $inputs['staff_id']; $name = get_the_author_meta( 'display_name', $id ); $inputs['staff_id'] = '' !== $name ? "{$name} (ID: {$id})" : (string) $id; } return $inputs; } public function __invoke( int $staff_id ): array { $check = $this->guard_admin(); if ( $check ) { return $check; } if ( $staff_id <= 0 || ! class_exists( '\Timetics\Core\Staffs\Staff' ) ) { return [ 'error' => 'A valid staff_id is required.' ]; } $staff = new \Timetics\Core\Staffs\Staff( $staff_id ); if ( ! $staff->is_staff() ) { return [ 'error' => "Staff #{$staff_id} was not found." ]; } try { $request = $this->build_request( 'GET', '/timetics/v1/staffs/re-invite/' . $staff_id, [], null, [ 'staff_id' => $staff_id ] ); if ( is_array( $request ) ) { return $request; } $controller = \Timetics\Core\Staffs\Api_Staff::instance(); $data = $this->extract_response( $controller->re_invite_staff( $request ), "Failed to re-invite staff #{$staff_id}." ); if ( isset( $data['error'] ) ) { return $data; } return [ 'success' => true, 'staff_id' => $staff_id, 'message' => "Invitation email resent to staff #{$staff_id}.", ]; } catch ( \Throwable $e ) { Log::error( 'Timetics_Reinvite_Staff_Tool error', [ 'error' => $e->getMessage() ] ); return [ 'error' => 'Failed to re-invite staff: ' . $e->getMessage() ]; } } }