ColumnRequest
5 years ago
ListScreen
5 years ago
Middleware
5 years ago
AjaxColumnRequest.php
5 years ago
AjaxColumnValue.php
5 years ago
AjaxRequestCustomFieldKeys.php
5 years ago
AjaxScreenOptions.php
5 years ago
ColumnRequest.php
5 years ago
DefaultColumns.php
5 years ago
ListScreenRestoreColumns.php
5 years ago
RedirectAddonStatus.php
5 years ago
RestoreSettingsRequest.php
5 years ago
TableListScreenSetter.php
5 years ago
AjaxScreenOptions.php
45 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Controller; |
| 4 | |
| 5 | use AC\Admin\Preference\ScreenOptions; |
| 6 | use AC\Ajax; |
| 7 | use AC\Registrable; |
| 8 | |
| 9 | class AjaxScreenOptions implements Registrable { |
| 10 | |
| 11 | /** |
| 12 | * @var ScreenOptions |
| 13 | */ |
| 14 | private $preference; |
| 15 | |
| 16 | public function __construct( ScreenOptions $preference ) { |
| 17 | $this->preference = $preference; |
| 18 | } |
| 19 | |
| 20 | public function register() { |
| 21 | $this->get_ajax_handler()->register(); |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * @return Ajax\Handler |
| 26 | */ |
| 27 | private function get_ajax_handler() { |
| 28 | $handler = new Ajax\Handler(); |
| 29 | $handler |
| 30 | ->set_action( 'ac_admin_screen_options' ) |
| 31 | ->set_callback( [ $this, 'handle_ajax_request' ] ); |
| 32 | |
| 33 | return $handler; |
| 34 | } |
| 35 | |
| 36 | public function handle_ajax_request() { |
| 37 | $this->get_ajax_handler()->verify_request(); |
| 38 | |
| 39 | $name = filter_input( INPUT_POST, 'option_name', FILTER_SANITIZE_STRING ); |
| 40 | $value = (int) filter_input( INPUT_POST, 'option_value', FILTER_SANITIZE_NUMBER_INT ); |
| 41 | |
| 42 | $this->preference->set( $name, $value ); |
| 43 | } |
| 44 | |
| 45 | } |