PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / trunk
JetFormBuilder — Dynamic Blocks Form Builder vtrunk
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 3 weeks ago
update-options.php
101 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 if ( ! current_user_can( 'manage_options' ) ) {
52 return;
53 }
54
55 $fields_map = ! empty( $this->settings['meta_fields_map'] ) ? $this->settings['meta_fields_map'] : array();
56 $options_data = array();
57
58 if ( empty( $this->settings['options_page'] ) ) {
59 return;
60 }
61
62 if ( ! empty( $fields_map ) ) {
63 foreach ( $fields_map as $form_field => $option_field ) {
64 if ( ! empty( $option_field ) && isset( $request[ $form_field ] ) ) {
65 $options_data[ $option_field ] = $request[ $form_field ];
66 }
67 }
68 }
69
70 if ( empty( $options_data ) ) {
71 throw new Action_Exception( 'failed' );
72 }
73
74 $option_name = $this->settings['options_page'];
75
76 $page = isset( jet_engine()->options_pages->registered_pages[ $option_name ] ) ? jet_engine()->options_pages->registered_pages[ $option_name ] : false;
77
78 if ( $page && method_exists( $page, 'update_options' ) ) {
79 $page->update_options( $options_data, false, false );
80 return;
81 }
82
83 $current_value = get_option( $option_name, array() );
84 $new_value = array_merge( $current_value, $options_data );
85
86 update_option( $option_name, $new_value );
87 }
88
89 /**
90 * Regsiter custom action data for the editor
91 *
92 * @return [type] [description]
93 */
94 public function action_data() {
95 return array(
96 'optionsPages' => Tools::with_placeholder( Tools::get_options_pages_for_js() ),
97 );
98 }
99
100 }
101