PluginProbe
JetFormBuilder — Dynamic Blocks Form Builder / 3.6.5.2
JetFormBuilder — Dynamic Blocks Form Builder v3.6.5.2
3.6.5.2 3.6.5.1 3.6.5 3.6.4.2 3.6.4.1 3.6.4 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 All 130 releases
jetformbuilder / compatibility / jet-engine / actions / update-options.php
update-options.php
101 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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