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

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