phone-field-handler.php
57 lines
| 1 | <?php |
| 2 | |
| 3 | namespace JFB_Modules\Blocks_V2\Phone_Field\Admin_Tabs; |
| 4 | |
| 5 | use Jet_Form_Builder\Admin\Tabs_Handlers\Base_Handler; |
| 6 | |
| 7 | // If this file is called directly, abort. |
| 8 | if ( ! defined( 'WPINC' ) ) { |
| 9 | die; |
| 10 | } |
| 11 | |
| 12 | /** |
| 13 | * Phone Field Settings Handler |
| 14 | * |
| 15 | * Manages global settings for Phone Field (ipinfo.io API token) |
| 16 | */ |
| 17 | class Phone_Field_Handler extends Base_Handler { |
| 18 | |
| 19 | /** |
| 20 | * Default options |
| 21 | */ |
| 22 | const OPTIONS = array( |
| 23 | 'ipinfo_token' => '', |
| 24 | ); |
| 25 | |
| 26 | /** |
| 27 | * Tab slug |
| 28 | */ |
| 29 | public function slug() { |
| 30 | return 'phone-field-tab'; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Handle POST request to save settings |
| 35 | */ |
| 36 | public function on_get_request() { |
| 37 | // phpcs:disable WordPress.Security.NonceVerification.Missing |
| 38 | $ipinfo_token = sanitize_text_field( wp_unslash( $_POST['ipinfo_token'] ?? '' ) ); |
| 39 | // phpcs:enable WordPress.Security.NonceVerification.Missing |
| 40 | |
| 41 | $result = $this->update_options( |
| 42 | array( |
| 43 | 'ipinfo_token' => $ipinfo_token, |
| 44 | ) |
| 45 | ); |
| 46 | |
| 47 | $this->send_response( $result ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Load options (required by Base_Handler) |
| 52 | */ |
| 53 | public function on_load() { |
| 54 | return $this->get_options( self::OPTIONS ); |
| 55 | } |
| 56 | } |
| 57 |