Halloween Sale 15% off Ends in See the plans
PHP

Warn About Privacy Requests Close to the 30-Day Deadline

Shows a dashboard notice to administrators when a personal data request has been waiting for more than 25 days, since GDPR expects an answer within one month.

Don’t have WPIDE yet? Install it on your site

Code

// Warn when a request is older than this many days.
$wpide_request_warn_days = 25;

add_action( 'admin_notices', function () use ( $wpide_request_warn_days ) {
    global $wpdb;

    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }

    $late = get_transient( 'wpide_late_privacy_requests' );

    if ( false === $late ) {
        $late = (int) $wpdb->get_var( $wpdb->prepare(
            "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_type = 'user_request' AND post_status IN ('request-pending','request-confirmed') AND post_date_gmt < %s",
            gmdate( 'Y-m-d H:i:s', time() - $wpide_request_warn_days * DAY_IN_SECONDS )
        ) );
        set_transient( 'wpide_late_privacy_requests', $late, HOUR_IN_SECONDS );
    }

    if ( $late ) {
        printf(
            '<div class="notice notice-error"><p>%s <a href="%s">Export requests</a> | <a href="%s">Erasure requests</a></p></div>',
            esc_html( sprintf( '%d personal data request(s) have been open for more than %d days.', $late, $wpide_request_warn_days ) ),
            esc_url( admin_url( 'export-personal-data.php' ) ),
            esc_url( admin_url( 'erase-personal-data.php' ) )
        );
    }
} );

Notes

Change $wpide_request_warn_days to warn earlier; the check is cached for an hour.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.