0

How can i anonymize any comment after a certain time? Is there a way to do this? It's for data protection.

  • Do you mean just on the front-end or do you want to clear all the user input data (like name/email etc) on the backend as well? As in, the stored data of the comment... – Christine Cooper Mar 28 '18 at 11:46
  • I mean the second one. I want to overwrite the whole user related data. – Aleshanee Mar 28 '18 at 11:47
  • 2
    create an anonymous User. Write a Plug-in using WordPress cron to check comments of all users for creation date + 1year. if that applies move comments to user anonymous – Pat_Morita Mar 28 '18 at 11:53
2

I don't have a ready to use solution. Howeder I think is not to heavy to build a custom plugin, that do that.

  1. Update the comment data, use wp_update_comment().
  2. For anonymize the IP you can use wp_privacy_anonymize_ip() (currently not in core, open as ticket).
  3. Use the wp cron to run this after 6 months and build a comparison with the comment date to anonymize the data of the comment.

Alternative to the wp function to anonymize the IP helps this small function, only an small idea.

function fb_cut_ip( $ip, $cut_end = true )
{
    return str_replace(
        ( $cut_end ? strrchr( $ip, ':' ) : strstr( $ip, ':' ) ),
        '',
        $ip
    );
}
1

Thank you all for your help.

Here is my final solution: It's a PHP-snippet that i paste into a wp cron job plugin.

add_action( 'wp_enqueue_scripts', 'wp_privacy_anonymize_comments' );
function wp_privacy_anonymize_comments() {
  $expiry_date = date("Y-m-d", strtotime("-1 years"));
  $args = array(
    // args here
 );

// The Query
$comments_query = new WP_Comment_Query;
$meta_values = $comments_query->query( $args );

foreach($meta_values as $meta_value) :
    $current_comment_ID =   $meta_value->comment_ID;
    $current_comment_date = $meta_value->comment_date;

    if ($current_comment_date < $expiry_date) {
        //Override Userdata #anonymer-Bär
        $update_comment = array(
            'comment_ID'    => $current_comment_ID,
            'comment_author'=> 'Anonym ' . $current_comment_ID,
            'comment_author_email' => 'anonym@web.de',
            'comment_author_url' => ''
        );
        wp_update_comment($update_comment);
    }
endforeach;
}

Thank you all :) Kind regards, Kathi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.