PluginProbe
Age Gate / 3.7.3
Age Gate v3.7.3
3.7.3 trunk 1.0.0 1.0.1 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.10 1.4.11 1.4.12 1.4.13 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 All 113 releases
age-gate / src / Admin / Tools / Reset.php

Reset.php in Age Gate 3.7.3, at src/Admin/Tools/Reset.php

75 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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