-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathGdprMain.php
113 lines (90 loc) · 3.22 KB
/
GdprMain.php
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* GDPR interface
*
* @package GDPR Interface
* @author Jesper V Nielsen
*
* Plugin Name: GDPR for WP
* Plugin URI: http://github.com
* Description: This provides an interface for other developers to use, and implement in their code.
* Version: 1.0
* Author: Peytz & Co (Kåre Mulvad Steffensen, Jesper V Nielsen, Stephan Victor Schønbeck & others)
* Author URI: http://peytz.dk/medarbejdere/
* GitHub Plugin URI: http://github.com
*/
require_once( 'includes/GdprDataContainer.php' );
class GdprMain extends GdprDataContainer {
private static $plugin_path;
public static function instance() {
static $inst = null;
if ( $inst === null ) {
$inst = new GdprMain();
}
return $inst;
}
public function __construct() {
require_once( 'includes/API/GdprApiBootstrap.php' );
require_once( 'includes/GdprToolbox.php' );
require_once( 'includes/Enqueue.php' );
require_once( 'includes/AdminSettings.php' );
// Uncomment to see the magic happen
add_action( 'admin_init', [ $this, 'run' ] );
}
public static function get_plugin_url() {
return untrailingslashit( plugins_url( '/', __FILE__ ) );
}
public static function get_plugin_path() {
if ( empty( self::$plugin_path ) ) {
self::$plugin_path = untrailingslashit( plugin_dir_path( __FILE__ ) );
}
return self::$plugin_path;
}
public static function get_assets_path() {
return self::get_plugin_url() . '/assets';
}
public static function get_js_path() {
return self::get_assets_path() . '/js';
}
public static function get_views_path( $template_name ) {
return self::get_plugin_path() . '/views/' . $template_name;
}
public static function get_view( $template_name, $vars = [] ) {
include self::get_views_path( $template_name );
}
public function run() {
$email = '[email protected]';
do_action( 'gdpr_init', new GdprToolbox( $email ) );
// Call GdprDataContainer::Instance() to see data
//TO TEST / DEBUG:
//check if GDPR is set as parameter, then make a var_dump and kill site.
//http://yoursite.com/wp-admin/?debug-gdpr
if ( isset( $_GET['debug-gdpr'] ) ) {
print '<pre>';
var_dump( GdprDataContainer::Instance() );
print '</pre>';
/**
* This is an example of how callacks can be used.
* The plugin registeres the callbacks there should be run when anonymize is run.
* This part will be implemented in ajax calls, so each callback gets its own request, while maintaining a structuere for plugin developers,
* to register all data, in one function.
*/
$gdpr = GdprDataContainer::Instance();
foreach ( $gdpr->get_data() as $plugin_data ) {
foreach ( $plugin_data->get_anonymize_cb() as $callback ) {
if ( ! is_callable( $callback ) ) {
continue;
}
//This will be run in a seperatly ajax request.
call_user_func_array( $callback, [ $plugin_data ] );
// if the plugin developer updates the $gdpr object ($plugin_data) with the corresponding functions, such as $gdpr->set_field() (or other functions), we can then find the updated date our GdprDataContainer
print '<pre>';
var_dump( GdprDataContainer::Instance() );
print '</pre>';
}
}
wp_die();
}
}
}
$gdpr_main = GdprMain::instance();