Skip to content

feat: add CSV export for visitor records +semver: minor#56

Merged
guibranco merged 2 commits into
mainfrom
feature/export-csv
May 13, 2026
Merged

feat: add CSV export for visitor records +semver: minor#56
guibranco merged 2 commits into
mainfrom
feature/export-csv

Conversation

@guibranco
Copy link
Copy Markdown
Owner

@guibranco guibranco commented May 13, 2026

📑 Description

Introduce a filtered CSV download from the Visitors admin screen. The export honours active search and risk-type filters, streams all matching rows unpaginated, and prepends a UTF-8 BOM for Excel compatibility. Bump version to 1.2.0.

✅ Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

☢️ Does this introduce a breaking change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Added CSV export on the Visitors screen to download all or filtered/searched visitor records as a UTF-8 CSV (includes BOM for Excel).
  • Documentation

    • Updated docs and readme to describe CSV export behavior, exported columns, filename format, and that exports include all matching records (not paginated).
  • Chores

    • Bumped plugin version to 1.2.0.

Review Change Stack

Introduce a filtered CSV download from the Visitors admin screen.
The export honours active search and risk-type filters, streams all
matching rows unpaginated, and prepends a UTF-8 BOM for Excel
compatibility. Bump version to 1.2.0.
@guibranco guibranco enabled auto-merge (squash) May 13, 2026 10:19
@gstraccini gstraccini Bot added the ☑️ auto-merge Automatic merging of pull requests (gstraccini-bot) label May 13, 2026
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @guibranco, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1319c926-aa10-456a-9ce1-58f24ae2a2f6

📥 Commits

Reviewing files that changed from the base of the PR and between 0de1298 and f6eb19c.

📒 Files selected for processing (2)
  • includes/class-ipquery-admin.php
  • includes/class-ipquery-db.php

Walkthrough

PR adds a CSV export feature to the ipquery WordPress plugin, enabling admin users to download visitor records as UTF-8 CSV with optional filters (search, risk type), and bumps the plugin version to 1.2.0 across all metadata files.

Changes

CSV Export Feature

Layer / File(s) Summary
Version 1.2.0 bump across plugin files
ipquery.php, README.md, readme.txt
Plugin version constant, header metadata, and stable tag updated from 1.1.4 to 1.2.0.
Database export query builder
includes/class-ipquery-db.php
New get_all_for_export() method fetches all visitor rows matching optional search, country, and risk filters with validated sorting, returning results without pagination.
Admin export HTTP handler and routing
includes/class-ipquery-admin.php
Admin controller registers admin_post_ipquery_export_csv hook and implements handle_export_csv() to validate nonce/permissions, read POST filters, fetch records, and stream CSV with UTF-8 BOM headers.
Export CSV form in admin toolbar
admin/views/visitors.php
New form element posts nonce, search term, and risk filter to trigger export via the admin handler.
Feature documentation and release notes
docs/visitors.md, README.md, readme.txt
New "Export CSV" documentation section details filter behavior, filename, columns, and UTF-8 BOM; feature announced in README badge, feature list, changelog, and upgrade notice.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A hop, a skip, a CSV dance—
Visitors now pack in one glance,
With filters applied, no paging in sight,
UTF-8 BOM shines oh-so-bright,
One-point-two-oh, a tidy new prize!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: add CSV export for visitor records +semver: minor' directly and accurately summarizes the main change: adding CSV export functionality for visitor records.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/export-csv

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 13, 2026

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
1 0 1

⚠️ Warnings (1)

📁 includes/class-ipquery-db.php (1 warning)
📍 Line 🔖 Check 💬 Message
399 PluginCheck.Security.DirectDB.UnescapedDBParameter Unescaped parameter $sql used in $wpdb->get_results()\n$sql assigned unsafely at line 394.

🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@includes/class-ipquery-admin.php`:
- Around line 376-401: The CSV export writes raw string cells in the foreach
loop inside class-ipquery-admin.php (the fputcsv call) and may allow
spreadsheet-formula payloads; before building the array passed to fputcsv,
sanitize each string cell (country, country_code, city, state, zipcode, org,
isp, first_seen, last_seen, and any other user-sourced text) by detecting if the
value begins with '=', '+', '-', or '@' and, if so, prefix it with a single
quote character to neutralize formulas; leave numeric and boolean fields
unchanged and apply this normalization right where the array for fputcsv is
constructed in the foreach ($rows as $row) block.

In `@includes/class-ipquery-db.php`:
- Around line 356-403: get_all_for_export currently pulls the entire result set
into memory; change it to read and emit rows in chunks (e.g., add $limit and
$offset loop or keyset pagination using the $orderby column) and fetch each page
with a prepared $wpdb->get_results call, streaming/processing each chunk instead
of returning the full array; update the function signature or add a new method
to accept a callback/Generator so callers can consume rows as they arrive, keep
using the validated $orderby/$order and $where_sql/$values logic but append
"LIMIT %d OFFSET %d" (or keyset WHERE > last_value) to the SQL and loop until an
empty chunk to avoid OOM.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 36d50206-2734-48dc-b877-8a319b65c549

📥 Commits

Reviewing files that changed from the base of the PR and between c40e02d and 0de1298.

📒 Files selected for processing (7)
  • README.md
  • admin/views/visitors.php
  • docs/visitors.md
  • includes/class-ipquery-admin.php
  • includes/class-ipquery-db.php
  • ipquery.php
  • readme.txt

Comment thread includes/class-ipquery-admin.php
Comment thread includes/class-ipquery-db.php
Reformats the fputcsv header array in the CSV export to use
one element per line for improved readability and easier
diffs. Also adds missing phpcs ignore flag
`WordPress.DB.PreparedSQL.NotPrepared` to the direct DB
query suppression comment.
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
20.1% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@guibranco guibranco merged commit bcc25d2 into main May 13, 2026
13 of 15 checks passed
@guibranco guibranco deleted the feature/export-csv branch May 13, 2026 10:31
@penify-dev
Copy link
Copy Markdown

penify-dev Bot commented May 13, 2026

Failed to generate code suggestions for PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☑️ auto-merge Automatic merging of pull requests (gstraccini-bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants