class-gdpr.php
2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace um\core;
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! class_exists( 'um\core\GDPR' ) ) {
/**
* Class Admin_GDPR
* @package um\core
*/
class GDPR {
/**
* Admin_GDPR constructor.
*/
function __construct() {
add_action( 'um_submit_form_register', array( &$this, 'agreement_validation' ), 9 );
add_filter( 'um_before_save_filter_submitted', array( &$this, 'add_agreement_date' ), 10, 2 );
add_filter( 'um_email_registration_data', array( &$this, 'email_registration_data' ), 10, 1 );
add_action( 'um_after_form_fields', array( &$this, 'display_option' ) );
}
/**
* @param $args
*/
function display_option( $args ) {
if ( isset( $args['use_gdpr'] ) && $args['use_gdpr'] == 1 ) {
$template_path = trailingslashit( get_stylesheet_directory() ). '/ultimate-member/templates/gdpr-register.php';
if ( file_exists( $template_path ) ) {
require $template_path;
} else {
require um_path . 'templates/gdpr-register.php';
}
}
}
/**
* @param $args
*/
function agreement_validation( $args ) {
$gdpr_enabled = get_post_meta( $args['form_id'], '_um_register_use_gdpr', true );
if ( $gdpr_enabled && ! isset( $args['submitted']['use_gdpr_agreement'] ) ) {
UM()->form()->add_error( 'use_gdpr_agreement', isset( $args['use_gdpr_error_text'] ) ? $args['use_gdpr_error_text'] : '' );
}
}
/**
* @param $submitted
* @param $args
*
* @return mixed
*/
function add_agreement_date( $submitted, $args ) {
if ( isset( $submitted['use_gdpr_agreement'] ) ) {
$submitted['use_gdpr_agreement'] = time();
}
return $submitted;
}
/**
* @param $submitted
*
* @return mixed
*/
function email_registration_data( $submitted ) {
if ( ! empty( $submitted['use_gdpr_agreement'] ) ) {
$submitted['GDPR Applied'] = date( "d M Y H:i", $submitted['use_gdpr_agreement'] );
unset( $submitted['use_gdpr_agreement'] );
}
return $submitted;
}
}
}