[wp-trac] [WordPress Trac] #43545: Helper functions: Anonymizing data in a standardized way
WordPress Trac
noreply at wordpress.org
Fri Mar 16 12:58:21 UTC 2018
#43545: Helper functions: Anonymizing data in a standardized way
--------------------------------+------------------------------
Reporter: dejliglama | Owner:
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Options, Meta APIs | Version: trunk
Severity: normal | Resolution:
Keywords: needs-patch gdpr | Focuses:
--------------------------------+------------------------------
Comment (by jesperher):
We could do something like this:
{{{#!php
<?php
function wp_privacy_anonymize_data( $data_to_anonymize = '', $type =
'text' ) {
switch ( $type ) {
case 'email':
$data_to_anonymize = ...
break
...
...
}
return $data_to_anonymize;
}
}}}
That would mean we could expand it with multiple types, and also allow
filtering on the data to be returned.
fx:
{{{#!php
<?php
/**
* Anonymizes data for the GDPR "Right to Anonymization".
*
* @since 5.0.0
*
* @param string $data_to_anonymize.
* @param string $type the type of the data to be anonymized.
*
* @return string $data_to_anonymize as anonymized.
*/
function wp_privacy_anonymize_data( $data_to_anonymize = '', $type =
'text' ) {
if( ! $data_to_anonymize) {
return false;
}
$type = trim( strtolower( $type ) );
$orginal_data_to_anonymize = $data_to_anonymize;
switch ( $type ) {
case 'id':
// should we ever make something to do this?
break;
case 'email':
/* translators: IP to anonymize */
$data_to_anonymize = __('anonymized-email') . '-'
. wp_hash( $data_to_anonymize ) .'@example.com';
break;
case 'url':
/* translators: url to anonymize */
$data_to_anonymize = __('example at example.com');
break;
case 'ip':
/* translators: IP to anonymize */
$data_to_anonymize = __('0.0.0.0');
break;
case 'agent':
break;
case 'float':
break;
case 'number':
case 'int':
return
break;
case 'date':
//should we ever make something to do this? - can
dates be personal?
break;
case 'name':
break;
case 'text':
/* translators: text to anonymize */
$data_to_anonymize = __('anonymized-text');
break;
case 'shorttext':
/* translators: shorttext to anonymize */
$data_to_anonymize = __('anonymized-text. This
text has been deleted on request of the person who wrote it.');
break;
case 'longtext':
/* translators: longtext to anonymize */
$data_to_anonymize = __('anonymized-text. This
text has been deleted on request of the person who wrote it. This text has
been deleted on request of the person who wrote it. This text has been
deleted on request of the person who wrote it. This text has been deleted
on request of the person who wrote it. This text has been deleted on
request of the person who wrote it. This text has been deleted on request
of the person who wrote it.');
break;
default:
//keep this empty to allow filtering for other
types
break;
}
// allow for others to filter data_to_anonymize
$data_to_anonymize = apply_filters( 'wp_privacy_anonymize_data',
$data_to_anonymize, $type, $orginal_data_to_anonymize );
// allow for others to filter data_to_anonymize specific for type
$data_to_anonymize = apply_filters(
"wp_privacy_anonymize_data_{$type}", $data_to_anonymize, $type,
$orginal_data_to_anonymize );
return $data_to_anonymize;
}
}}}
Then we could create small helper functions fx:
{{{#!php
<?php
function wp_privacy_anonymize_ip( $ip_to_anonymize ) {
return wp_privacy_anonymize_data( $ip_to_anonymize, 'ip' );
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43545#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list