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