options-handler.php
50 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Admin\Tabs_Handlers; |
| 5 | |
| 6 | // If this file is called directly, abort. |
| 7 | if ( ! defined( 'WPINC' ) ) { |
| 8 | die; |
| 9 | } |
| 10 | |
| 11 | class Options_Handler extends Base_Handler { |
| 12 | |
| 13 | const OPTIONS = array( |
| 14 | 'enable_dev_mode' => false, |
| 15 | 'clear_on_uninstall' => false, |
| 16 | 'disable_next_button' => true, |
| 17 | 'scroll_on_next' => false, |
| 18 | 'auto_focus' => false, |
| 19 | ); |
| 20 | |
| 21 | public function slug() { |
| 22 | return 'options-tab'; |
| 23 | } |
| 24 | |
| 25 | public function on_get_request() { |
| 26 | $options = array(); |
| 27 | |
| 28 | // phpcs:disable WordPress.Security.NonceVerification.Missing |
| 29 | foreach ( self::OPTIONS as $name => $default ) { |
| 30 | if ( ! array_key_exists( $name, $_POST ) ) { |
| 31 | continue; |
| 32 | } |
| 33 | |
| 34 | $options[ $name ] = filter_var( |
| 35 | sanitize_key( $_POST[ $name ] ), |
| 36 | defined( 'FILTER_VALIDATE_BOOL' ) ? FILTER_VALIDATE_BOOL : FILTER_VALIDATE_BOOLEAN |
| 37 | ); |
| 38 | |
| 39 | } |
| 40 | // phpcs:enable WordPress.Security.NonceVerification.Missing |
| 41 | |
| 42 | $result = $this->update_options( $options ); |
| 43 | $this->send_response( $result ); |
| 44 | } |
| 45 | |
| 46 | public function on_load() { |
| 47 | return $this->get_options(); |
| 48 | } |
| 49 | } |
| 50 |