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

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