|
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
|
|
|
$frm_roles = FrmAppHelper::frm_capabilities(); |
|
22
|
|
|
|
|
23
|
|
|
$uploads = wp_upload_dir(); |
|
24
|
|
|
$target_path = $uploads['basedir'] . '/formidable/css'; |
|
25
|
|
|
|
|
26
|
|
|
$sections = self::get_settings_tabs(); |
|
27
|
|
|
|
|
28
|
|
|
$captcha_lang = FrmAppHelper::locales( 'captcha' ); |
|
29
|
|
|
|
|
30
|
|
|
require( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/form.php' ); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
private static function get_settings_tabs() { |
|
34
|
|
|
$sections = array(); |
|
35
|
|
|
if ( apply_filters( 'frm_include_addon_page', false ) ) { |
|
36
|
|
|
$sections['licenses'] = array( |
|
37
|
|
|
'class' => 'FrmAddonsController', 'function' => 'license_settings', |
|
38
|
|
|
'name' => __( 'Plugin Licenses', 'formidable' ), |
|
39
|
|
|
'ajax' => true, |
|
40
|
|
|
); |
|
41
|
|
|
} |
|
42
|
|
|
$sections = apply_filters( 'frm_add_settings_section', $sections ); |
|
43
|
|
|
|
|
44
|
|
|
return $sections; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public static function load_settings_tab() { |
|
48
|
|
|
FrmAppHelper::permission_check('frm_change_settings'); |
|
49
|
|
|
check_ajax_referer( 'frm_ajax', 'nonce' ); |
|
50
|
|
|
|
|
51
|
|
|
$section = FrmAppHelper::get_post_param( 'tab', '', 'sanitize_text_field' ); |
|
52
|
|
|
$sections = self::get_settings_tabs(); |
|
53
|
|
|
if ( ! isset( $sections[ $section ] ) ) { |
|
54
|
|
|
wp_die(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$section = $sections[ $section ]; |
|
58
|
|
|
|
|
59
|
|
View Code Duplication |
if ( isset( $section['class'] ) ) { |
|
|
|
|
|
|
60
|
|
|
call_user_func( array( $section['class'], $section['function'] ) ); |
|
61
|
|
|
} else { |
|
62
|
|
|
call_user_func( ( isset( $section['function'] ) ? $section['function'] : $section ) ); |
|
63
|
|
|
} |
|
64
|
|
|
wp_die(); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public static function process_form( $stop_load = false ) { |
|
68
|
|
|
global $frm_vars; |
|
69
|
|
|
|
|
70
|
|
|
$frm_settings = FrmAppHelper::get_settings(); |
|
71
|
|
|
|
|
72
|
|
|
$process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); |
|
73
|
|
|
if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) { |
|
74
|
|
|
wp_die( $frm_settings->admin_permission ); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
$errors = array(); |
|
78
|
|
|
$message = ''; |
|
79
|
|
|
|
|
80
|
|
|
if ( ! isset( $frm_vars['settings_routed'] ) || ! $frm_vars['settings_routed'] ) { |
|
81
|
|
|
$errors = $frm_settings->validate( $_POST, array() ); |
|
82
|
|
|
|
|
83
|
|
|
$frm_settings->update( stripslashes_deep( $_POST ) ); |
|
84
|
|
|
|
|
85
|
|
|
if ( empty( $errors ) ) { |
|
86
|
|
|
$frm_settings->store(); |
|
87
|
|
|
$message = __( 'Settings Saved', 'formidable' ); |
|
88
|
|
|
} |
|
89
|
|
|
} else { |
|
90
|
|
|
$message = __( 'Settings Saved', 'formidable' ); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
if ( $stop_load == 'stop_load' ) { |
|
94
|
|
|
$frm_vars['settings_routed'] = true; |
|
95
|
|
|
return; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
self::display_form( $errors, $message ); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
public static function route( $stop_load = false ) { |
|
102
|
|
|
$action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; |
|
103
|
|
|
$action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
|
104
|
|
|
if ( $action == 'process-form' ) { |
|
105
|
|
|
self::process_form( $stop_load ); |
|
106
|
|
|
} else if ( $stop_load != 'stop_load' ) { |
|
107
|
|
|
self::display_form(); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.