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

384 lines 11.1 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 public static function menu() {
9 // Make sure admins can see the menu items
10 FrmAppHelper::force_capability( 'frm_change_settings' );
11
12 add_submenu_page( 'formidable', 'Formidable | ' . __( 'Global Settings', 'formidable' ), __( 'Global Settings', 'formidable' ), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route' );
13 }
14
15 public static function license_box() {
16 $a = FrmAppHelper::simple_get( 't', 'sanitize_title', 'general_settings' );
17 include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/license_box.php' );
18 }
19
20 public static function display_form( $errors = array(), $message = '' ) {
21 global $frm_vars;
22
23 $frm_settings = FrmAppHelper::get_settings();
24
25 $uploads = wp_upload_dir();
26 $target_path = $uploads['basedir'] . '/formidable/css';
27
28 $sections = self::get_settings_tabs();
29 $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'general_settings' );
30
31 require( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/form.php' );
32 }
33
34 /**
35 * Get sections to use for Global Settings.
36 *
37 * @return array<array>
38 */
39 private static function get_settings_tabs() {
40 $sections = array(
41 'general' => array(
42 'class' => __CLASS__,
43 'function' => 'general_settings',
44 'name' => __( 'General Settings', 'formidable' ),
45 'icon' => 'frm_icon_font frm_settings_icon',
46 ),
47 'messages' => array(
48 'class' => __CLASS__,
49 'function' => 'message_settings',
50 'name' => __( 'Message Defaults', 'formidable' ),
51 'icon' => 'frm_icon_font frm_stamp_icon',
52 ),
53 'permissions' => array(
54 'class' => __CLASS__,
55 'function' => 'permission_settings',
56 'name' => __( 'Permissions', 'formidable' ),
57 'icon' => 'frm_icon_font frm_lock_icon',
58 ),
59 'custom_css' => array(
60 'class' => 'FrmStylesController',
61 'function' => 'custom_css',
62 'name' => __( 'Custom CSS', 'formidable' ),
63 'icon' => 'frm_icon_font frm_code_icon',
64 ),
65 'manage_styles' => array(
66 'class' => 'FrmStylesController',
67 'function' => 'manage',
68 'name' => __( 'Manage Styles', 'formidable' ),
69 'icon' => 'frm_icon_font frm_pallet_icon',
70 ),
71 'captcha' => array(
72 'class' => __CLASS__,
73 'function' => 'captcha_settings',
74 'name' => __( 'Captcha', 'formidable' ),
75 'icon' => 'frm_icon_font frm_shield_check_icon',
76 ),
77 'white_label' => array(
78 'name' => __( 'White Labeling', 'formidable' ),
79 'icon' => 'frm_icon_font frm_ghost_icon',
80 'html_class' => 'frm_show_upgrade_tab frm_noallow',
81 'data' => array(
82 'medium' => 'white-label',
83 'upgrade' => __( 'White labeling options', 'formidable' ),
84 'screenshot' => 'white-label.png',
85 ),
86 ),
87 'inbox' => array(
88 'name' => __( 'Inbox', 'formidable' ),
89 'icon' => 'frm_icon_font frm_email_icon',
90 'html_class' => 'frm_show_upgrade_tab frm_noallow',
91 'data' => array(
92 'medium' => 'inbox-settings',
93 'upgrade' => __( 'Inbox settings', 'formidable' ),
94 'screenshot' => 'inbox.png',
95 ),
96 ),
97 );
98
99 if ( apply_filters( 'frm_include_addon_page', false ) ) {
100 // If no addons need a license, skip this page
101 $show_licenses = false;
102 $installed_addons = apply_filters( 'frm_installed_addons', array() );
103 foreach ( $installed_addons as $installed_addon ) {
104 if ( ! $installed_addon->is_parent_licence && $installed_addon->plugin_name != 'Formidable Pro' && $installed_addon->needs_license ) {
105 $show_licenses = true;
106 break;
107 }
108 }
109
110 if ( $show_licenses ) {
111 $sections['licenses'] = array(
112 'class' => 'FrmAddonsController',
113 'function' => 'license_settings',
114 'name' => __( 'Plugin Licenses', 'formidable' ),
115 'icon' => 'frm_icon_font frm_keyalt_icon',
116 'ajax' => true,
117 );
118 }
119 }
120
121 /**
122 * @param array<array> $sections
123 */
124 $sections = apply_filters( 'frm_add_settings_section', $sections );
125
126 $sections['misc'] = array(
127 'name' => __( 'Miscellaneous', 'formidable' ),
128 'icon' => 'frm_icon_font frm_shuffle_icon',
129 'class' => __CLASS__,
130 'function' => 'misc_settings',
131 );
132
133 foreach ( $sections as $key => $section ) {
134 $original = $section;
135 $defaults = array(
136 'html_class' => '',
137 'name' => ucfirst( $key ),
138 'icon' => 'frm_icon_font frm_settings_icon',
139 'anchor' => $key . '_settings',
140 'data' => array(),
141 );
142
143 $section = array_merge( $defaults, $section );
144
145 if ( isset( $section['ajax'] ) && ! isset( $section['data']['frmajax'] ) ) {
146 $section['data']['frmajax'] = $section['ajax'];
147 }
148
149 // For reverse compatibility.
150 if ( ! isset( $section['function'] ) && ( ! is_array( $original ) || ! isset( $original['name'] ) ) ) {
151 $section['function'] = $original;
152 }
153
154 $sections[ $key ] = $section;
155 }
156
157 return $sections;
158 }
159
160 public static function load_settings_tab() {
161 FrmAppHelper::permission_check( 'frm_change_settings' );
162 check_ajax_referer( 'frm_ajax', 'nonce' );
163
164 $section = FrmAppHelper::get_post_param( 'tab', '', 'sanitize_text_field' );
165 $sections = self::get_settings_tabs();
166 if ( ! isset( $sections[ $section ] ) ) {
167 wp_die();
168 }
169
170 $section = $sections[ $section ];
171
172 if ( isset( $section['class'] ) ) {
173 call_user_func( array( $section['class'], $section['function'] ) );
174 } else {
175 call_user_func( ( isset( $section['function'] ) ? $section['function'] : $section ) );
176 }
177 wp_die();
178 }
179
180 /**
181 * @since 4.0
182 */
183 public static function general_settings() {
184 $frm_settings = FrmAppHelper::get_settings();
185
186 $uploads = wp_upload_dir();
187 $target_path = $uploads['basedir'] . '/formidable/css';
188
189 include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/general.php' );
190 }
191
192 /**
193 * @since 4.0
194 */
195 public static function message_settings() {
196 $frm_settings = FrmAppHelper::get_settings();
197
198 include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/messages.php' );
199 }
200
201 /**
202 * @since 4.0
203 */
204 public static function captcha_settings() {
205 $frm_settings = FrmAppHelper::get_settings();
206 $captcha_lang = FrmAppHelper::locales( 'captcha' );
207
208 include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/captcha/captcha.php' );
209 }
210
211 /**
212 * @since 4.0
213 */
214 public static function permission_settings() {
215 $frm_settings = FrmAppHelper::get_settings();
216 $frm_roles = FrmAppHelper::frm_capabilities();
217
218 include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/permissions.php' );
219 }
220
221 /**
222 * @since 4.0
223 */
224 public static function misc_settings() {
225 $frm_settings = FrmAppHelper::get_settings();
226
227 include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/misc.php' );
228 }
229
230 /**
231 * Save form data submitted from the Global settings page.
232 *
233 * @param string|bool $stop_load
234 *
235 * @return void
236 */
237 public static function process_form( $stop_load = false ) {
238 global $frm_vars;
239
240 $frm_settings = FrmAppHelper::get_settings();
241 $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' );
242
243 if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) {
244 wp_die( esc_html( $frm_settings->admin_permission ) );
245 }
246
247 $errors = array();
248 $message = '';
249
250 if ( empty( $frm_vars['settings_routed'] ) ) {
251 $errors = $frm_settings->validate( $_POST, array() );
252
253 $frm_settings->update( wp_unslash( $_POST ) );
254
255 if ( ! $errors ) {
256 $frm_settings->store();
257 $message = __( 'Settings Saved', 'formidable' );
258 }
259 } else {
260 $message = __( 'Settings Saved', 'formidable' );
261 }
262
263 if ( $stop_load === 'stop_load' ) {
264 $frm_vars['settings_routed'] = true;
265 return;
266 }
267
268 self::display_form( $errors, $message );
269 }
270
271 /**
272 * Include the Update button on the global settings page.
273 *
274 * @since 4.0.02
275 */
276 public static function save_button() {
277 echo '<input class="button-primary frm-button-primary" type="submit"
278 value="' . esc_attr__( 'Update', 'formidable' ) . '"/>';
279 }
280
281 public static function route( $stop_load = false ) {
282 $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action';
283 $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' );
284 FrmAppHelper::include_svg();
285
286 if ( $action == 'process-form' ) {
287 self::process_form( $stop_load );
288 } elseif ( $stop_load != 'stop_load' ) {
289 self::display_form();
290 }
291 }
292
293 /**
294 * Add CTA to the bottom on the plugin settings pages.
295 *
296 * @since 3.04.02
297 */
298 public static function settings_cta( $view ) {
299
300 if ( get_option( 'frm_lite_settings_upgrade', false ) ) {
301 return;
302 }
303
304 $features = array(
305 __( 'Extra form features like file uploads, pagination, etc', 'formidable' ),
306 __( 'Repeaters & cascading fields for advanced forms', 'formidable' ),
307 __( 'Flexibly view, search, edit, and delete entries anywhere', 'formidable' ),
308 __( 'Display entries with virtually limitless Formidable views', 'formidable' ),
309 __( 'Create surveys & polls', 'formidable' ),
310 __( 'WordPress user registration and login forms', 'formidable' ),
311 __( 'Create Stripe, PayPal or Authorize.net payment forms', 'formidable' ),
312 __( 'Powerful conditional logic for smart forms', 'formidable' ),
313 __( 'Integrations with 1000+ marketing & payment services', 'formidable' ),
314 __( 'Collect digital signatures', 'formidable' ),
315 __( 'Accept user-submitted content with Post submissions', 'formidable' ),
316 __( 'Email routing', 'formidable' ),
317 __( 'Create calculator forms', 'formidable' ),
318 __( 'Save draft entries and return later', 'formidable' ),
319 __( 'Analyze form data with graphs & stats', 'formidable' ),
320 );
321
322 include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/settings_cta.php' );
323 }
324
325 /**
326 * Dismiss upgrade notice at the bottom on the plugin settings pages.
327 *
328 * @since 3.04.02
329 */
330 public static function settings_cta_dismiss() {
331 FrmAppHelper::permission_check( 'frm_change_settings' );
332
333 update_option( 'frm_lite_settings_upgrade', time(), 'no' );
334
335 wp_send_json_success();
336 }
337
338 /**
339 * Autocomplete page admin ajax endpoint
340 *
341 * @since 4.03.06
342 */
343 public static function page_search() {
344 FrmAppHelper::permission_check( 'frm_edit_forms' );
345 check_ajax_referer( 'frm_ajax', 'nonce' );
346
347 global $wpdb;
348
349 $term = FrmAppHelper::get_param( 'term', '', 'get', 'sanitize_text_field' );
350 $post_type = FrmAppHelper::get_param( 'post_type', 'page', 'get', 'sanitize_text_field' );
351
352 $where = array(
353 'post_status' => 'publish',
354 'post_type' => $post_type,
355 'post_title LIKE' => $term,
356 );
357
358 $atts = array(
359 'limit' => 25,
360 'order_by' => 'post_title',
361 );
362
363 $pages = FrmDb::get_results( $wpdb->posts, $where, 'ID, post_title', $atts );
364
365 $results = array();
366 foreach ( $pages as $page ) {
367 $results[] = array(
368 'value' => $page->ID,
369 'label' => $page->post_title,
370 );
371 }
372
373 wp_send_json( $results );
374 }
375
376 /**
377 * @deprecated x.x use FrmSettingsController::captcha_settings().
378 */
379 public static function recaptcha_settings() {
380 _deprecated_function( __FUNCTION__, 'x.x', 'FrmSettingsController::captcha_settings()' );
381 self::captcha_settings();
382 }
383 }
384