Site Health Checks for Privacy Settings
Adds Site Health tests that check whether a privacy policy page is published, whether full commenter IP addresses are being stored, and whether the comment cookie consent checkbox is turned on.
Opens WPIDE on
Code
add_filter( 'site_status_tests', function ( $tests ) {
$result = function ( $id, $ok, $good, $bad, $fix ) {
return array(
'label' => $ok ? $good : $bad,
'status' => $ok ? 'good' : 'recommended',
'badge' => array( 'label' => 'Privacy', 'color' => $ok ? 'blue' : 'orange' ),
'description' => '<p>' . esc_html( $ok ? $good . '.' : $fix ) . '</p>',
'test' => $id,
);
};
$tests['direct']['wpide_privacy_page'] = array(
'label' => 'Privacy policy page',
'test' => function () use ( $result ) {
$id = (int) get_option( 'wp_page_for_privacy_policy' );
return $result( 'wpide_privacy_page', $id && 'publish' === get_post_status( $id ), 'A privacy policy page is published', 'No privacy policy page is published', 'Create and publish a privacy policy page, then select it under Settings > Privacy.' );
},
);
$tests['direct']['wpide_comment_ips'] = array(
'label' => 'Commenter IP addresses',
'test' => function () use ( $result ) {
global $wpdb;
$ip = (string) $wpdb->get_var( "SELECT comment_author_IP FROM {$wpdb->comments} WHERE comment_author_IP <> '' ORDER BY comment_ID DESC LIMIT 1" );
$ok = '' === $ip || wp_privacy_anonymize_ip( $ip ) === $ip;
return $result( 'wpide_comment_ips', $ok, 'New comments do not store full IP addresses', 'Full IP addresses are stored with comments', 'Store shortened IP addresses for comments, or none at all, unless your spam protection needs them.' );
},
);
$tests['direct']['wpide_comment_cookies'] = array(
'label' => 'Comment cookie consent',
'test' => function () use ( $result ) {
$ok = ! get_option( 'default_comment_status' ) || 'closed' === get_option( 'default_comment_status' ) || get_option( 'show_comments_cookies_opt_in' );
return $result( 'wpide_comment_cookies', (bool) $ok, 'Commenters are asked before their details are saved in a cookie', 'Comment cookies are set without asking', 'Turn on "Show comments cookies opt-in checkbox" under Settings > Discussion.' );
},
);
return $tests;
} );
Notes
Each result explains how to fix the setting; pair it with the IP shortening and consent snippets.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.