Privacy: Schedule _wp_personal_data_cleanup_requests() on WP-Cron and fix timezone bug in expiry query#11444
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
| } | ||
|
|
||
| if ( ! wp_next_scheduled( 'wp_privacy_personal_data_cleanup_requests' ) ) { | ||
| wp_schedule_event( time(), 'hourly', 'wp_privacy_personal_data_cleanup_requests' ); |
There was a problem hiding this comment.
What is intention for running the cron every hours?
Trac ticket: https://core.trac.wordpress.org/ticket/44498
What
Adds a WP-Cron schedule for
_wp_personal_data_cleanup_requests()sothat expired, unconfirmed privacy requests are cleaned up automatically
— not only when an admin visits the Export or Erase Personal Data pages.
Also fixes a pre-existing timezone bug in the expiry query that caused
requests to fail immediately on sites in UTC+ timezones.
Changes
wp-includes/functions.php
wp_schedule_personal_data_cleanup_requests()— registers an hourlycron event, matching the pattern of
wp_schedule_delete_old_privacy_export_files().wp_cron_personal_data_cleanup_requests()— cron callback thatrequires
wp-admin/includes/privacy-tools.phpbefore calling_wp_personal_data_cleanup_requests(), since that file is not loadedin a cron request context.
wp-includes/default-filters.php
initand the cron event, followingthe same pattern as the existing export-file cleanup hooks.
wp-admin/includes/privacy-tools.php
date_querycolumn frompost_modified_gmttopost_modified.WP_Date_Query::build_mysql_datetime()resolvesrelative strings like "86400 seconds ago" using the site's local
timezone and returns a local-time string. Comparing that against
post_modified_gmt(UTC) produced the wrong threshold for any sitenot on UTC — immediate failure on UTC+ sites, over-long expiry on
UTC- sites. Using
post_modified(local time) makes both sides ofthe comparison consistent.
Backward compatibility
The direct calls to
_wp_personal_data_cleanup_requests()inexport-personal-data.phpanderase-personal-data.phpare unchangedand continue to serve as a synchronous fallback on admin page visits.
Trac ticket: https://core.trac.wordpress.org/ticket/44498
Use of AI Tools
AI assistance: Yes
Tool(s): Claude
Model(s): Sonnet 4.6
Used for: Code review and manual test suggestions to test extensively; final implementation were reviewed and fully tested by me.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.