[wp-trac] [WordPress Trac] #43797: Consent Logging
WordPress Trac
noreply at wordpress.org
Thu Apr 19 09:02:09 UTC 2018
#43797: Consent Logging
-------------------------+------------------------------
Reporter: xkon | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: General | Version:
Severity: normal | Resolution:
Keywords: gdpr | Focuses:
-------------------------+------------------------------
Comment (by xkon):
I've been doing something similar with a website that has custom forms /
cookies etc, so I thought of converting the code a little bit to see if it
would help here at all. I went along the lines of how the requests CPTs
where created for the privacy tools but I'm not sure if there's a
better/clever way to do it for core. I have a custom admin page that lists
all of the consents so the admin can easily who has done what also.
Ofc this might be pretty basic but it has served the websites needs pretty
well until now.
I can add this on the `user.php` that we currently have all of our extra
classes if this is ok for a start so we can check / enhance it better.
{{{#!php
<?php
class WP_Privacy_Consent_Logs {
public function consent_exists( $attr ) {
$args = array(
'post_type' => 'consent_log',
'meta_query' => array(
'relation' => 'AND',
'_user_email' => array(
'key' => '_user_email',
'value' => $attr['email_address'],
),
'city_clause' => array(
'key' => '_consent_identifier',
'value' => $attr['identifier'],
),
),
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
return $query->post->ID;
} else {
return false;
}
}
public function has_consent( $attr ) {
$exists = $this->consent_exists( array(
'email_address' => $attr['email_address'],
'identifier' => $attr['identifier'],
));
if ( $exists ) {
if ( 'yes' === get_post_meta( $exists
,'_consent_status', true ) ) {
return true;
}
} else {
return false;
}
}
public function add_consent( $attr ) {
$exists = $this->consent_exists( array(
'email_address' => $attr['email_address'],
'identifier' => $attr['identifier'],
));
if ( ! $exists ) {
$user_id = 0;
$consent = wp_insert_post( array(
'post_author' => $user_id,
'post_status' => 'publish',
'post_type' => 'consent_log',
'post_date' => current_time( 'mysql',
false ),
'post_date_gmt' => current_time( 'mysql',
true ),
), true );
update_post_meta( $consent, '_user_email',
$attr['email_address'] );
update_post_meta( $consent, '_consent_identifier',
$attr['identifier'] );
update_post_meta( $consent, '_consent_status',
$attr['accepted'] );
return true;
} else {
return false;
}
}
public function remove_consent( $attr ) {
$exists = $this->consent_exists( array(
'email_address' => $attr['email_address'],
'identifier' => $attr['identifier'],
));
if ( $exists ) {
wp_delete_post( $exists );
return true;
} else {
return false;
}
}
public function update_consent( $attr ) {
if ( ! empty( $attr['accepted'] ) ) {
$exists = $this->consent_exists( array(
'email_address' => $attr['email_address'],
'identifier' => $attr['identifier'],
));
if ( $exists ) {
update_post_meta( $exists,
'_consent_status', $attr['accepted'] );
return true;
} else {
return false;
}
}
}
}
}}}
I'm using it this way pretty much:
{{{#!php
<?php
// consent_exists
$consent = new WP_Privacy_Consent_Logs();
$args = array(
'email_address' => 'test at test.test',
'identifier' => 'cookie_form_1',
);
$check = $consent->consent_exists( $args );
if ( $check ) {
error_log( 'exists' );
} else {
error_log( 'exists not' );
}
// has_consent
$consent = new WP_Privacy_Consent_Logs();
$args = array(
'email_address' => 'test at test.test',
'identifier' => 'cookie_form_1',
);
$check = $consent->has_consent( $args );
if ( $check ) {
error_log( 'has' );
} else {
error_log( 'has not' );
}
// add_consent
$consent = new WP_Privacy_Consent_Logs();
$args = array(
'email_address' => 'test at test.test',
'identifier' => 'cookie_form_1',
'accepted' => 'no',
);
$check = $consent->add_consent( $args );
if ( $check ) {
error_log( 'added' );
} else {
error_log( 'not added' );
}
// remove_consent
$consent = new WP_Privacy_Consent_Logs();
$args = array(
'email_address' => 'test at test.test',
'identifier' => 'cookie_form_1',
);
$check = $consent->remove_consent( $args );
if ( $check ) {
error_log( 'removed' );
} else {
error_log( 'not removed' );
}
// update_consent
$consent = new WP_Privacy_Consent_Logs();
$args = array(
'email_address' => 'test at test.test',
'identifier' => 'cookie_form_1',
'accepted' => 'yes',
);
$check = $consent->update_consent( $args );
if ( $check ) {
error_log( 'updated' );
} else {
error_log( 'not updated' );
}
}}}
--
Ticket URL: <https://core.trac.wordpress.org/ticket/43797#comment:5>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list