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

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