models
4 years ago
queries
4 years ago
utils
4 years ago
chart.php
4 years ago
db.php
4 years ago
delete_data_ajax.php
4 years ago
filters.php
4 years ago
filters_ajax.php
4 years ago
rest_api.php
4 years ago
settings.php
4 years ago
settings_ajax.php
4 years ago
super_secret_content_generator.php
4 years ago
table.php
4 years ago
table_referrers.php
4 years ago
table_views.php
4 years ago
track_resource_changes.php
4 years ago
delete_data_ajax.php
44 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP; |
| 4 | |
| 5 | class Delete_Data_Ajax |
| 6 | { |
| 7 | public function __construct() |
| 8 | { |
| 9 | add_action('wp_ajax_iawp_delete_data', [$this, 'delete_data']); |
| 10 | } |
| 11 | |
| 12 | public function delete_data() |
| 13 | { |
| 14 | if (!IAWP()->min_permission_level('admin')) { |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | check_ajax_referer('iawp_delete_data', 'delete_data_nonce'); |
| 19 | |
| 20 | $confirmation = $this->get_field('confirmation'); |
| 21 | $valid = strtolower($confirmation) == 'delete all data'; |
| 22 | |
| 23 | if (!$valid) { |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | (new DB())->wipe_db(); |
| 28 | } |
| 29 | |
| 30 | private function get_field($name) |
| 31 | { |
| 32 | if (!array_key_exists($name, $_POST)) { |
| 33 | return null; |
| 34 | } |
| 35 | $type = gettype($_POST[$name]); |
| 36 | |
| 37 | if ($type == 'array') { |
| 38 | return rest_sanitize_array($_POST[$name]); |
| 39 | } else { |
| 40 | return sanitize_text_field($_POST[$name]); |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 |