PluginProbe
The GDPR Framework By Data443 / 2.1.0
The GDPR Framework By Data443 v2.1.0
2.5.0 2.4.0 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.3 1.0.33 1.0.34 1.0.35 1.0.36 1.0.37 1.0.39 1.0.4 1.0.40 1.0.41 1.0.42 1.0.43 1.0.44 1.0.45 1.0.46 All 41 releases
gdpr-framework / src / Admin / WordpressAdmin.php

WordpressAdmin.php in The GDPR Framework By Data443 2.1.0, at src/Admin/WordpressAdmin.php

188 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Codelight\GDPR\Admin;
4
5 /**
6 * Handles general admin functionality
7 *
8 * Class WordpressAdmin
9 *
10 * @package Codelight\GDPR\Admin
11 */
12 class WordpressAdmin
13 {
14 protected $adminPage;
15
16 public function __construct(WordpressAdminPage $adminPage)
17 {
18 $this->adminPage = $adminPage;
19
20 // Allow turning off helpers
21 if (apply_filters('gdpr/admin/helpers/enabled', true)) {
22 new AdminHelper();
23 }
24
25 $this->setup();
26
27 }
28
29 /**
30 * Set up hooks
31 */
32 protected function setup()
33 {
34 // Register the main GDPR options page
35 add_action('admin_menu', [$this, 'registerGDPROptionsPage']);
36
37 // Register General admin tab
38 add_filter('gdpr/admin/tabs', [$this, 'registerAdminTabGeneral'], 0);
39
40 // Enqueue assets
41 add_action('admin_enqueue_scripts', [$this, 'enqueue']);
42
43 // Register post states
44 add_filter('display_post_states', [$this, 'registerPostStates'], 10, 2);
45
46 // Show help notice
47 add_action('current_screen', [$this, 'maybeShowHelpNotice'], 999);
48
49 //
50 add_action( 'delete_user', [$this, 'gdprf_delete_userlogs']);
51 }
52
53
54 public function maybeShowHelpNotice()
55 {
56 if ('tools_page_privacy' === get_current_screen()->base) {
57 //gdpr('admin-notice')->add('admin/notices/help');
58 }
59 }
60
61 /**
62 * Register the GDPR options page in WP admin
63 */
64 public function registerGDPROptionsPage()
65 {
66 add_management_page(
67 _x('Privacy & GDPR Settings', '(Admin)', 'gdpr-framework'),
68 _x('Data443 GDPR', '(Admin)', 'gdpr-framework'),
69 'manage_options',
70 'privacy',
71 [$this->adminPage, 'renderPage']
72 );
73 }
74
75 /**
76 * Register General admin tab
77 *
78 * @param $tabs
79 * @return array
80 */
81 public function registerAdminTabGeneral($tabs)
82 {
83 global $gdpr;
84 $tabs['general'] = $gdpr->AdminTabGeneral;
85
86 return $tabs;
87 }
88
89 /**
90 * Enqueue all admin scripts and styles
91 */
92 public function enqueue()
93 {
94 global $gdpr;
95 /**
96 * General admin styles
97 */
98 wp_enqueue_style(
99 'gdpr-admin',
100 $gdpr->PluginUrl . 'assets/gdpr-admin.css'
101 );
102
103
104 $screen = get_current_screen();
105 if($screen->base=='tools_page_privacy'){
106
107 /**
108 * jQuery UI dialog for modals
109 */
110 wp_enqueue_style('wp-jquery-ui-dialog');
111 wp_enqueue_script(
112 'gdpr-admin',
113 $gdpr->PluginUrl . 'assets/gdpr-admin.js',
114 ['jquery-ui-dialog']
115 );
116
117 /**
118 * jQuery Repeater
119 */
120 wp_enqueue_script(
121 'jquery-repeater',
122 $gdpr->PluginUrl . 'assets/jquery.repeater.min.js',
123 ['jquery']
124 );
125
126 /**
127 * Select2
128 */
129
130 wp_dequeue_script( 'select2css' );
131 wp_dequeue_script( 'select2' );
132
133 wp_enqueue_style(
134 'select2css',
135 $gdpr->PluginUrl . 'assets/select2-4.0.5.css'
136 );
137
138 wp_enqueue_script(
139 'select2',
140 $gdpr->PluginUrl . 'assets/select2-4.0.3.js',
141 ['jquery']
142 );
143
144 wp_enqueue_script(
145 'conditional-show',
146 $gdpr->PluginUrl . 'assets/conditional-show.js',
147 ['jquery']
148 );
149 /**
150 * Color Picker
151 */
152 wp_enqueue_script( 'iris',$gdpr->PluginUrl .'assets/iris.min.js' );
153 wp_enqueue_script( 'iris-init',$gdpr->PluginUrl .'assets/iris-init.js' );
154 }
155 }
156
157 /**
158 * Add a new Post State for our super important system pages
159 */
160 public function registerPostStates($postStates, $post)
161 {
162 global $gdpr;
163 if ($gdpr->Options->get('policy_page') == $post->ID) {
164 $postStates['gdpr_policy_page'] = _x('Privacy Policy Page', '(Admin)', 'gdpr-framework');
165 }
166
167 if ($gdpr->Options->get('tools_page') == $post->ID) {
168 $postStates['gdpr_tools_page'] = _x('Privacy Tools Page', '(Admin)', 'gdpr-framework');
169 }
170
171 return $postStates;
172 }
173 //Delete userlogs if user deleted from admin panel.
174 public function gdprf_delete_userlogs($user_id)
175 {
176 global $wpdb;
177
178 $this->logtableName = $wpdb->prefix . 'gdpr_userlogs';
179
180 return $wpdb->delete(
181 $this->logtableName,
182 [
183 'user_id' => $user_id,
184 ]
185 );
186 }
187
188 }