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