plugin = $plugin; } public function register() { add_filter('wp_privacy_personal_data_exporters', [$this, 'exporters']); add_filter('wp_privacy_personal_data_erasers', [$this, 'erasers']); add_action('admin_init', [$this, 'policy']); } public function policy() { if (function_exists('wp_add_privacy_policy_content')) { wp_add_privacy_policy_content( 'SSF Forms & Workflows', wp_kses_post( '
Forms may collect the answers and files you choose to submit. Accepted answers are stored in this WordPress database. Administrators may enable email notifications and optional integrations, which send the configured answers to the chosen recipients or services. Notification acceptance is not proof of inbox delivery.
Submission records keep the form definition used at submission time. The default form retention is 90 days; administrators may choose another period or zero for manual retention. Rate limiting uses a short-lived salted hash of the request address, not a stored raw IP address. Erasure removes local submissions and their queued actions; it cannot recall previously sent emails or erase copies held by an independently configured service. Uninstall keeps saved data by default.
', ), ); } } public function exporters($exporters) { $exporters['ssf-forms'] = [ 'exporter_friendly_name' => __('SSF Forms submissions', 'ssf-forms'), 'callback' => [$this, 'export'], ]; return $exporters; } public function erasers($erasers) { $erasers['ssf-forms'] = [ 'eraser_friendly_name' => __('SSF Forms submissions', 'ssf-forms'), 'callback' => [$this, 'erase'], ]; return $erasers; } public function export($email, $page = 1) { global $wpdb; $email = sanitize_email($email); if (!$email) { return ['data' => [], 'done' => true]; } $page = max(1, absint($page)); $like = '%' . $wpdb->esc_like($email) . '%'; $table = $this->plugin->repository->table('entries'); $rows = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i WHERE values_json LIKE %s ORDER BY id ASC LIMIT 100 OFFSET %d', $table, $like, ($page - 1) * 100, ), ARRAY_A, ); $data = []; foreach ($rows ?: [] as $row) { $entry = $this->plugin->repository->decode_entry($row); if (!$this->matches_email($entry, $email)) { continue; } $fields = [ ['name' => __('Form', 'ssf-forms'), 'value' => $entry['form_title']], ['name' => __('Submitted (UTC)', 'ssf-forms'), 'value' => $entry['created_at']], ['name' => __('Submission reference', 'ssf-forms'), 'value' => $entry['submission_id']], ]; foreach ($entry['schema']['fields'] ?? [] as $field) { if (!array_key_exists($field['id'], $entry['values'])) { continue; } $answer = $entry['values'][$field['id']]; $fields[] = [ 'name' => $field['label'], 'value' => esc_html(is_scalar($answer) ? (string) $answer : wp_json_encode($answer)), ]; } $data[] = [ 'group_id' => 'ssf-forms-submissions', 'group_label' => __('Form submissions', 'ssf-forms'), 'item_id' => 'ssffw-' . $entry['id'], 'data' => $fields, ]; } return ['data' => $data, 'done' => count($rows ?: []) < 100]; } public function erase($email, $page = 1) { global $wpdb; $email = sanitize_email($email); $result = [ 'items_removed' => false, 'items_retained' => false, 'messages' => [], 'done' => true, ]; if (!$email) { return $result; } $cursor_key = 'ssffw_erase_' . hash_hmac('sha256', strtolower($email), wp_salt('nonce')); $cursor = (int) get_transient($cursor_key); if ((int) $page === 1) { $cursor = 0; } $like = '%' . $wpdb->esc_like($email) . '%'; $table = $this->plugin->repository->table('entries'); $rows = $wpdb->get_results( $wpdb->prepare( 'SELECT * FROM %i WHERE id > %d AND values_json LIKE %s ORDER BY id ASC LIMIT 100', $table, $cursor, $like, ), ARRAY_A, ); foreach ($rows ?: [] as $row) { $cursor = max($cursor, (int) $row['id']); $entry = $this->plugin->repository->decode_entry($row); if (!$this->matches_email($entry, $email)) { continue; } $deleted = $this->plugin->repository->delete_entry($entry['id'], true); if (is_wp_error($deleted)) { $result['items_retained'] = true; $result['messages'][] = __( 'A submission could not be erased. An administrator must review its workflow storage.', 'ssf-forms', ); } else { $result['items_removed'] = true; } } $result['done'] = count($rows ?: []) < 100; if ($result['done']) { delete_transient($cursor_key); } else { set_transient($cursor_key, $cursor, HOUR_IN_SECONDS); } return $result; } private function matches_email($entry, $email) { foreach ($entry['schema']['fields'] ?? [] as $field) { if ( ($field['type'] ?? '') === 'email' && isset($entry['values'][$field['id']]) && is_string($entry['values'][$field['id']]) && strcasecmp($entry['values'][$field['id']], $email) === 0 ) { return true; } if ( ($field['type'] ?? '') === 'repeater' && is_array($entry['values'][$field['id']] ?? null) ) { foreach ($entry['values'][$field['id']] as $row) { if (!is_array($row)) { continue; } foreach ($field['fields'] ?? ($field['children'] ?? []) as $child) { if ( ($child['type'] ?? '') === 'email' && isset($row[$child['id']]) && is_string($row[$child['id']]) && strcasecmp($row[$child['id']], $email) === 0 ) { return true; } } } } } return false; } public function cleanup() { global $wpdb; $deleted = 0; $table = $this->plugin->repository->table('entries'); foreach ($this->plugin->repository->list_forms() as $form) { $days = (int) ($form['settings']['retention_days'] ?? 90); if ($days < 1) { continue; } $cutoff = gmdate('Y-m-d H:i:s', time() - $days * DAY_IN_SECONDS); $ids = $wpdb->get_col( $wpdb->prepare( 'SELECT id FROM %i WHERE form_id = %d AND created_at < %s ORDER BY id ASC LIMIT 500', $table, $form['id'], $cutoff, ), ); foreach ($ids ?: [] as $id) { if ($this->plugin->repository->delete_entry($id, true) === true) { $deleted++; } } } $rates = $this->plugin->repository->table('rates'); $wpdb->query($wpdb->prepare('DELETE FROM %i WHERE expires_at < %d', $rates, time())); do_action('ssffw_retention_complete', $deleted); return $deleted; } }