PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 4.08
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v4.08
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / models / FrmSettings.php

FrmSettings.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 4.08, at classes/models/FrmSettings.php

295 lines 8.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmSettings {
7 public $option_name = 'frm_options';
8 public $menu;
9 public $mu_menu;
10 public $use_html;
11 public $jquery_css;
12 public $accordion_js;
13 public $fade_form;
14 public $old_css;
15 public $admin_bar;
16
17 public $success_msg;
18 public $blank_msg;
19 public $unique_msg;
20 public $invalid_msg;
21 public $failed_msg;
22 public $submit_value;
23 public $login_msg;
24 public $admin_permission;
25
26 public $email_to;
27 public $load_style;
28 public $custom_style;
29
30 public $pubkey;
31 public $privkey;
32 public $re_lang;
33 public $re_type;
34 public $re_msg;
35 public $re_multi;
36
37 public $no_ips;
38 public $current_form = 0;
39 public $tracking;
40
41 public function __construct( $args = array() ) {
42 if ( ! defined( 'ABSPATH' ) ) {
43 die( 'You are not allowed to call this page directly.' );
44 }
45
46 $settings = get_transient( $this->option_name );
47
48 if ( ! is_object( $settings ) ) {
49 $settings = $this->translate_settings( $settings );
50 }
51
52 foreach ( $settings as $setting_name => $setting ) {
53 $this->{$setting_name} = $setting;
54 unset( $setting_name, $setting );
55 }
56
57 $this->set_default_options();
58
59 $this->maybe_filter_for_form( $args );
60 }
61
62 private function translate_settings( $settings ) {
63 if ( $settings ) { //workaround for W3 total cache conflict
64 return unserialize( serialize( $settings ) );
65 }
66
67 $settings = get_option( $this->option_name );
68 if ( is_object( $settings ) ) {
69 set_transient( $this->option_name, $settings );
70
71 return $settings;
72 }
73
74 // If unserializing didn't work
75 if ( $settings ) { //workaround for W3 total cache conflict
76 $settings = unserialize( serialize( $settings ) );
77 } else {
78 $settings = $this;
79 }
80
81 update_option( $this->option_name, $settings );
82 set_transient( $this->option_name, $settings );
83
84 return $settings;
85 }
86
87 /**
88 * @return array
89 */
90 public function default_options() {
91 return array(
92 'menu' => apply_filters( 'frm_default_menu', 'Formidable' ),
93 'mu_menu' => 0,
94 'use_html' => true,
95 'jquery_css' => false,
96 'accordion_js' => false,
97 'fade_form' => false,
98 'old_css' => false,
99 'admin_bar' => false,
100
101 're_multi' => 1,
102
103 'success_msg' => __( 'Your responses were successfully submitted. Thank you!', 'formidable' ),
104 'blank_msg' => __( 'This field cannot be blank.', 'formidable' ),
105 'unique_msg' => __( 'This value must be unique.', 'formidable' ),
106 'invalid_msg' => __( 'There was a problem with your submission. Errors are marked below.', 'formidable' ),
107 'failed_msg' => __( 'We\'re sorry. It looks like you\'ve already submitted that.', 'formidable' ),
108 'submit_value' => __( 'Submit', 'formidable' ),
109 'login_msg' => __( 'You do not have permission to view this form.', 'formidable' ),
110 'admin_permission' => __( 'You do not have permission to do that', 'formidable' ),
111
112 'email_to' => '[admin_email]',
113 'no_ips' => 0,
114 'tracking' => FrmAppHelper::pro_is_installed(),
115 );
116 }
117
118 private function set_default_options() {
119 $this->fill_recaptcha_settings();
120
121 if ( ! isset( $this->load_style ) ) {
122 if ( ! isset( $this->custom_style ) ) {
123 $this->custom_style = true;
124 }
125
126 $this->load_style = 'all';
127 }
128
129 $this->fill_with_defaults();
130
131 if ( is_multisite() && is_admin() ) {
132 $mu_menu = get_site_option( 'frm_admin_menu_name' );
133 if ( $mu_menu && ! empty( $mu_menu ) ) {
134 $this->menu = $mu_menu;
135 $this->mu_menu = 1;
136 }
137 }
138
139 $frm_roles = FrmAppHelper::frm_capabilities( 'pro' );
140 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
141 if ( ! isset( $this->$frm_role ) ) {
142 $this->$frm_role = 'administrator';
143 }
144 }
145 }
146
147 public function fill_with_defaults( $params = array() ) {
148 $settings = $this->default_options();
149
150 foreach ( $settings as $setting => $default ) {
151 if ( isset( $params[ 'frm_' . $setting ] ) ) {
152 $this->{$setting} = $params[ 'frm_' . $setting ];
153 } elseif ( ! isset( $this->{$setting} ) ) {
154 $this->{$setting} = $default;
155 }
156
157 if ( $setting == 'menu' && empty( $this->{$setting} ) ) {
158 $this->{$setting} = $default;
159 }
160
161 unset( $setting, $default );
162 }
163 }
164
165 private function fill_recaptcha_settings() {
166 $privkey = '';
167 $re_lang = '';
168
169 if ( ! isset( $this->pubkey ) ) {
170 // get the options from the database
171 $recaptcha_opt = is_multisite() ? get_site_option( 'recaptcha' ) : get_option( 'recaptcha' );
172 $this->pubkey = isset( $recaptcha_opt['pubkey'] ) ? $recaptcha_opt['pubkey'] : '';
173 $privkey = isset( $recaptcha_opt['privkey'] ) ? $recaptcha_opt['privkey'] : $privkey;
174 $re_lang = isset( $recaptcha_opt['re_lang'] ) ? $recaptcha_opt['re_lang'] : $re_lang;
175 }
176
177 if ( ! isset( $this->re_msg ) || empty( $this->re_msg ) ) {
178 $this->re_msg = __( 'The reCAPTCHA was not entered correctly', 'formidable' );
179 }
180
181 if ( ! isset( $this->privkey ) ) {
182 $this->privkey = $privkey;
183 }
184
185 if ( ! isset( $this->re_lang ) ) {
186 $this->re_lang = $re_lang;
187 }
188
189 if ( ! isset( $this->re_type ) ) {
190 $this->re_type = '';
191 }
192 }
193
194 /**
195 * Get values that may be shown on the front-end without an override in the form settings.
196 *
197 * @since 3.06.01
198 */
199 public function translatable_strings() {
200 return array(
201 'invalid_msg',
202 'failed_msg',
203 'login_msg',
204 );
205 }
206
207 /**
208 * Allow strings to be filtered when a specific form may be displaying them.
209 *
210 * @since 3.06.01
211 */
212 public function maybe_filter_for_form( $args ) {
213 if ( isset( $args['current_form'] ) && is_numeric( $args['current_form'] ) ) {
214 $this->current_form = $args['current_form'];
215 foreach ( $this->translatable_strings() as $string ) {
216 $this->{$string} = apply_filters( 'frm_global_setting', $this->{$string}, $string, $this );
217 $this->{$string} = apply_filters( 'frm_global_' . $string, $this->{$string}, $this );
218 }
219 }
220 }
221
222 public function validate( $params, $errors ) {
223 return apply_filters( 'frm_validate_settings', $errors, $params );
224 }
225
226 public function update( $params ) {
227 $this->fill_with_defaults( $params );
228 $this->update_settings( $params );
229
230 if ( $this->mu_menu ) {
231 update_site_option( 'frm_admin_menu_name', $this->menu );
232 } elseif ( current_user_can( 'administrator' ) ) {
233 update_site_option( 'frm_admin_menu_name', false );
234 }
235
236 $this->update_roles( $params );
237
238 do_action( 'frm_update_settings', $params );
239
240 if ( function_exists( 'get_filesystem_method' ) ) {
241 // save styling settings in case fallback setting changes
242 $frm_style = new FrmStyle();
243 $frm_style->update( 'default' );
244 }
245 }
246
247 private function update_settings( $params ) {
248 $this->pubkey = trim( $params['frm_pubkey'] );
249 $this->privkey = $params['frm_privkey'];
250 $this->re_type = $params['frm_re_type'];
251 $this->re_lang = $params['frm_re_lang'];
252
253 $this->load_style = $params['frm_load_style'];
254
255 $checkboxes = array( 'mu_menu', 're_multi', 'use_html', 'jquery_css', 'accordion_js', 'fade_form', 'old_css', 'no_ips', 'tracking', 'admin_bar' );
256 foreach ( $checkboxes as $set ) {
257 $this->$set = isset( $params[ 'frm_' . $set ] ) ? $params[ 'frm_' . $set ] : 0;
258 }
259 }
260
261 private function update_roles( $params ) {
262 global $wp_roles;
263
264 $frm_roles = FrmAppHelper::frm_capabilities();
265 $roles = get_editable_roles();
266 foreach ( $frm_roles as $frm_role => $frm_role_description ) {
267 $this->$frm_role = (array) ( isset( $params[ $frm_role ] ) ? $params[ $frm_role ] : 'administrator' );
268
269 // Make sure administrators always have permissions
270 if ( ! in_array( 'administrator', $this->$frm_role ) ) {
271 array_push( $this->$frm_role, 'administrator' );
272 }
273
274 foreach ( $roles as $role => $details ) {
275 if ( in_array( $role, $this->$frm_role ) ) {
276 $wp_roles->add_cap( $role, $frm_role );
277 } else {
278 $wp_roles->remove_cap( $role, $frm_role );
279 }
280 }
281 }
282 }
283
284 public function store() {
285 // Save the posted value in the database
286
287 update_option( 'frm_options', $this );
288
289 delete_transient( 'frm_options' );
290 set_transient( 'frm_options', $this );
291
292 do_action( 'frm_store_settings' );
293 }
294 }
295