Wp privacy personal data

From Lonsdale201/wp-agent-skills · View interactive version

Wp privacy personal data is an AI agent skill from the GitHub repository Lonsdale201/wp-agent-skills. Implement or audit WordPress plugin privacy integration with privacy-policy suggestions, personal-data exporters, and personal-data erasers. Covers wp_add_privacy_policy_content, wp_privacy_personal_data_exporters, wp_privacy_personal_data_erasers, paged callback contracts, retained-data messages, i

How to use this skill

Skill file

WordPress Personal Data Privacy Integration

Use WordPress' Privacy tools so an administrator can export and erase data

owned by a plugin from Tools > Export Personal Data and Tools > Erase Personal

Data. This is an engineering contract, not legal advice or a claim of GDPR

compliance.

Start with a data inventory

Before writing callbacks, trace every personal-data store and transfer:

Exporters and erasers must cover the same inventory. Do not assume deleting a

WP_User removes plugin tables, files, remote copies, or denormalized logs.

Verify the collection boundary

Capture personal data only after the host workflow has established that the

submission or business event is valid. Early hooks such as

rest_request_before_callbacks and priority-zero wp_ajax_nopriv_* observers

run before the target plugin's permission callback or action callback, including

its callback-level nonce, spam, business validation, and success logic. The REST

filter runs after core authentication and registered argument validation, but it

can still persist data from requests the endpoint later rejects.

Prefer the integration's documented post-success hook and verify the exact

form/list/action plus consent/feature state. Sanitization does not turn a failed

submission into a valid collection event. Test invalid, spam, unauthorized, and

downstream-failure paths and assert that they create no durable profile data.

Suggest privacy-policy text

Register factual, conditional text from admin_init. Describe what is

collected, why, retention, recipients, and user choices. Do not paste a legal

guarantee or silently edit the site's published policy.

add_action( 'admin_init', static function (): void {
    wp_add_privacy_policy_content(
        __( 'My Plugin', 'myplugin' ),
        wp_kses_post(
            '<p class="privacy-policy-tutorial">' .
            __( 'Suggested text: describe the data this plugin actually stores and sends.', 'myplugin' ) .
            '</p>'
        )
    );
} );

Keep the suggestion synchronized with feature flags. If telemetry or a remote

integration is optional, say when it is active and what leaves the site.

Register a personal-data exporter

The filter receives all exporters. Add a stable, plugin-prefixed key and return

the array. The callback accepts an email and a 1-based page number.

add_filter( 'wp_privacy_personal_data_exporters', static function ( array $exporters ): array {
    $exporters['myplugin-submissions'] = array(
        'exporter_friendly_name' => __( 'My Plugin submissions', 'myplugin' ),
        'callback'               => 'myplugin_export_personal_data',
    );
    return $exporters;
} );

function myplugin_export_personal_data( string $email, int $page = 1 ): array {
    $per_page = 100;
    $page     = max( 1, $page );
    $rows     = MyPlugin_Submission_Repository::find_by_email(
        sanitize_email( $email ),
        $per_page,
        ( $page - 1 ) * $per_page
    );
    $data = array();

    foreach ( $rows as $row ) {
        $data[] = array(
            'group_id'          => 'myplugin-submissions',
            'group_label'       => __( 'Form submissions', 'myplugin' ),
            'group_description' => __( 'Submissions stored by My Plugin.', 'myplugin' ),
            'item_id'           => 'submission-' . (int) $row->id,
            'data'              => array(
                array( 'name' => __( 'Email', 'myplugin' ), 'value' => (string) $row->email ),
                array( 'name' => __( 'Message', 'myplugin' ), 'value' => (string) $row->message ),
                array( 'name' => __( 'Created', 'myplugin' ), 'value' => (string) $row->created_at_gmt ),
            ),
        );
    }

    return array(
        'data' => $data,
        'done' => count( $rows ) < $per_page,
    );
}

Rules:

Register a personal-data eraser

add_filter( 'wp_privacy_personal_data_erasers', static function ( array $erasers ): array {
    $erasers['myplugin-submissions'] = array(
        'eraser_friendly_name' => __( 'My Plugin submissions', 'myplugin' ),
        'callback'             => 'myplugin_erase_personal_data',
    );
    return $erasers;
} );

function myplugin_erase_personal_data( string $email, int $page = 1 ): array {
    $result = MyPlugin_Submission_Repository::anonymize_next_batch(
        sanitize_email( $email ),
        100
    );

    return array(
        'items_removed'  => $result->changed > 0,
        'items_retained' => $result->retained > 0,
        'messages'       => array_map( 'sanitize_text_field', $result->messages ),
        'done'           => ! $result->has_more,
    );
}

The eraser response must contain all four keys. items_removed also covers

successful anonymization. items_retained means personal data was found but

kept; explain why in messages without leaking the retained data itself.

Erasure design rules

links and remove direct identifiers that are not required.

irreversibly detach crosswalk/profile rows keyed by user ID, email, cookie ID,

session ID, device fingerprint, order/customer ID, captcha/consent token, or

deterministic hash. An anonymized entity is still identifiable when a

secondary table can attach the same browser/account again on its next visit.

data-producing integration. A hand-written generic PII list easily misses

namespaces such as form_email or provider-specific address fields.

as they are erased: page 2 can skip records. Re-query the next first batch,

or use a stable cursor/processed marker and calculate has_more explicitly.

clear message; never claim complete erasure when one controlled store failed.

privacy request UI owns confirmation, capabilities, and nonces.

Retention and lifecycle

Privacy erasure, uninstall, and routine retention are different operations:

uninstall policy says so; it is not a substitute for subject erasure.

WordPress 7.1 schedules wp_privacy_personal_data_cleanup_requests daily. Core

marks expired request-pending user_request posts as request-failed and

clears their confirmation key; it does not delete completed requests or

plugin-owned personal data. Expiry follows user_request_key_expiration

(normally one day), and the cleanup compares the site-local post_modified

column because the relative date is evaluated in the site timezone.

Do not duplicate this cron event or treat it as a plugin retention engine.

WP-Cron is traffic-dependent, so operationally critical retention still needs

monitoring and a safe idempotent catch-up path. If filtering

user_request_key_expiration, test confirmation links and scheduled cleanup

together; the filter changes both sides of the lifecycle.

Do not keep personal data in autoloaded options or permanent transients. Give

temporary exports/logs an expiry and cleanup path. Backups are usually managed

outside plugin callbacks; document their retention instead of pretending the

plugin erased them synchronously.

Multisite and tests

Decide whether data belongs to one site, network tables, or both. Core runs a

site's registered callbacks in that site's context; do not silently iterate an

entire network without network authorization and a documented contract.

Test at least:

  1. no matching data;
  2. one row and more than one full batch;
  3. registered user plus guest records sharing the email;
  4. retained and partially failed records;
  5. repeated erasure calls;
  6. multisite scope and deleted-user records;
  7. export output for accidental secrets/internal fields;
  8. every integration-specific PII namespace and every profile/crosswalk type;
  9. failed/spam/unauthorized submissions create no durable data;
  10. a post-erasure request with the old cookie/fingerprint cannot reattach the

anonymized entity.

Critical rules

not just direct fields on the primary entity.

personal-data erasure.

Cross-references

Core references

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.