active-campaign-handler.php
4 years ago
base-handler.php
4 years ago
captcha-handler.php
4 years ago
get-response-handler.php
4 years ago
mailchimp-handler.php
4 years ago
payments-gateways-handler.php
4 years ago
paypal-handler.php
4 years ago
tab-handler-manager.php
4 years ago
base-handler.php
91 lines
| 1 | <?php |
| 2 | |
| 3 | |
| 4 | namespace Jet_Form_Builder\Admin\Tabs_Handlers; |
| 5 | |
| 6 | abstract class Base_Handler { |
| 7 | |
| 8 | private $prefix = 'jet_form_builder_settings__'; |
| 9 | |
| 10 | abstract public function slug(); |
| 11 | |
| 12 | abstract public function on_get_request(); |
| 13 | |
| 14 | abstract public function on_load(); |
| 15 | |
| 16 | public function __construct() { |
| 17 | add_action( 'jet-fb/admin-pages/before-assets/jfb-settings', array( $this, 'before_assets' ) ); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Define this, if you want to save options |
| 22 | * in Tab_Handler_Manager::$_tabs_options. |
| 23 | * |
| 24 | * Then you can get this data via |
| 25 | * $this->get_global_options() |
| 26 | * |
| 27 | * @return array |
| 28 | */ |
| 29 | public function save_global_default() { |
| 30 | return array(); |
| 31 | } |
| 32 | |
| 33 | public function is_visible( $advanced_options ) { |
| 34 | return true; |
| 35 | } |
| 36 | |
| 37 | public function get_options( $default = array() ) { |
| 38 | $response = get_option( $this->option_name(), false ); |
| 39 | |
| 40 | $response = $response |
| 41 | ? json_decode( $response, true ) |
| 42 | : array(); |
| 43 | |
| 44 | return array_merge( $default, $response ); |
| 45 | } |
| 46 | |
| 47 | public function update_options( $options ) { |
| 48 | $options = wp_json_encode( $options ); |
| 49 | |
| 50 | return update_option( $this->option_name(), $options ); |
| 51 | } |
| 52 | |
| 53 | public function before_assets() { |
| 54 | } |
| 55 | |
| 56 | public function save_global_options( $default = array() ) { |
| 57 | Tab_Handler_Manager::instance()->save_options_tab( |
| 58 | $this->slug(), |
| 59 | $this->get_options( $default ) |
| 60 | ); |
| 61 | } |
| 62 | |
| 63 | public function get_global_options() { |
| 64 | return Tab_Handler_Manager::instance()->get_options_tab( $this->slug() ); |
| 65 | } |
| 66 | |
| 67 | public function option_name() { |
| 68 | return $this->prefix . $this->slug(); |
| 69 | } |
| 70 | |
| 71 | public function get_success_response_data() { |
| 72 | return array( |
| 73 | 'message' => __( 'Saved successfully!', 'jet-form-builder' ), |
| 74 | ); |
| 75 | } |
| 76 | |
| 77 | public function get_failed_response_data() { |
| 78 | return array( |
| 79 | 'message' => __( 'Unsuccessful save.', 'jet-form-builder' ), |
| 80 | ); |
| 81 | } |
| 82 | |
| 83 | public function send_response( $result ) { |
| 84 | if ( $result ) { |
| 85 | wp_send_json_success( $this->get_success_response_data() ); |
| 86 | } |
| 87 | |
| 88 | wp_send_json_error( $this->get_failed_response_data() ); |
| 89 | } |
| 90 | } |
| 91 |