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

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