-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathAjaxScreenOptions.php
44 lines (32 loc) · 998 Bytes
/
AjaxScreenOptions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
namespace AC\Controller;
use AC\Admin\Preference\ScreenOptions;
use AC\Ajax;
use AC\Registerable;
class AjaxScreenOptions implements Registerable
{
private $preference;
public function __construct(ScreenOptions $preference)
{
$this->preference = $preference;
}
public function register(): void
{
$this->get_ajax_handler()->register();
}
private function get_ajax_handler(): Ajax\Handler
{
$handler = new Ajax\Handler();
$handler
->set_action('ac_admin_screen_options')
->set_callback([$this, 'handle_ajax_request']);
return $handler;
}
public function handle_ajax_request()
{
$this->get_ajax_handler()->verify_request();
$name = filter_input(INPUT_POST, 'option_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
$value = (int)filter_input(INPUT_POST, 'option_value', FILTER_SANITIZE_NUMBER_INT);
$this->preference->set($name, $value);
}
}