| @@ -1,115 +1,44 @@ | ||
| 1 | 1 | <?php |
| 2 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 3 | - die( 'You are not allowed to call this page directly.' ); | |
| 4 | -} | |
| 5 | 2 | |
| 6 | 3 | class FrmSettingsController { |
| 7 | 4 | |
| 8 | - public static function menu() { | |
| 5 | + public static function menu() { | |
| 9 | 6 | // Make sure admins can see the menu items |
| 10 | 7 | FrmAppHelper::force_capability( 'frm_change_settings' ); |
| 11 | 8 | |
| 12 | - add_submenu_page( 'formidable', 'Formidable | ' . __( 'Global Settings', 'formidable' ), __( 'Global Settings', 'formidable' ), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route' ); | |
| 13 | - } | |
| 9 | + add_submenu_page( 'formidable', 'Formidable | ' . __( 'Global Settings', 'formidable' ), __( 'Global Settings', 'formidable' ), 'frm_change_settings', 'formidable-settings', 'FrmSettingsController::route' ); | |
| 10 | + } | |
| 14 | 11 | |
| 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 | - } | |
| 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 | + } | |
| 26 | 16 | |
| 27 | - public static function display_form( $errors = array(), $message = '' ) { | |
| 28 | - global $frm_vars; | |
| 17 | + public static function display_form( $errors = array(), $message = '' ) { | |
| 18 | + global $frm_vars; | |
| 29 | 19 | |
| 30 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 20 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 21 | + $frm_roles = FrmAppHelper::frm_capabilities(); | |
| 31 | 22 | |
| 32 | - $uploads = wp_upload_dir(); | |
| 33 | - $target_path = $uploads['basedir'] . '/formidable/css'; | |
| 23 | + $uploads = wp_upload_dir(); | |
| 24 | + $target_path = $uploads['basedir'] . '/formidable/css'; | |
| 34 | 25 | |
| 35 | 26 | $sections = self::get_settings_tabs(); |
| 36 | - $current = FrmAppHelper::simple_get( 't', 'sanitize_title', 'general_settings' ); | |
| 37 | 27 | |
| 28 | + $captcha_lang = FrmAppHelper::locales( 'captcha' ); | |
| 29 | + | |
| 38 | 30 | require( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/form.php' ); |
| 39 | 31 | } |
| 40 | 32 | |
| 41 | - /** | |
| 42 | - * Get sections to use for Global Settings. | |
| 43 | - * | |
| 44 | - * @return array<array> | |
| 45 | - */ | |
| 46 | 33 | 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 | - | |
| 34 | + $sections = array(); | |
| 106 | 35 | if ( apply_filters( 'frm_include_addon_page', false ) ) { |
| 107 | - // If no addons need a license, skip this page | |
| 108 | - $show_licenses = false; | |
| 36 | + // if no addons need a license, skip this page | |
| 37 | + $show_licenses = false; | |
| 109 | 38 | $installed_addons = apply_filters( 'frm_installed_addons', array() ); |
| 110 | 39 | foreach ( $installed_addons as $installed_addon ) { |
| 111 | - if ( ! $installed_addon->is_parent_licence && $installed_addon->plugin_name != 'Formidable Pro' && $installed_addon->needs_license ) { | |
| 40 | + if ( ! $installed_addon->is_parent_licence && $installed_addon->plugin_name != 'Formidable Pro' ) { | |
| 112 | 41 | $show_licenses = true; |
| 113 | 42 | break; |
| 114 | 43 | } |
| 115 | 44 | } |
| @@ -118,50 +47,14 @@ | ||
| 118 | 47 | $sections['licenses'] = array( |
| 119 | 48 | 'class' => 'FrmAddonsController', |
| 120 | 49 | 'function' => 'license_settings', |
| 121 | 50 | 'name' => __( 'Plugin Licenses', 'formidable' ), |
| 122 | - 'icon' => 'frm_icon_font frm_keyalt_icon', | |
| 123 | 51 | 'ajax' => true, |
| 124 | 52 | ); |
| 125 | 53 | } |
| 126 | 54 | } |
| 127 | - | |
| 128 | - /** | |
| 129 | - * @param array<array> $sections | |
| 130 | - */ | |
| 131 | 55 | $sections = apply_filters( 'frm_add_settings_section', $sections ); |
| 132 | 56 | |
| 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 | 57 | return $sections; |
| 165 | 58 | } |
| 166 | 59 | |
| 167 | 60 | public static function load_settings_tab() { |
| @@ -167,9 +60,9 @@ | ||
| 167 | 60 | public static function load_settings_tab() { |
| 168 | 61 | FrmAppHelper::permission_check( 'frm_change_settings' ); |
| 169 | 62 | check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 170 | 63 | |
| 171 | - $section = FrmAppHelper::get_post_param( 'tab', '', 'sanitize_text_field' ); | |
| 64 | + $section = FrmAppHelper::get_post_param( 'tab', '', 'sanitize_text_field' ); | |
| 172 | 65 | $sections = self::get_settings_tabs(); |
| 173 | 66 | if ( ! isset( $sections[ $section ] ) ) { |
| 174 | 67 | wp_die(); |
| 175 | 68 | } |
| @@ -183,141 +76,51 @@ | ||
| 183 | 76 | } |
| 184 | 77 | wp_die(); |
| 185 | 78 | } |
| 186 | 79 | |
| 187 | - /** | |
| 188 | - * Render the general global settings section. | |
| 189 | - * | |
| 190 | - * @since 4.0 | |
| 191 | - * | |
| 192 | - * @return void | |
| 193 | - */ | |
| 194 | - public static function general_settings() { | |
| 195 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 196 | - $uploads = wp_upload_dir(); | |
| 197 | - $target_path = $uploads['basedir'] . '/formidable/css'; | |
| 80 | + public static function process_form( $stop_load = false ) { | |
| 81 | + global $frm_vars; | |
| 198 | 82 | |
| 199 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/general.php'; | |
| 200 | - } | |
| 83 | + $frm_settings = FrmAppHelper::get_settings(); | |
| 201 | 84 | |
| 202 | - /** | |
| 203 | - * Render the global currency selector if Pro is up to date. | |
| 204 | - * | |
| 205 | - * @param FrmSettings $frm_settings | |
| 206 | - * @param string $more_html | |
| 207 | - * @return void | |
| 208 | - */ | |
| 209 | - public static function maybe_render_currency_selector( $frm_settings, $more_html ) { | |
| 210 | - if ( false !== strpos( $more_html, 'id="frm_currency"' ) ) { | |
| 211 | - // Avoid rendering the Currency setting if it gets rendered from the frm_settings_form hook. | |
| 212 | - // This is for backward compatibility. If Pro is outdated there won't be two currency dropdowns. | |
| 213 | - return; | |
| 214 | - } | |
| 215 | - | |
| 216 | - $currencies = FrmCurrencyHelper::get_currencies(); | |
| 217 | - include FrmAppHelper::plugin_path() . '/classes/views/frm-settings/_currency.php'; | |
| 218 | - } | |
| 219 | - | |
| 220 | - /** | |
| 221 | - * @since 4.0 | |
| 222 | - */ | |
| 223 | - public static function message_settings() { | |
| 224 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 225 | - | |
| 226 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/messages.php' ); | |
| 227 | - } | |
| 228 | - | |
| 229 | - /** | |
| 230 | - * @since 4.0 | |
| 231 | - */ | |
| 232 | - public static function captcha_settings() { | |
| 233 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 234 | - $captcha_lang = FrmAppHelper::locales( 'captcha' ); | |
| 235 | - | |
| 236 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/captcha/captcha.php' ); | |
| 237 | - } | |
| 238 | - | |
| 239 | - /** | |
| 240 | - * @since 4.0 | |
| 241 | - */ | |
| 242 | - public static function permission_settings() { | |
| 243 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 244 | - $frm_roles = FrmAppHelper::frm_capabilities(); | |
| 245 | - | |
| 246 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/permissions.php' ); | |
| 247 | - } | |
| 248 | - | |
| 249 | - /** | |
| 250 | - * @since 4.0 | |
| 251 | - */ | |
| 252 | - public static function misc_settings() { | |
| 253 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 254 | - | |
| 255 | - include( FrmAppHelper::plugin_path() . '/classes/views/frm-settings/misc.php' ); | |
| 256 | - } | |
| 257 | - | |
| 258 | - /** | |
| 259 | - * Save form data submitted from the Global settings page. | |
| 260 | - * | |
| 261 | - * @param string|bool $stop_load | |
| 262 | - * | |
| 263 | - * @return void | |
| 264 | - */ | |
| 265 | - public static function process_form( $stop_load = false ) { | |
| 266 | - global $frm_vars; | |
| 267 | - | |
| 268 | - $frm_settings = FrmAppHelper::get_settings(); | |
| 269 | 85 | $process_form = FrmAppHelper::get_post_param( 'process_form', '', 'sanitize_text_field' ); |
| 270 | - | |
| 271 | 86 | if ( ! wp_verify_nonce( $process_form, 'process_form_nonce' ) ) { |
| 272 | 87 | wp_die( esc_html( $frm_settings->admin_permission ) ); |
| 273 | - } | |
| 88 | + } | |
| 274 | 89 | |
| 275 | - $errors = array(); | |
| 276 | - $message = ''; | |
| 90 | + $errors = array(); | |
| 91 | + $message = ''; | |
| 277 | 92 | |
| 278 | - if ( empty( $frm_vars['settings_routed'] ) ) { | |
| 279 | - $errors = $frm_settings->validate( $_POST, array() ); | |
| 93 | + if ( ! isset( $frm_vars['settings_routed'] ) || ! $frm_vars['settings_routed'] ) { | |
| 94 | + $errors = $frm_settings->validate( $_POST, array() ); | |
| 280 | 95 | |
| 281 | - $frm_settings->update( wp_unslash( $_POST ) ); | |
| 96 | + $frm_settings->update( stripslashes_deep( $_POST ) ); | |
| 282 | 97 | |
| 283 | - if ( ! $errors ) { | |
| 284 | - $frm_settings->store(); | |
| 285 | - $message = __( 'Settings Saved', 'formidable' ); | |
| 286 | - } | |
| 287 | - } else { | |
| 288 | - $message = __( 'Settings Saved', 'formidable' ); | |
| 289 | - } | |
| 98 | + if ( empty( $errors ) ) { | |
| 99 | + $frm_settings->store(); | |
| 100 | + $message = __( 'Settings Saved', 'formidable' ); | |
| 101 | + } | |
| 102 | + } else { | |
| 103 | + $message = __( 'Settings Saved', 'formidable' ); | |
| 104 | + } | |
| 290 | 105 | |
| 291 | - if ( $stop_load === 'stop_load' ) { | |
| 292 | - $frm_vars['settings_routed'] = true; | |
| 293 | - return; | |
| 294 | - } | |
| 106 | + if ( $stop_load == 'stop_load' ) { | |
| 107 | + $frm_vars['settings_routed'] = true; | |
| 108 | + return; | |
| 109 | + } | |
| 295 | 110 | |
| 296 | - self::display_form( $errors, $message ); | |
| 297 | - } | |
| 111 | + self::display_form( $errors, $message ); | |
| 112 | + } | |
| 298 | 113 | |
| 299 | - /** | |
| 300 | - * Include the Update button on the global settings page. | |
| 301 | - * | |
| 302 | - * @since 4.0.02 | |
| 303 | - */ | |
| 304 | - public static function save_button() { | |
| 305 | - echo '<input class="button-primary frm-button-primary" type="submit" | |
| 306 | - value="' . esc_attr__( 'Update', 'formidable' ) . '"/>'; | |
| 307 | - } | |
| 308 | - | |
| 309 | - public static function route( $stop_load = false ) { | |
| 310 | - $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; | |
| 114 | + public static function route( $stop_load = false ) { | |
| 115 | + $action = isset( $_REQUEST['frm_action'] ) ? 'frm_action' : 'action'; | |
| 311 | 116 | $action = FrmAppHelper::get_param( $action, '', 'get', 'sanitize_title' ); |
| 312 | - FrmAppHelper::include_svg(); | |
| 313 | - | |
| 314 | - if ( $action == 'process-form' ) { | |
| 117 | + if ( $action == 'process-form' ) { | |
| 315 | 118 | self::process_form( $stop_load ); |
| 316 | - } elseif ( $stop_load != 'stop_load' ) { | |
| 119 | + } else if ( $stop_load != 'stop_load' ) { | |
| 317 | 120 | self::display_form(); |
| 318 | - } | |
| 319 | - } | |
| 121 | + } | |
| 122 | + } | |
| 320 | 123 | |
| 321 | 124 | /** |
| 322 | 125 | * Add CTA to the bottom on the plugin settings pages. |
| 323 | 126 | * |
| @@ -362,50 +165,5 @@ | ||
| 362 | 165 | |
| 363 | 166 | wp_send_json_success(); |
| 364 | 167 | } |
| 365 | 168 | |
| 366 | - /** | |
| 367 | - * Autocomplete page admin ajax endpoint | |
| 368 | - * | |
| 369 | - * @since 4.03.06 | |
| 370 | - */ | |
| 371 | - public static function page_search() { | |
| 372 | - FrmAppHelper::permission_check( 'frm_edit_forms' ); | |
| 373 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 374 | - | |
| 375 | - global $wpdb; | |
| 376 | - | |
| 377 | - $term = FrmAppHelper::get_param( 'term', '', 'get', 'sanitize_text_field' ); | |
| 378 | - $post_type = FrmAppHelper::get_param( 'post_type', 'page', 'get', 'sanitize_text_field' ); | |
| 379 | - | |
| 380 | - $where = array( | |
| 381 | - 'post_status' => 'publish', | |
| 382 | - 'post_type' => $post_type, | |
| 383 | - 'post_title LIKE' => $term, | |
| 384 | - ); | |
| 385 | - | |
| 386 | - $atts = array( | |
| 387 | - 'limit' => 25, | |
| 388 | - 'order_by' => 'post_title', | |
| 389 | - ); | |
| 390 | - | |
| 391 | - $pages = FrmDb::get_results( $wpdb->posts, $where, 'ID, post_title', $atts ); | |
| 392 | - | |
| 393 | - $results = array(); | |
| 394 | - foreach ( $pages as $page ) { | |
| 395 | - $results[] = array( | |
| 396 | - 'value' => $page->ID, | |
| 397 | - 'label' => $page->post_title, | |
| 398 | - ); | |
| 399 | - } | |
| 400 | - | |
| 401 | - wp_send_json( $results ); | |
| 402 | - } | |
| 403 | - | |
| 404 | - /** | |
| 405 | - * @deprecated 6.0 use FrmSettingsController::captcha_settings(). | |
| 406 | - */ | |
| 407 | - public static function recaptcha_settings() { | |
| 408 | - _deprecated_function( __FUNCTION__, '6.0', 'FrmSettingsController::captcha_settings()' ); | |
| 409 | - self::captcha_settings(); | |
| 410 | - } | |
| 411 | 169 | } |