PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.26.1
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.26.1
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 / controllers / FrmSettingsController.php

FrmSettingsController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.26.1, at classes/controllers/FrmSettingsController.php

542 lines 14.5 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 FrmSettingsController {
7
8 /**
9 * Payments sections are removed from the top level and added to a payments section.
10 *
11 * @since 6.22.1
12 *
13 * @var array
14 */
15 private static $removed_payments_sections = array();
16
17 /**
18 * @return void
19 */
20 public static function menu() {
21 // Make sure admins can see the menu items
22 FrmAppHelper::force_capability( 'frm_change_settings' );
23
24 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Global Settings', 'formidable' ), __( 'Global Settings', 'formidable' ), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route' );
25 }
26
27 /**
28 * Include license box template on demand.
29 *
30 * @return void
31 */
32 public static function license_box() {
33 if ( ! current_user_can( 'activate_plugins' ) ) {
34 return;
35 }
36 include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/license_box.php';
37 }
38
39 /**
40 * @param array $errors
41 * @param string $message
42 *
43 * @return void
44 */
45 public static function display_form( $errors = array(), $message = '' ) {
46 global $frm_vars;
47
48 $frm_settings = FrmAppHelper::get_settings();
49
50 $uploads = wp_upload_dir();
51 $target_path = $uploads['basedir'] . '/formidable/css';
52
53 $sections = self::get_settings_tabs();
54 $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'general_settings' );
55
56 if ( in_array( $current, array( 'stripe_settings', 'square_settings', 'authorize_net_settings', 'paypal_settings' ), true ) ) {
57 $current = 'payments_settings';
58 }
59
60 require FrmAppHelper::plugin_path() . '/classes/views/frm-settings/form.php';
61 }
62
63 /**
64 * Get sections to use for Global Settings.
65 *
66 * @return array<array>
67 */
68 private static function get_settings_tabs() {
69 $sections = array(
70 'general' => array(
71 'class' => self::class,
72 'function' => 'general_settings',
73 'name' => __( 'General Settings', 'formidable' ),
74 'icon' => 'frm_icon_font frm_settings_icon',
75 ),
76 'messages' => array(
77 'class' => self::class,
78 'function' => 'message_settings',
79 'name' => __( 'Message Defaults', 'formidable' ),
80 'icon' => 'frm_icon_font frm_stamp_icon',
81 ),
82 'permissions' => array(
83 'class' => self::class,
84 'function' => 'permission_settings',
85 'name' => __( 'Permissions', 'formidable' ),
86 'icon' => 'frm_icon_font frm_lock_icon',
87 ),
88 'payments' => array(
89 'name' => __( 'Payments', 'formidable' ),
90 'icon' => 'frm_icon_font frm_simple_cc_icon',
91 'class' => self::class,
92 'function' => 'payments_settings',
93 ),
94 'custom_css' => array(
95 'class' => 'FrmStylesController',
96 'function' => 'custom_css',
97 'name' => __( 'Custom CSS', 'formidable' ),
98 'icon' => 'frm_icon_font frm_code_icon',
99 ),
100 'manage_styles' => array(
101 'class' => 'FrmStylesController',
102 'function' => 'manage',
103 'name' => __( 'Manage Styles', 'formidable' ),
104 'icon' => 'frm_icon_font frm_pallet_icon',
105 ),
106 'captcha' => array(
107 'class' => self::class,
108 'function' => 'captcha_settings',
109 'name' => __( 'Captcha/Spam', 'formidable' ),
110 'icon' => 'frm_icon_font frm_shield_check_icon',
111 ),
112 'email' => array(
113 'class' => self::class,
114 'function' => 'email_settings',
115 'name' => __( 'Email', 'formidable' ),
116 'icon' => 'frm_icon_font frm_email_icon',
117 ),
118 'white_label' => array(
119 'name' => __( 'White Labeling', 'formidable' ),
120 'icon' => 'frm_icon_font frm_ghost_icon',
121 'html_class' => 'frm_show_upgrade_tab frm_noallow',
122 'data' => array(
123 'medium' => 'white-label',
124 'upgrade' => __( 'White labeling options', 'formidable' ),
125 'screenshot' => 'white-label.png',
126 'learn-more' => FrmAppHelper::get_doc_url( 'features/white-label-form-builder-wordpress', 'white-labeling-global-settings', false ),
127 ),
128 ),
129 'inbox' => array(
130 'name' => __( 'Inbox', 'formidable' ),
131 'icon' => 'frm_icon_font frm_email_icon',
132 'html_class' => 'frm_show_upgrade_tab frm_noallow',
133 'data' => array(
134 'medium' => 'inbox-settings',
135 'upgrade' => __( 'Inbox settings', 'formidable' ),
136 'screenshot' => 'inbox.png',
137 'learn-more' => FrmAppHelper::get_doc_url( 'global-settings-overview/#kb-inbox', 'inbox-global-settings' ),
138 ),
139 ),
140 );
141
142 if ( apply_filters( 'frm_include_addon_page', false ) ) {
143 // If no addons need a license, skip this page
144 $show_licenses = false;
145 $installed_addons = apply_filters( 'frm_installed_addons', array() );
146
147 foreach ( $installed_addons as $installed_addon ) {
148 if ( ! $installed_addon->is_parent_licence && $installed_addon->plugin_name != 'Formidable Pro' && $installed_addon->needs_license ) {
149 $show_licenses = true;
150 break;
151 }
152 }
153
154 if ( $show_licenses ) {
155 $sections['licenses'] = array(
156 'class' => 'FrmAddonsController',
157 'function' => 'license_settings',
158 'name' => __( 'Plugin Licenses', 'formidable' ),
159 'icon' => 'frmfont frm_key_icon',
160 'ajax' => true,
161 );
162 }
163 }//end if
164
165 /**
166 * @param array<array> $sections
167 */
168 $sections = apply_filters( 'frm_add_settings_section', $sections );
169 self::remove_payments_sections( $sections );
170
171 $sections['misc'] = array(
172 'name' => __( 'Miscellaneous', 'formidable' ),
173 'icon' => 'frm_icon_font frm_shuffle_icon',
174 'class' => self::class,
175 'function' => 'misc_settings',
176 );
177
178 foreach ( $sections as $key => $section ) {
179 $original = $section;
180 $defaults = array(
181 'html_class' => '',
182 'name' => ucfirst( $key ),
183 'icon' => 'frm_icon_font frm_settings_icon',
184 'anchor' => $key . '_settings',
185 'data' => array(),
186 );
187
188 $section = array_merge( $defaults, $section );
189
190 if ( isset( $section['ajax'] ) && ! isset( $section['data']['frmajax'] ) ) {
191 $section['data']['frmajax'] = $section['ajax'];
192 }
193
194 // For reverse compatibility.
195 if ( ! isset( $section['function'] ) && ( ! is_array( $original ) || ! isset( $original['name'] ) ) ) {
196 $section['function'] = $original;
197 }
198
199 $sections[ $key ] = $section;
200 }//end foreach
201
202 return $sections;
203 }
204
205 /**
206 * Remove the payments sections (PayPal, Square, Stripe, Authorize.Net)
207 * and show them all on the payments section in separate tabs.
208 *
209 * @since 6.22.1
210 *
211 * @param array $sections
212 *
213 * @return void
214 */
215 private static function remove_payments_sections( &$sections ) {
216 $payment_section_keys = array( 'paypal', 'square', 'stripe', 'authorize_net' );
217
218 foreach ( $sections as $key => $section ) {
219 if ( in_array( $key, $payment_section_keys, true ) ) {
220 self::$removed_payments_sections[ $key ] = $section;
221 unset( $sections[ $key ] );
222 }
223 }
224
225 uksort( self::$removed_payments_sections, array( self::class, 'payment_sections_sort_callback' ) );
226 }
227
228 /**
229 * Sort the payments sections (PayPal, Square, Stripe, Authorize.Net)
230 *
231 * @since 6.22.1
232 *
233 * @param string $a
234 * @param string $b
235 *
236 * @return int
237 */
238 private static function payment_sections_sort_callback( $a, $b ) {
239 $order = array( 'stripe', 'square', 'paypal', 'authorize_net' );
240 $first_key = array_search( $a, $order );
241 $second_key = array_search( $b, $order );
242
243 if ( false === $first_key || false === $second_key ) {
244 return 0;
245 }
246 return $first_key - $second_key;
247 }
248
249 public static function load_settings_tab() {
250 FrmAppHelper::permission_check( 'frm_change_settings' );
251 check_ajax_referer( 'frm_ajax', 'nonce' );
252
253 $section = FrmAppHelper::get_post_param( 'tab', '', 'sanitize_text_field' );
254 $sections = self::get_settings_tabs();
255
256 if ( ! isset( $sections[ $section ] ) ) {
257 wp_die();
258 }
259
260 $section = $sections[ $section ];
261
262 if ( isset( $section['class'] ) ) {
263 call_user_func( array( $section['class'], $section['function'] ) );
264 } else {
265 call_user_func( ( $section['function'] ?? $section ) );
266 }
267 wp_die();
268 }
269
270 /**
271 * Render the general global settings section.
272 *
273 * @since 4.0
274 *
275 * @return void
276 */
277 public static function general_settings() {
278 $frm_settings = FrmAppHelper::get_settings();
279 $uploads = wp_upload_dir();
280 $target_path = $uploads['basedir'] . '/formidable/css';
281
282 include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/general.php';
283 }
284
285 /**
286 * Render the global currency selector if Pro is up to date.
287 *
288 * @param FrmSettings $frm_settings
289 * @param string $more_html
290 *
291 * @return void
292 */
293 public static function maybe_render_currency_selector( $frm_settings, $more_html ) {
294 if ( is_callable( 'FrmProSettingsController::add_currency_settings' ) ) {
295 FrmProSettingsController::add_currency_settings();
296 return;
297 }
298
299 $currencies = FrmCurrencyHelper::get_currencies();
300 include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/_currency.php';
301 }
302
303 /**
304 * @since 4.0
305 *
306 * @return void
307 */
308 public static function message_settings() {
309 $frm_settings = FrmAppHelper::get_settings();
310
311 include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/messages.php';
312 }
313
314 /**
315 * @since 4.0
316 *
317 * @return void
318 */
319 public static function captcha_settings() {
320 $frm_settings = FrmAppHelper::get_settings();
321 $captcha_lang = FrmAppHelper::locales( 'captcha' );
322
323 include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/captcha/captcha.php';
324 }
325
326 /**
327 * Shows email settings.
328 *
329 * @since 6.25
330 *
331 * @return void
332 */
333 public static function email_settings() {
334 $frm_settings = FrmAppHelper::get_settings();
335
336 include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/email/email-styles.php';
337 }
338
339 /**
340 * @since 4.0
341 *
342 * @return void
343 */
344 public static function permission_settings() {
345 $frm_settings = FrmAppHelper::get_settings();
346 $frm_roles = FrmAppHelper::frm_capabilities();
347
348 include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/permissions.php';
349 }
350
351 /**
352 * @return void
353 */
354 public static function payments_settings() {
355 $payment_sections = self::$removed_payments_sections;
356
357 $tab = FrmAppHelper::simple_get( 't', 'sanitize_title', 'general_settings' );
358
359 if ( $tab && in_array( $tab, array( 'stripe_settings', 'square_settings', 'authorize_net_settings', 'paypal_settings' ), true ) ) {
360 $tab = str_replace( '_settings', '', $tab );
361 } else {
362 $tab = 'stripe';
363 }
364
365 include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/payments.php';
366 }
367
368 /**
369 * @since 4.0
370 *
371 * @return void
372 */
373 public static function misc_settings() {
374 $frm_settings = FrmAppHelper::get_settings();
375
376 include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/misc.php';
377 }
378
379 /**
380 * Save form data submitted from the Global settings page.
381 *
382 * @param bool|string $stop_load
383 *
384 * @return void
385 */
386 public static function process_form( $stop_load = false ) {
387 global $frm_vars;
388
389 $frm_settings = FrmAppHelper::get_settings();
390 $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
391
392 if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
393 $error_args = array(
394 'title' => __( 'Verification failed', 'formidable' ),
395 'body' => $frm_settings->admin_permission,
396 'cancel_text' => __( 'Cancel', 'formidable' ),
397 );
398 FrmAppController::show_error_modal( $error_args );
399 return;
400 }
401
402 $errors = array();
403 $message = '';
404
405 if ( empty( $frm_vars['settings_routed'] ) ) {
406 $errors = $frm_settings->validate( $_POST, array() );
407
408 $frm_settings->update( wp_unslash( $_POST ) );
409
410 if ( ! $errors ) {
411 $frm_settings->store();
412 $message = __( 'Settings Saved', 'formidable' );
413 }
414 } else {
415 $message = __( 'Settings Saved', 'formidable' );
416 }
417
418 if ( $stop_load === 'stop_load' ) {
419 $frm_vars['settings_routed'] = true;
420 return;
421 }
422
423 self::display_form( $errors, $message );
424 }
425
426 /**
427 * Include the Update button on the global settings page.
428 *
429 * @since 4.0.02
430 *
431 * @return void
432 */
433 public static function save_button() {
434 echo '<input class="button-primary frm-button-primary" type="submit"
435 value="' . esc_attr__( 'Update', 'formidable' ) . '"/>';
436 }
437
438 /**
439 * @param bool|string $stop_load
440 *
441 * @return void
442 */
443 public static function route( $stop_load = false ) {
444 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
445 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
446 FrmAppHelper::include_svg();
447
448 if ( $action === 'process-form' ) {
449 self::process_form( $stop_load );
450 } elseif ( $stop_load != 'stop_load' ) {
451 self::display_form();
452 }
453 }
454
455 /**
456 * Add CTA to the bottom on the plugin settings pages.
457 *
458 * @since 3.04.02
459 *
460 * @return void
461 */
462 public static function settings_cta() {
463 if ( get_option( 'frm_lite_settings_upgrade', false ) ) {
464 return;
465 }
466
467 include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/settings_cta.php';
468 }
469
470 /**
471 * Dismiss upgrade notice at the bottom on the plugin settings pages.
472 *
473 * @since 3.04.02
474 */
475 public static function settings_cta_dismiss() {
476 check_ajax_referer( 'frm_ajax', 'nonce' );
477 FrmAppHelper::permission_check( 'frm_change_settings' );
478
479 update_option( 'frm_lite_settings_upgrade', time(), 'no' );
480
481 wp_send_json_success();
482 }
483
484 /**
485 * Autocomplete page admin ajax endpoint
486 *
487 * @since 4.03.06
488 */
489 public static function page_search() {
490 FrmAppHelper::permission_check( 'frm_edit_forms' );
491 check_ajax_referer( 'frm_ajax', 'nonce' );
492
493 global $wpdb;
494
495 $term = FrmAppHelper::get_param( 'term', '', 'get', 'sanitize_text_field' );
496 $post_type = FrmAppHelper::get_param( 'post_type', 'page', 'get', 'sanitize_text_field' );
497
498 $where = array(
499 'post_status' => 'publish',
500 'post_type' => $post_type,
501 'post_title LIKE' => $term,
502 );
503
504 $atts = array(
505 'limit' => 25,
506 'order_by' => 'post_title',
507 );
508
509 $pages = FrmDb::get_results( $wpdb->posts, $where, 'ID, post_title', $atts );
510
511 $results = array();
512
513 foreach ( $pages as $page ) {
514 $results[] = array(
515 'value' => $page->ID,
516 'label' => $page->post_title,
517 );
518 }
519
520 wp_send_json( $results );
521 }
522
523 /**
524 * Shows a fake color picker.
525 *
526 * @since 6.25
527 *
528 * @param string $color Color value.
529 *
530 * @return void
531 */
532 public static function fake_color_picker( $color ) {
533 ?>
534 <div class="wp-picker-container">
535 <button type="button" class="button wp-color-result" aria-expanded="false" aria-disabled="true" tabindex="-1" style="background-color:<?php echo esc_attr( $color ); ?>;">
536 <span class="wp-color-result-text" style="color:#a7aaad;"><?php esc_html_e( 'Select Color', 'formidable' ); ?></span>
537 </button>
538 </div>
539 <?php
540 }
541 }
542