Skip to content

feat(export): add an options dialog to the CSV exports (NPPD-2231) - #1001

Open
adekbadek wants to merge 2 commits into
releasefrom
nppd-2231-members-export-reach-parity-with-the-woocommerce-memberships
Open

feat(export): add an options dialog to the CSV exports (NPPD-2231)#1001
adekbadek wants to merge 2 commits into
releasefrom
nppd-2231-members-export-reach-parity-with-the-woocommerce-memberships

Conversation

@adekbadek

Copy link
Copy Markdown
Member

All Submissions:

Changes proposed in this Pull Request:

The CSV exports on the Users and Subscriptions list tables were a bare button with no options, so publishers coming off WooCommerce Memberships lost controls the member export had. "Export CSV" now opens a dialog, prefilled from the filters already applied to the list.

It holds a creation/registration date range on both exports, multi-role selection on users (core allows one role at a time), multi-status on subscriptions (the status tabs are one at a time), a delimiter choice, and a date format. A picker offers the user meta keys the site actually stores, adding one column per key — that covers the registration fields Memberships collected, and anything a form plugin writes.

Clearing every checkbox means "all", overriding the filter the dialog was opened on. A list view the dialog has no control for keeps its filter instead: core's role-less ?role=none and the subscriptions Trash tab were never offered a box to clear, and dropping them would silently widen a PII export.

The same options are on wp newspack export-users and wp newspack export-subscriptions. Unlike the dialog, whose values come from a list the server rendered, the CLI rejects a flag value it does not recognize rather than dropping it — a mistyped --role used to narrow to nothing and would otherwise now widen to everything.

Two behaviour changes worth knowing about:

  • The users export's Registered Date is written in the site's timezone. It was UTC, which would contradict the date range that selected the row.
  • The meta columns are headed by the raw meta key. The Memberships export headed them with the bare field slug, so an existing spreadsheet keyed on those headers will not line up.

Closes NPPD-2231.

How to test the changes in this Pull Request:

  1. Activate WooCommerce and WooCommerce Subscriptions.
  2. Go to Users. Filter the list by a role.
  3. Select "Export CSV". A dialog opens with that role checked.
  4. Set a registration date range. Select a second role.
  5. Select one or more keys under "Extra user meta".
  6. Set "Separate fields by" to Semicolon. Set "Date format" to Custom and enter D, d M Y.
  7. Select "Export". The file holds both roles, only users registered in the range, one column per selected meta key, semicolon separators and the custom date format.
  8. Open the dialog again. Clear every role checkbox. Select "Export".
  9. The file holds every role, not the role the list was filtered by.
  10. Go to WooCommerce > Subscriptions. Open a status tab.
  11. Select "Export CSV". Check a second status. Select "Export".
  12. The file holds both statuses.
  13. Run wp newspack export-users --role=subscrber. The command stops with "Unrecognized --role value".
  14. Run wp newspack export-users --meta=<a key from the picker> --date-from=2024-01-01. The file holds that column.

Export users dialog, prefilled from the list's role filter

Export users dialog with a date range, two roles, two meta keys, semicolon delimiter and a custom date format

Export users dialog with the prefilled role selection cleared

Export subscriptions dialog with Active and Expired both selected

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?

Base is release per the ticket's hotfix note; the forward-port to main/alpha is automatic.

n test-php --group csv-export passes at 62 tests; the full newspack-plugin suite passes at 2929.

Gate/plan and computed-access columns (the ticket's item 5), and merging the subscription columns into a single export (item 4), are follow-ups.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds an export-options modal for the admin “Export CSV” actions on Users and WooCommerce Subscriptions list tables, and unifies those options with the wp newspack export-users / wp newspack export-subscriptions CLI commands via a shared sanitization boundary.

Changes:

  • Introduces a <dialog>-based options UI (roles/statuses multi-select, date range, delimiter, date format, and user-meta columns) and posts a serialized config through each AJAX export step.
  • Extends the users/subscriptions exporters to apply the sanitized export config (query args + optional columns + delimiter + formatted dates) and ensures the headers-row temp file exists for ended-short runs.
  • Adds/expands PHPUnit coverage around config sanitization, query-arg precedence rules, date handling, meta-key columns, and CLI flag validation.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
plugins/newspack-plugin/tests/unit-tests/export/class-users-csv-exporter.php Adds tests for role precedence, registration date range behavior, and opt-in meta columns.
plugins/newspack-plugin/tests/unit-tests/export/class-user-meta-columns.php New unit tests for available meta keys, sanitization, column naming, and value flattening/encoding.
plugins/newspack-plugin/tests/unit-tests/export/class-subscriptions-csv-exporter.php Adds tests for status/date-range precedence and “cleared selection” semantics.
plugins/newspack-plugin/tests/unit-tests/export/class-csv-exports.php Adds tests for export-config sanitization, date formatting, delimiter propagation, and column recomputation.
plugins/newspack-plugin/tests/unit-tests/export/class-csv-exports-handlers.php Extends handler tests to verify header-row temp file existence for short runs.
plugins/newspack-plugin/src/csv-export/style.scss Styles the new export options dialog and its form controls.
plugins/newspack-plugin/src/csv-export/index.js Updates the export flow to open the modal, serialize options, and replay them through each AJAX step.
plugins/newspack-plugin/includes/export/class-users-csv-exporter.php Applies export config to query args, adds meta columns, and formats registration dates consistently with config.
plugins/newspack-plugin/includes/export/class-user-meta-columns.php New helper for discovering, sanitizing, and exporting user-meta columns.
plugins/newspack-plugin/includes/export/class-subscriptions-csv-exporter.php Applies export config to status/date filters and formats date columns via shared formatting logic.
plugins/newspack-plugin/includes/export/class-csv-exports.php Renders modal(s), sanitizes posted export config, and threads config into export execution + download constraints.
plugins/newspack-plugin/includes/export/class-csv-batch-exporter.php Adds export-config storage, delimiter/columns recompute, date-formatting helper, and header-row file enforcement.
plugins/newspack-plugin/includes/cli/class-export.php Adds CLI flags for the same export options and validates that CLI-supplied restrictions survive sanitization.
Suppressed comments (1)

plugins/newspack-plugin/includes/export/class-csv-exports.php:487

  • The helper text for the Statuses checkbox group is misleading on the Subscriptions Trash view. When the list is filtered to Trash, clearing all checkboxes still keeps the Trash filter (by design), so the copy shouldn’t claim it will export every status in all cases.
					<fieldset class="newspack-csv-export-modal__field" aria-describedby="<?php echo \esc_attr( $id ); ?>-statuses-desc">
						<legend><?php \esc_html_e( 'Statuses', 'newspack-plugin' ); ?></legend>
						<p class="description" id="<?php echo \esc_attr( $id ); ?>-statuses-desc"><?php \esc_html_e( 'Leave all unchecked to export every status.', 'newspack-plugin' ); ?></p>
						<div class="newspack-csv-export-modal__checkboxes">

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread plugins/newspack-plugin/includes/export/class-csv-exports.php
@adekbadek
adekbadek marked this pull request as ready for review August 31, 2026 13:07
@adekbadek
adekbadek requested a review from a team as a code owner August 31, 2026 13:07
@dkoo dkoo self-assigned this Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants