| 1 |
<?php |
| 2 |
|
| 3 |
namespace AgeGate\Admin\Tools; |
| 4 |
|
| 5 |
use AgeGate\Update\Activate; |
| 6 |
use AgeGate\Common\Admin\Helper; |
| 7 |
use AgeGate\Common\Immutable\Constants as Immutable; |
| 8 |
|
| 9 |
class Reset |
| 10 |
{ |
| 11 |
use Helper; |
| 12 |
|
| 13 |
public const PERMISSION = Immutable::HARD_RESET; |
| 14 |
|
| 15 |
public function __construct() |
| 16 |
{ |
| 17 |
add_action('admin_post_age_gate_reset', [$this, 'resetSettings']); |
| 18 |
add_action('admin_post_age_gate_reset_post', [$this, 'resetPosts']); |
| 19 |
} |
| 20 |
|
| 21 |
private function auth($password) |
| 22 |
{ |
| 23 |
$user = get_user_by('ID', get_current_user_id( )); |
| 24 |
|
| 25 |
return wp_check_password( $password, $user->data->user_pass, get_current_user_id()); |
| 26 |
} |
| 27 |
|
| 28 |
public function resetSettings() |
| 29 |
{ |
| 30 |
$postData = wp_unslash($_POST ?? []); |
| 31 |
|
| 32 |
if (!current_user_can(self::PERMISSION) || !wp_verify_nonce($postData['ag_reset_settings'] ?? '', 'ag_reset_settings')) { |
| 33 |
wp_die('Disallowed action'); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
if (!$this->auth($postData['pwd'])) { |
| 38 |
$this->redirect($postData['_wp_http_referer'], 0, 'tools'); |
| 39 |
} |
| 40 |
|
| 41 |
foreach (Immutable::AGE_GATE_OPTIONS as $option) { |
| 42 |
delete_option($option); |
| 43 |
} |
| 44 |
|
| 45 |
delete_option('age_gate_version'); |
| 46 |
|
| 47 |
Activate::activate(); |
| 48 |
|
| 49 |
$this->redirect($postData['_wp_http_referer'], 1, 'tools'); |
| 50 |
} |
| 51 |
|
| 52 |
public function resetPosts() |
| 53 |
{ |
| 54 |
$postData = wp_unslash($_POST ?? []); |
| 55 |
|
| 56 |
|
| 57 |
if (!current_user_can(self::PERMISSION) || !wp_verify_nonce($postData['ag_reset_post'] ?? '', 'ag_reset_post')) { |
| 58 |
wp_die('Disallowed action'); |
| 59 |
} |
| 60 |
|
| 61 |
if (!$this->auth($postData['pwd'])) { |
| 62 |
$this->redirect($postData['_wp_http_referer'], 0, 'tools'); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
global $wpdb; |
| 67 |
|
| 68 |
$wpdb->query("DELETE FROM {$wpdb->postmeta} WHERE meta_key LIKE '_age_gate-%'"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery |
| 69 |
$wpdb->query("DELETE FROM {$wpdb->termmeta} WHERE meta_key LIKE '_age_gate-%'"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery |
| 70 |
$wpdb->query("DELETE FROM {$wpdb->usermeta} WHERE meta_key LIKE '_age_gate-%'"); // phpcs:ignore WordPress.DB.DirectDatabaseQuery |
| 71 |
|
| 72 |
$this->redirect($postData['_wp_http_referer'], 1, 'tools'); |
| 73 |
} |
| 74 |
} |
| 75 |
|