> $exporters Exporters. * @return array> */ public static function add_exporter( array $exporters ): array { $exporters['flexsolutions-form-builder'] = array( 'exporter_friendly_name' => __( 'Flexsolutions Form Builder entries', 'flexsolutions-form-builder' ), 'callback' => array( self::class, 'export' ), ); return $exporters; } /** * Adds the eraser. * * @param array> $erasers Erasers. * @return array> */ public static function add_eraser( array $erasers ): array { $erasers['flexsolutions-form-builder'] = array( 'eraser_friendly_name' => __( 'Flexsolutions Form Builder entries', 'flexsolutions-form-builder' ), 'callback' => array( self::class, 'erase' ), ); return $erasers; } /** * Exports one page of entries for an email address. * * @param string $email Email address. * @param int $page Page (1-based). * @return array{data:array>,done:bool} */ public static function export( string $email, int $page = 1 ): array { $ids = is_email( $email ) ? Entry_Store::ids_with_value( $email, self::PAGE_SIZE, ( max( 1, $page ) - 1 ) * self::PAGE_SIZE ) : array(); $data = array(); foreach ( $ids as $id ) { $entry = Entry_Store::get( $id ); if ( null === $entry ) { continue; } $items = array( array( 'name' => __( 'Form', 'flexsolutions-form-builder' ), 'value' => get_the_title( (int) $entry->form_id ), ), array( 'name' => __( 'Submitted (UTC)', 'flexsolutions-form-builder' ), 'value' => (string) $entry->created_at, ), ); if ( '' !== (string) $entry->ip ) { $items[] = array( 'name' => __( 'IP address', 'flexsolutions-form-builder' ), 'value' => (string) $entry->ip, ); } foreach ( $entry->values as $name => $value ) { $items[] = array( 'name' => (string) $name, 'value' => (string) $value, ); } foreach ( $entry->files as $file ) { $items[] = array( 'name' => (string) $file->field_name, 'value' => (string) $file->original_name, ); } $tags = Entry_Tags::for_entries( array( $id ) )[ $id ] ?? array(); if ( array() !== $tags ) { $items[] = array( 'name' => __( 'Tags', 'flexsolutions-form-builder' ), 'value' => implode( ', ', $tags ), ); } foreach ( Entry_Notes::for_entry( $id ) as $note ) { $items[] = array( 'name' => __( 'Note', 'flexsolutions-form-builder' ), 'value' => (string) $note->content, ); } $data[] = array( 'group_id' => 'flexsolutions-form-builder', 'group_label' => __( 'Form submissions', 'flexsolutions-form-builder' ), 'item_id' => 'tflexforms-entry-' . $id, 'data' => $items, ); } return array( 'data' => $data, 'done' => count( $ids ) < self::PAGE_SIZE, ); } /** * Erases entries (and their files) for an email address. * * @param string $email Email address. * @param int $page Page (always 1: deleted rows shift the results). * @return array{items_removed:bool,items_retained:bool,messages:string[],done:bool} */ public static function erase( string $email, int $page = 1 ): array { unset( $page ); $ids = is_email( $email ) ? Entry_Store::ids_with_value( $email, self::PAGE_SIZE ) : array(); $removed = array() !== $ids && Entry_Store::delete( $ids ) > 0; return array( 'items_removed' => $removed, 'items_retained' => false, 'messages' => array(), 'done' => count( $ids ) < self::PAGE_SIZE, ); } /** * Suggested text for the site's privacy policy. */ public static function policy_text(): void { if ( ! function_exists( 'wp_add_privacy_policy_content' ) ) { return; } wp_add_privacy_policy_content( __( 'Flexsolutions Form Builder', 'flexsolutions-form-builder' ), wp_kses_post( '

' . __( 'When you submit a form on this site, the information you enter is emailed to us and may be stored in our database so we can respond. If enabled, your IP address is stored with the submission. Stored submissions are kept for the period set by the site owner and can be exported or erased on request.', 'flexsolutions-form-builder' ) . '

' . '

' . __( 'Some forms use a CAPTCHA service (Cloudflare Turnstile, Google reCAPTCHA or hCaptcha) or Akismet to block spam; these services receive your IP address and, for Akismet, the content of your message.', 'flexsolutions-form-builder' ) . '

' ) ); } }