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 / Ajax.php

Ajax.php in Age Gate 3.7.3, at src/Admin/Ajax.php

60 lines 1.6 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;
4
5 use AgeGate\Admin\Controller\ContentController;
6 use Asylum\Utility\Notice;
7 use AgeGate\Admin\Taxonomy\TermHelper;
8 use AgeGate\Common\Immutable\Constants;
9
10 class Ajax
11 {
12 public function __construct()
13 {
14 add_action('wp_ajax_ag_clear_legacy_css', [$this, 'removeLegacyCss']);
15 add_action('wp_ajax_age_gate_store_terms', [$this, 'storeTerms']);
16 }
17
18 public function removeLegacyCss()
19 {
20 $postData = wp_unslash($_POST ?? []);
21
22 $data = [];
23 if (!current_user_can(Constants::ADVANCED) || !wp_verify_nonce($postData['nonce'], 'ag_clear_css' )) {
24 $data['status'] = 'Not allowed';
25 $code = 401;
26 } else {
27 delete_option('age_gate_legacy_css');
28 Notice::add(__('Legacy CSS removed', 'age-gate'), 'success');
29 $data['status'] = 'ok';
30 $code = 200;
31 }
32
33 wp_send_json($data, $code);
34 wp_die();
35 }
36
37 public function storeTerms()
38 {
39 $postData = wp_unslash($_POST ?? []);
40
41 if (!current_user_can( Constants::CONTENT) || !wp_verify_nonce($postData['nonce'], 'age_gate_store_terms')) {
42 wp_send_json_error( [], 401);
43 }
44
45 $options = get_option(ContentController::OPTION, []);
46
47 if ($postData['idx'] == 0) {
48 $options['terms'] = [];
49 }
50
51 $options['terms'] = array_merge($options['terms'] ?? [], $postData['ag_settings'] ?? []);
52
53 update_option(ContentController::OPTION, $options);
54
55 wp_send_json([
56 'terms' => $options['terms'],
57 ]);
58 }
59 }
60