PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.4.7
JetFormBuilder — Dynamic Blocks Form Builder v3.4.7
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / includes / admin / tabs-handlers / base-handler.php
jetformbuilder / includes / admin / tabs-handlers Last commit date
base-handler.php 2 years ago options-handler.php 2 years ago tab-handler-manager.php 1 year ago
base-handler.php
126 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Admin\Tabs_Handlers;
5
6 // If this file is called directly, abort.
7 use JFB_Components\Repository\Repository_Item_Instance_Trait;
8
9 if ( ! defined( 'WPINC' ) ) {
10 die;
11 }
12
13 abstract class Base_Handler implements Repository_Item_Instance_Trait {
14
15 const PREFIX = 'jet_form_builder_settings__';
16
17 abstract public function slug();
18
19 abstract public function on_get_request();
20
21 abstract public function on_load();
22
23 public function after_install() {
24 add_action( "wp_ajax_jet_fb_save_tab__{$this->slug()}", array( $this, 'on_raw_request' ) );
25 add_action( 'jet-fb/admin-pages/before-assets/jfb-settings', array( $this, 'before_assets' ) );
26 }
27
28 public function on_raw_request() {
29 if (
30 empty( $_POST['_nonce'] ) ||
31 ! wp_verify_nonce( sanitize_key( $_POST['_nonce'] ?? '' ), 'jfb-settings' ) ||
32 ! current_user_can( 'manage_options' )
33 ) {
34 $this->send_response( false );
35
36 return;
37 }
38
39 $this->on_get_request();
40 }
41
42 /**
43 * @return array
44 * @since 3.1.0
45 */
46 public function on_editor_load(): array {
47 return $this->get_options();
48 }
49
50 /**
51 * Define this, if you want to save options
52 * in Tab_Handler_Manager::$_tabs_options.
53 *
54 * Then you can get this data via
55 * $this->get_global_options()
56 *
57 * @return array
58 */
59 public function save_global_default() {
60 return array();
61 }
62
63 public function is_visible( $advanced_options ) {
64 return true;
65 }
66
67 public function get_options( $if_empty = array() ) {
68 $response = get_option( $this->option_name(), false );
69
70 $response = $response
71 ? json_decode( $response, true )
72 : array();
73
74 return array_merge( $if_empty, $response );
75 }
76
77 public function update_options( $options ) {
78 $json_options = wp_json_encode( $options );
79 $prev_value = get_option( $this->option_name(), false );
80
81 if ( $prev_value === $json_options ) {
82 return true;
83 }
84
85 $prev_options = json_decode( $prev_value, true ) ?: array();
86
87 return update_option(
88 $this->option_name(),
89 wp_json_encode( array_merge( $prev_options, $options ) ),
90 false
91 );
92 }
93
94 public function before_assets() {
95 }
96
97 public function option_name() {
98 return self::PREFIX . $this->slug();
99 }
100
101 public function get_success_response_data() {
102 return array(
103 'message' => __( 'Saved successfully!', 'jet-form-builder' ),
104 );
105 }
106
107 public function get_failed_response_data() {
108 return array(
109 'message' => __( 'Unsuccessful save.', 'jet-form-builder' ),
110 );
111 }
112
113 public function send_response( $result ) {
114 if ( $result ) {
115 wp_send_json_success( $this->get_success_response_data() );
116 }
117
118 wp_send_json_error( $this->get_failed_response_data() );
119 }
120
121 public function rep_item_id() {
122 return $this->slug();
123 }
124
125 }
126