PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.1.6
JetFormBuilder — Dynamic Blocks Form Builder v3.1.6
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 / compatibility / jet-engine / actions / update-options.php
jetformbuilder / compatibility / jet-engine / actions Last commit date
update-options.php 2 years ago
update-options.php
97 lines
1 <?php
2
3 namespace JFB_Compatibility\Jet_Engine\Actions;
4
5 use Jet_Form_Builder\Actions\Action_Handler;
6 use Jet_Form_Builder\Actions\Types\Base;
7 use Jet_Form_Builder\Classes\Tools;
8 use Jet_Form_Builder\Exceptions\Action_Exception;
9
10 // If this file is called directly, abort.
11 if ( ! defined( 'WPINC' ) ) {
12 die;
13 }
14
15 /**
16 * Define Base_Type class
17 */
18 class Update_Options extends Base {
19
20 public function get_name() {
21 return __( 'Update Options', 'jet-form-builder' );
22 }
23
24 public function get_id() {
25 return 'update_options';
26 }
27
28 public function action_attributes() {
29 return array(
30 'meta_fields_map' => array(
31 'default' => array(),
32 ),
33 'options_page' => array(
34 'default' => '',
35 ),
36 );
37 }
38
39 public function self_script_name() {
40 return 'jetFormUpdateOptionsData';
41 }
42
43 public function editor_labels() {
44 return array(
45 'options_page' => __( 'Options Page:', 'jet-form-builder' ),
46 'options_map' => __( 'Options Map:', 'jet-form-builder' ),
47 );
48 }
49
50 public function do_action( array $request, Action_Handler $handler ) {
51 $fields_map = ! empty( $this->settings['meta_fields_map'] ) ? $this->settings['meta_fields_map'] : array();
52 $options_data = array();
53
54 if ( empty( $this->settings['options_page'] ) ) {
55 return;
56 }
57
58 if ( ! empty( $fields_map ) ) {
59 foreach ( $fields_map as $form_field => $option_field ) {
60 if ( ! empty( $option_field ) && isset( $request[ $form_field ] ) ) {
61 $options_data[ $option_field ] = $request[ $form_field ];
62 }
63 }
64 }
65
66 if ( empty( $options_data ) ) {
67 throw new Action_Exception( 'failed' );
68 }
69
70 $option_name = $this->settings['options_page'];
71
72 $page = isset( jet_engine()->options_pages->registered_pages[ $option_name ] ) ? jet_engine()->options_pages->registered_pages[ $option_name ] : false;
73
74 if ( $page && method_exists( $page, 'update_options' ) ) {
75 $page->update_options( $options_data, false, false );
76 return;
77 }
78
79 $current_value = get_option( $option_name, array() );
80 $new_value = array_merge( $current_value, $options_data );
81
82 update_option( $option_name, $new_value );
83 }
84
85 /**
86 * Regsiter custom action data for the editor
87 *
88 * @return [type] [description]
89 */
90 public function action_data() {
91 return array(
92 'optionsPages' => Tools::with_placeholder( Tools::get_options_pages_for_js() ),
93 );
94 }
95
96 }
97