(int) $row->id, 'form_id' => (int) $row->form_id, 'fields' => json_decode( $row->fields, true ), 'ip_address' => $row->ip_address, 'created_at' => $row->created_at, ]; } nocache_headers(); header( 'Content-Type: application/json; charset=utf-8' ); header( 'Content-Disposition: attachment; filename="phemightforms-gdpr-' . sanitize_file_name( $email ) . '.json"' ); echo wp_json_encode( $payload, JSON_PRETTY_PRINT ); exit; } /** * Delete entries containing the given email. * * @param string $email Email to match. * @return int Number deleted. */ private static function delete_by_email( $email ) { global $wpdb; $rows = self::find_entries( $email ); $table = Install::entries_table(); $count = 0; foreach ( $rows as $row ) { $wpdb->delete( $table, [ 'id' => $row->id ], [ '%d' ] ); // phpcs:ignore WordPress.DB $count++; } return $count; } /** * Find entry rows whose JSON contains the email. * * @param string $email Email address. * @return array */ private static function find_entries( $email ) { global $wpdb; $table = Install::entries_table(); $like = '%' . $wpdb->esc_like( $email ) . '%'; return $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$table} WHERE fields LIKE %s", $like ) ); // phpcs:ignore WordPress.DB } }