candidates = $candidates; $this->sessions = $sessions; $this->emails = $emails; $this->events = $events; $this->reminders = $reminders; } /** * {@inheritdoc} */ public function register(): void { add_filter( 'wp_privacy_personal_data_exporters', array( $this, 'add_exporter' ) ); add_filter( 'wp_privacy_personal_data_erasers', array( $this, 'add_eraser' ) ); add_action( 'admin_init', array( $this, 'add_policy_text' ) ); } /** * Registers the exporter. * * @since 0.1.0 * * @param array $exporters Exporters. * @return array */ public function add_exporter( $exporters ) { $exporters['interviewnea'] = array( 'exporter_friendly_name' => __( 'InterviewNea interview candidates', 'interviewnea' ), 'callback' => array( $this, 'export' ), ); return $exporters; } /** * Registers the eraser. * * @since 0.1.0 * * @param array $erasers Erasers. * @return array */ public function add_eraser( $erasers ) { $erasers['interviewnea'] = array( 'eraser_friendly_name' => __( 'InterviewNea interview candidates', 'interviewnea' ), 'callback' => array( $this, 'erase' ), ); return $erasers; } /** * Exports everything stored about an email address. * * @since 0.1.0 * * @param string $email_address Email address. * @param int $page Page (everything fits one page). * @return array{data: array>, done: bool} */ public function export( $email_address, $page = 1 ): array { unset( $page ); $items = array(); foreach ( $this->candidates->all_by_email( (string) $email_address ) as $candidate ) { $session = $this->sessions->find( (int) $candidate->session_id ); $data = array( array( 'name' => __( 'Name', 'interviewnea' ), 'value' => $candidate->full_name, ), array( 'name' => __( 'Email', 'interviewnea' ), 'value' => $candidate->email, ), array( 'name' => __( 'Phone', 'interviewnea' ), 'value' => $candidate->phone, ), array( 'name' => __( 'Interview session', 'interviewnea' ), 'value' => $session ? $session->title . ' (' . $session->session_date . ')' : '', ), array( 'name' => __( 'Status', 'interviewnea' ), 'value' => $candidate->status, ), array( 'name' => __( 'Checked in (UTC)', 'interviewnea' ), 'value' => (string) $candidate->checkin_at, ), ); foreach ( $this->emails->for_candidate( (int) $candidate->id ) as $mail ) { $data[] = array( 'name' => __( 'Email sent', 'interviewnea' ), 'value' => $mail->created_at . ' · ' . $mail->subject . ' · ' . $mail->delivery_status, ); } $items[] = array( 'group_id' => 'interviewnea-candidates', 'group_label' => __( 'Interview candidate records', 'interviewnea' ), 'item_id' => 'interviewnea-candidate-' . (int) $candidate->id, 'data' => $data, ); } return array( 'data' => $items, 'done' => true, ); } /** * Erases candidate records for an email address, except candidates in a live call. * * @since 0.1.0 * * @param string $email_address Email address. * @param int $page Page (everything fits one page). * @return array{items_removed: bool, items_retained: bool, messages: string[], done: bool} */ public function erase( $email_address, $page = 1 ): array { unset( $page ); $removed = false; $retained = false; $messages = array(); foreach ( $this->candidates->all_by_email( (string) $email_address ) as $candidate ) { $session = $this->sessions->find( (int) $candidate->session_id ); if ( ! $session || ! CandidateLifecycle::can_modify( $candidate->status, (int) $session->current_candidate_id === (int) $candidate->id ) ) { $retained = true; $messages[] = __( 'A candidate record was kept because the person is in a live interview call. Request erasure again once the call has ended.', 'interviewnea' ); continue; } if ( $this->candidates->delete( (int) $candidate->id ) ) { $this->reminders->clear( (int) $candidate->id ); $this->events->log( (int) $session->id, 0, 'candidate_erased', 'Candidate erased on a privacy request; ID ' . (int) $candidate->id ); $removed = true; } } return array( 'items_removed' => $removed, 'items_retained' => $retained, 'messages' => array_values( array_unique( $messages ) ), 'done' => true, ); } /** * Adds suggested text to the privacy policy guide. * * @since 0.1.0 * * @return void */ public function add_policy_text(): void { if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) { return; } $content = '

' . esc_html__( 'Interview candidates', 'interviewnea' ) . '

' . '

' . esc_html__( 'When you check in for a virtual interview, we match the email address and phone number you enter against your application record. We store your name, email address, phone number, interview status and the times of your check-in and interview. Copies of the reminder emails sent to you are kept in a log for the period set by the site administrator, and are deleted when your candidate record is deleted.', 'interviewnea' ) . '

' . '

' . esc_html__( 'Your browser stores a random check-in token in local storage so that the waiting-room page can reconnect after a refresh.', 'interviewnea' ) . '

'; wp_add_privacy_policy_content( 'InterviewNea', wp_kses_post( wpautop( $content, false ) ) ); } }