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

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