Skip to content

Add wp user privacy-request commands for GDPR personal data management#611

Open
Copilot wants to merge 10 commits intomainfrom
copilot/add-data-export-erasure-commands
Open

Add wp user privacy-request commands for GDPR personal data management#611
Copilot wants to merge 10 commits intomainfrom
copilot/add-data-export-erasure-commands

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 22, 2026

WordPress 4.9.6 introduced personal data export and erasure tools (GDPR), but no WP-CLI interface existed for them. This adds a wp user privacy-request command group covering the full lifecycle of user_request posts.

New commands

  • list — Query all requests; filterable by --action-type and --status, supports all standard output formats (table, csv, json, ids, count, yaml)
  • create <email> <action-type> — Create a export_personal_data or remove_personal_data request; --status=pending|confirmed, --send-email, --porcelain
  • delete <request-id>... — Delete one or more requests; batch-reports success/failure counts
  • erase <request-id> — Invoke all registered wp_privacy_personal_data_erasers for the request's email, then mark it request-completed
  • export <request-id> — Invoke all registered wp_privacy_personal_data_exporters, generate the ZIP via wp_privacy_generate_personal_data_export_file(), mark complete, and output the file path
  • complete <request-id>... — Mark one or more requests as request-completed; batch-reports success/failure counts
$ wp user privacy-request create bob@example.com export_personal_data --status=confirmed --porcelain
3
$ wp user privacy-request export 3
Success: Exported personal data to: …/wp-personal-data-exports/wp-personal-data-export-bob-example-com-3.zip

$ wp user privacy-request create bob@example.com remove_personal_data --status=confirmed --porcelain
4
$ wp user privacy-request erase 4
Success: Erased personal data for request 4.

$ wp user privacy-request list --format=csv --fields=ID,user_email,action_name,status
ID,user_email,action_name,status
3,bob@example.com,export_personal_data,request-completed
4,bob@example.com,remove_personal_data,request-completed

Implementation notes

  • erase and export iterate over all registered erasers/exporters page-by-page (matching the admin AJAX flow) before marking the request complete
  • export errors explicitly if wp_privacy_generate_personal_data_export_file() produces no file path
  • wp_delete_user_request() exists since WP 4.9.6 but is absent from the php-stubs/wordpress-stubs library; suppressed with a scoped @phpstan-ignore
  • phpcs.xml.dist updated to include User_Privacy_Request_Command in the existing NamingConventions class-prefix exclusion pattern (consistent with all other command classes)
  • Behat feature file covers create/list/delete/complete/erase/export flows and error cases

Copilot AI linked an issue Apr 22, 2026 that may be closed by this pull request
@github-actions github-actions Bot added command:post Related to 'post' command command:post-create Related to 'post create' command command:post-delete Related to 'post delete' command labels Apr 22, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 22, 2026

Codecov Report

❌ Patch coverage is 82.56881% with 38 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/User_Privacy_Request_Command.php 82.29% 37 Missing ⚠️
entity-command.php 88.88% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI and others added 2 commits April 22, 2026 11:05
Copilot AI changed the title [WIP] Add commands for erasing and exporting personal data Add wp user privacy-request commands for GDPR personal data management Apr 22, 2026
Copilot AI requested a review from swissspidy April 22, 2026 11:08
@swissspidy

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

@swissspidy swissspidy marked this pull request as ready for review April 22, 2026 19:54
@swissspidy swissspidy requested a review from a team as a code owner April 22, 2026 19:54
Copilot AI review requested due to automatic review settings April 22, 2026 19:54

This comment was marked as resolved.

Comment thread src/User_Privacy_Request_Command.php Outdated
Copilot AI requested a review from swissspidy April 22, 2026 20:34
@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

…xport_file_name)

Agent-Logs-Url: https://github.com/wp-cli/entity-command/sessions/76bb4546-13cf-4c5e-90d1-e8679fd9b477

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +233 to +243
$request_id = wp_create_user_request( $email_address, $action_name, [], $status );

if ( is_wp_error( $request_id ) ) {
WP_CLI::error( $request_id );
}

// The $status parameter for wp_create_user_request() was added in WP 5.7.0.
// For older versions, manually update the post status when 'confirmed' was requested.
if ( 'confirmed' === $status ) {
wp_update_post(
[
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

The inline comment says the $status parameter for wp_create_user_request() was added in WP 5.7.0, but the call always passes $status as the 4th argument. If that comment is correct, this will be an incompatible call on WP < 5.7. Consider branching on Utils\wp_version_compare( '5.7', '<' ) (or function_exists/reflection) to call the 3-arg signature on older versions, and only pass $status when supported; alternatively, update/remove the comment if the 4th parameter is actually supported on all targeted versions.

Copilot uses AI. Check for mistakes.
Comment on lines +304 to +306
$result = wp_delete_post( $request_id, true );

if ( ! $result ) {
Copy link

Copilot AI Apr 28, 2026

Choose a reason for hiding this comment

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

The PR description mentions using wp_delete_user_request() (with a scoped @phpstan-ignore) for deleting privacy requests, but the implementation deletes the underlying post via wp_delete_post(). Either update the implementation to use wp_delete_user_request() (to match the stated intent and any extra cleanup it performs) or update the PR description accordingly.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:post Related to 'post' command command:post-create Related to 'post create' command command:post-delete Related to 'post delete' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Commands for erasing and exporting personal data

3 participants