| 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 |
|