PluginProbe
weForms – Easy Drag & Drop Contact Form Builder For WordPress / 1.4.1
weForms – Easy Drag & Drop Contact Form Builder For WordPress v1.4.1
1.6.7 1.6.8 1.6.9 1.6.12 1.6.13 1.6.14 1.6.15 1.6.16 1.6.17 1.6.18 1.6.19 1.6.2 1.6.20 1.6.21 1.6.22 1.6.23 1.6.24 1.6.25 1.6.26 1.6.27 1.6.28 1.6.3 1.6.4 1.6.5 1.6.6 All 74 releases
weforms / includes / api / class-weforms-settings-controller.php

class-weforms-settings-controller.php in weForms – Easy Drag & Drop Contact Form Builder For WordPress 1.4.1, at includes/api/class-weforms-settings-controller.php

153 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Settings manager class
5 *
6 * @since 1.4.2
7 */
8
9 class Weforms_Setting_Controller extends Weforms_REST_Controller {
10
11 /**
12 * Endpoint namespace
13 *
14 * @var string
15 */
16 protected $namespace = 'weforms/v1';
17
18 /**
19 * Route name
20 *
21 * @var string
22 */
23 protected $rest_base = 'settings';
24
25 /**
26 * @var array
27 */
28 protected $defaults = array(
29 'email_gateway' => '',
30 'gateways' => '',
31 'recaptcha' => '',
32 'gmap_api' => '',
33 'credit' => ''
34 );
35
36 public function register_routes() {
37
38 register_rest_route( $this->namespace, '/' . $this->rest_base, array(
39
40 array(
41 'methods' => WP_REST_Server::READABLE,
42 'callback' => array( $this, 'get_items' ),
43 'permission_callback' => array( $this, 'get_item_permissions_check' ),
44 'args' => array(
45 'context' => $this->get_context_param( [ 'default' => 'view' ] )
46 ),
47 ),
48 array(
49 'methods' => WP_REST_Server::CREATABLE,
50 'callback' => array( $this, 'create_item' ),
51 'permission_callback' => array( $this, 'create_item_permissions_check' ),
52 'args' => array(
53 'credit' => array(
54 'required' => false,
55 'type' => 'boolean',
56 'description' => __( 'Weforms Setting', 'weforms' ),
57 ),
58 )
59 ),
60 ) );
61
62 }
63
64 /**
65 * Retrieves a collection of forms.
66 *
67 * @since 1.4.2
68 *
69 * @param WP_REST_Request $request Full details about the request.
70 *
71 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
72 **/
73 public function get_items( $request ) {
74 $settings = weforms_get_settings();
75
76 // checking to prevent js error, will be removed in future
77 if ( ! isset( $settings['credit'] ) ) {
78 $settings['credit'] = false;
79 }
80
81 if ( ! isset( $settings['permission'] ) ) {
82 $settings['permission'] = 'manage_options';
83 }
84
85 $settings = $this->prepare_response_for_collection( $settings );
86 $response = rest_ensure_response( $settings );
87
88 return $response;
89
90 }
91
92 /**
93 * Creates a single form
94 *
95 * @param WP_REST_Request $request Full details about the request.
96 *
97 * @since 1.4.2
98 *
99 * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure.
100 **/
101 public function create_item( $request ) {
102 $req_settings = $request->get_params();
103 $settings = get_option( 'weforms_settings' );
104
105 foreach ( $settings as $key => $setting ) {
106 if( array_key_exists( $key, $req_settings ) ) {
107 $settings[$key] = $req_settings[$key];
108 }
109 }
110
111 $requires_wpuf_update = false;
112 $wpuf_update_array = array();
113
114 update_option( 'weforms_settings', $settings );
115
116 // wpuf settings sync
117 if ( !empty( $settings['gmap_api'] ) ) {
118 $requires_wpuf_update = true;
119 $wpuf_update_array['gmap_api_key'] = $settings['gmap_api'];
120 }
121
122 if ( !empty( $settings['recaptcha'] ) ) {
123 $requires_wpuf_update = true;
124 $wpuf_update_array['recaptcha_public'] = $settings['recaptcha']->key;
125 $wpuf_update_array['recaptcha_private'] = $settings['recaptcha']->secret;
126 }
127
128 if ( !empty( $settings['no_conflict'] ) ) {
129 $requires_wpuf_update = true;
130 $wpuf_update_array['no_conflict'] = $settings['no_conflict'];
131 }
132
133 if ( $requires_wpuf_update ) {
134 $wpuf_settings = get_option( 'wpuf_general', array() );
135 $wpuf_settings = array_merge( $wpuf_settings, $wpuf_update_array );
136
137 update_option( 'wpuf_general', $wpuf_settings );
138 }
139
140 do_action( 'weforms_save_settings', $settings );
141
142 $settings = apply_filters( 'weforms_after_save_settings', $settings );
143
144 $request->set_param( 'context', 'edit' );
145
146 $response = $this->prepare_response_for_collection( $settings,$request );
147 $response = rest_ensure_response( $response );
148
149 return $response;
150
151 }
152 }
153