*/ class UsersWP_Admin_Settings { private $form_builder; public function __construct($form_builder) { $this->form_builder = $form_builder; } public function init_settings() { global $uwp_options; $uwp_options = $this->uwp_get_settings(); } public function uwp_settings_page() { $page = isset( $_GET['page'] ) ? $_GET['page'] : 'userswp'; $settings_array = uwp_get_settings_tabs(); $active_tab = isset( $_GET['tab'] ) && array_key_exists( $_GET['tab'], $settings_array[$page] ) ? $_GET['tab'] : 'main'; ?>

1) { ?>
get_general_general_content(); } elseif ($subtab == 'shortcodes') { $this->get_general_shortcodes_content(); } elseif ($subtab == 'info') { $this->get_general_info_content(); } } //main tabs public function uwp_get_pages_as_option($selected) { $page_options = uwp_get_pages(); foreach ($page_options as $key => $page_title) { ?>
[uwp_profile]
[uwp_register]
[uwp_login]
[uwp_account]
[uwp_forgot]
[uwp_change]
[uwp_reset]
[uwp_users]

', ''); ?>

', ''); ?>

form_builder->uwp_form_builder($tab); if ($tab == 'account') { ?>

[#site_name_url#],[#site_name#],[#to_name#],[#from_name#],[#login_url#],[#user_name#],[#from_email#],[#user_login#],[#username#],[#current_date#],[#login_details#],[#reset_link#],[#activation_link#]
uwp_get_registered_settings() as $tab => $settings ) { foreach ( $settings as $key => $opt ) { add_settings_section( 'uwp_settings_' . $tab .'_'.$key, __return_null(), '__return_false', 'uwp_settings_' . $tab .'_'.$key ); foreach ($opt as $option) { $name = isset( $option['name'] ) ? $option['name'] : ''; add_settings_field( 'uwp_settings[' . $option['id'] . ']', $name, method_exists($callback, 'uwp_' . $option['type'] . '_callback') ? array($callback, 'uwp_' . $option['type'] . '_callback') : array($callback, 'uwp_missing_callback'), 'uwp_settings_' . $tab .'_'.$key, 'uwp_settings_' . $tab .'_'.$key, array( 'section' => $tab, 'id' => isset( $option['id'] ) ? $option['id'] : null, 'class' => isset( $option['class'] ) ? $option['class'] : null, 'desc' => ! empty( $option['desc'] ) ? $option['desc'] : '', 'name' => isset( $option['name'] ) ? $option['name'] : null, 'size' => isset( $option['size'] ) ? $option['size'] : null, 'options' => isset( $option['options'] ) ? $option['options'] : '', 'std' => isset( $option['std'] ) ? $option['std'] : '', 'min' => isset( $option['min'] ) ? $option['min'] : null, 'max' => isset( $option['max'] ) ? $option['max'] : null, 'step' => isset( $option['step'] ) ? $option['step'] : null, 'chosen' => isset( $option['chosen'] ) ? $option['chosen'] : null, 'placeholder' => isset( $option['placeholder'] ) ? $option['placeholder'] : null, 'allow_blank' => isset( $option['allow_blank'] ) ? $option['allow_blank'] : true, 'readonly' => isset( $option['readonly'] ) ? $option['readonly'] : false, 'faux' => isset( $option['faux'] ) ? $option['faux'] : false, 'global' => isset( $setting['global'] ) ? $setting['global'] : true, 'multiple' => isset( $option['multiple'] ) ? $option['multiple'] : false, ) ); } } } // Creates our settings in the options table register_setting( 'uwp_settings', 'uwp_settings', array($this, 'uwp_settings_sanitize') ); } public function uwp_get_registered_settings() { $file_obj = new UsersWP_Files(); /** * 'Whitelisted' uwp settings, filters are provided for each settings * section to allow extensions and other plugins to add their own settings */ $uwp_settings = array( /** General Settings */ 'userswp' => array( 'main' => apply_filters( 'uwp_settings_general_main', array( 'profile_page' => array( 'id' => 'profile_page', 'name' => __( 'User Profile Page', 'userswp' ), 'desc' => __( 'This is the front end user\'s profile page. This page automatically overrides the default WordPress author page.', 'userswp' ), 'type' => 'select', 'options' => uwp_get_pages(), 'chosen' => true, 'placeholder' => __( 'Select a page', 'userswp' ), 'class' => 'uwp_label_block', ), 'register_page' => array( 'id' => 'register_page', 'name' => __( 'Register Page', 'userswp' ), 'desc' => __( 'This is the front end register page. This is where users create their account.', 'userswp' ), 'type' => 'select', 'options' => uwp_get_pages(), 'chosen' => true, 'placeholder' => __( 'Select a page', 'userswp' ), 'class' => 'uwp_label_block', ), 'login_page' => array( 'id' => 'login_page', 'name' => __( 'Login Page', 'userswp' ), 'desc' => __( 'This is the front end login page. This is where users will login after creating their account.', 'userswp' ), 'type' => 'select', 'options' => uwp_get_pages(), 'chosen' => true, 'placeholder' => __( 'Select a page', 'userswp' ), 'class' => 'uwp_label_block', ), 'account_page' => array( 'id' => 'account_page', 'name' => __( 'Account Page', 'userswp' ), 'desc' => __( 'This is the front end account page. This is where users can edit their account.', 'userswp' ), 'type' => 'select', 'options' => uwp_get_pages(), 'chosen' => true, 'placeholder' => __( 'Select a page', 'userswp' ), 'class' => 'uwp_label_block', ), 'change_page' => array( 'id' => 'change_page', 'name' => __( 'Change Password Page', 'userswp' ), 'desc' => __( 'This is the front end Change Password page.', 'userswp' ), 'type' => 'select', 'options' => uwp_get_pages(), 'chosen' => true, 'placeholder' => __( 'Select a page', 'userswp' ), 'class' => 'uwp_label_block', ), 'forgot_page' => array( 'id' => 'forgot_page', 'name' => __( 'Forgot Password Page', 'userswp' ), 'desc' => __( 'This is the front end Forgot Password page. This is the page where users are sent to reset their password when they lose it.', 'userswp' ), 'type' => 'select', 'options' => uwp_get_pages(), 'chosen' => true, 'placeholder' => __( 'Select a page', 'userswp' ), 'class' => 'uwp_label_block', ), 'reset_page' => array( 'id' => 'reset_page', 'name' => __( 'Reset Password Page', 'userswp' ), 'desc' => __( 'This is the front end Reset Password page. This is the page where users can reset their password when they lose it.', 'userswp' ), 'type' => 'select', 'options' => uwp_get_pages(), 'chosen' => true, 'placeholder' => __( 'Select a page', 'userswp' ), 'class' => 'uwp_label_block', ), 'users_page' => array( 'id' => 'users_page', 'name' => __( 'Users List Page', 'userswp' ), 'desc' => __( 'This is the front end Users List page. This is the page where all registered users of the websites are listed.', 'userswp' ), 'type' => 'select', 'options' => uwp_get_pages(), 'chosen' => true, 'placeholder' => __( 'Select a page', 'userswp' ), 'class' => 'uwp_label_block', ), 'profile_no_of_items' => array( 'id' => 'profile_no_of_items', 'name' => __( 'Number of Items', 'userswp' ), 'type' => 'text', 'std' => '', 'desc' => __( 'Enter number of items to display in profile tabs.', 'userswp' ), ), ) ), 'register' => apply_filters( 'uwp_settings_general_register', uwp_settings_general_register_fields()), 'login' => apply_filters( 'uwp_settings_general_login', uwp_settings_general_loginout_fields()), 'profile' => apply_filters( 'uwp_settings_general_profile', array( 'enable_profile_header' => array( 'id' => 'enable_profile_header', 'name' => __( 'Display Header in Profile', 'userswp' ), 'desc' => '', 'type' => 'checkbox', 'std' => '1', 'class' => 'uwp_label_inline', ), 'profile_avatar_size' => array( 'id' => 'profile_avatar_size', 'name' => __( 'Profile Avatar max file size', 'userswp' ), 'desc' => sprintf(__( 'Enter Profile Avatar max file size in Kb. e.g. 512 for 512 kb, 1024 for 1 Mb, 2048 for 2 Mb etc. If empty WordPress default (%s) will be used.', 'userswp' ), ''.$file_obj->uwp_formatSizeinKb($file_obj->uwp_get_max_upload_size()).''), 'type' => 'number', 'std' => '', 'size' => 'regular', 'placeholder' => __( 'Enter Profile Avatar max file size.', 'userswp' ), ), 'profile_banner_size' => array( 'id' => 'profile_banner_size', 'name' => __( 'Profile Banner max file size', 'userswp' ), 'desc' => sprintf(__( 'Enter Profile Banner max file size in Kb. e.g. 512 for 512 kb, 1024 for 1 Mb, 2048 for 2 Mb etc. If empty WordPress default (%s) will be used.', 'userswp' ), ''.$file_obj->uwp_formatSizeinKb($file_obj->uwp_get_max_upload_size()).''), 'type' => 'number', 'std' => '', 'size' => 'regular', 'placeholder' => __( 'Enter Profile Banner max file size.', 'userswp' ), ), 'profile_banner_width' => array( 'id' => 'profile_banner_width', 'name' => __( 'Profile banner width', 'userswp' ), 'desc' => '', 'type' => 'number', 'std' => '1000', 'size' => 'regular', 'placeholder' => __( 'Enter Profile banner width in Pixels', 'userswp' ), ), 'profile_default_banner' => array( 'id' => 'profile_default_banner', 'name' => __( 'Default banner image', 'userswp' ), 'desc' => __( 'Recommended image size: 1000x300', 'userswp'), 'type' => 'media', 'std' => '', 'placeholder' => USERSWP_PLUGIN_URL."public/assets/images/banner.png" ), 'profile_default_profile' => array( 'id' => 'profile_default_profile', 'name' => __( 'Default profile image', 'userswp' ), 'desc' => __( 'Recommended image size: 150x150', 'userwp'), 'type' => 'media', 'std' => '', 'placeholder' => USERSWP_PLUGIN_URL."public/assets/images/no_profile.png" ), 'enable_profile_body' => array( 'id' => 'enable_profile_body', 'name' => __( 'Display Body in Profile', 'userswp' ), 'desc' => '', 'type' => 'checkbox', 'std' => '1', 'class' => 'uwp_label_inline', ), 'enable_profile_tabs' => array( 'id' => 'enable_profile_tabs', 'name' => __( 'Choose the tabs to display in Profile', 'userswp' ), 'desc' => __( 'Choose the tabs to display in UsersWP Profile', 'userswp' ), 'multiple' => true, 'chosen' => true, 'type' => 'select_order', 'options' => $this->uwp_available_tab_items(), 'placeholder' => __( 'Select Tabs', 'userswp' ) ), ) ), 'users' => apply_filters( 'uwp_settings_general_profile', array( 'users_default_layout' => array( 'id' => 'users_default_layout', 'name' => __( 'Users default layout', 'userswp' ), 'desc' => __( 'Choose the default layout for Users Page - Users List', 'userswp' ), 'type' => 'select', 'options' => $this->uwp_available_users_layout(), 'placeholder' => __( 'Select Layout', 'userswp' ) ), 'users_excluded_from_list' => array( 'id' => 'users_excluded_from_list', 'name' => __( 'Users to exclude', 'userswp' ), 'type' => 'text', 'std' => '', 'desc' => __( 'Enter comma separated ids of users to exclude from users listing.', 'userswp' ), ), ) ), 'change' => apply_filters( 'uwp_settings_general_change', array( 'change_enable_old_password' => array( 'id' => 'change_enable_old_password', 'name' => __( 'Enabled Old Password?', 'userswp' ), 'desc' => 'This option adds an extra layer of security. User need to enter their old password before changing the password.', 'type' => 'checkbox', 'std' => '1', 'class' => 'uwp_label_inline', ), 'change_disable_password_nag' => array( 'id' => 'change_disable_password_nag', 'name' => __( 'Disable system generated password notice.', 'userswp' ), 'desc' => 'This option will disable system generated password notice if user has not changed default password after registration.', 'type' => 'checkbox', 'std' => '0', 'class' => 'uwp_label_inline', ), ) ), 'uninstall' => apply_filters( 'uwp_settings_general_uninstall', array( 'uninstall_erase_data' => array( 'id' => 'uninstall_erase_data', 'name' => __( 'UsersWP', 'userswp' ), 'desc' => __( 'Remove all data when deleted?', 'userswp' ), 'type' => 'checkbox', 'std' => '1', 'class' => 'uwp_label_inline', ), ) ), ), 'uwp_notifications' => array( 'main' => apply_filters( 'uwp_settings_notifications_main', array( 'registration_activate_email_subject' => array( 'id' => 'registration_activate_email_subject', 'name' => __( 'Registration activate email', 'userswp' ), 'desc' => "", 'type' => 'text', 'size' => 'regular', 'placeholder' => __( 'Enter Registration activate email Subject', 'userswp' ) ), 'registration_activate_email_content' => array( 'id' => 'registration_activate_email_content', 'name' => "", 'desc' => "", 'type' => 'textarea', 'placeholder' => __( 'Enter Registration activate email Content', 'userswp' ) ), 'registration_success_email_subject' => array( 'id' => 'registration_success_email_subject', 'name' => __( 'Registration success email', 'userswp' ), 'desc' => "", 'type' => 'text', 'size' => 'regular', 'placeholder' => __( 'Enter Registration success email Subject', 'userswp' ) ), 'registration_success_email_content' => array( 'id' => 'registration_success_email_content', 'name' => "", 'desc' => "", 'type' => 'textarea', 'placeholder' => __( 'Enter Registration success email Content', 'userswp' ) ), 'forgot_password_email_subject' => array( 'id' => 'forgot_password_email_subject', 'name' => __( 'Forgot password email', 'userswp' ), 'desc' => "", 'type' => 'text', 'size' => 'regular', 'placeholder' => __( 'Enter forgot password email Subject', 'userswp' ) ), 'forgot_password_email_content' => array( 'id' => 'forgot_password_email_content', 'name' => "", 'desc' => "", 'type' => 'textarea', 'placeholder' => __( 'Enter forgot password email Content', 'userswp' ) ), 'change_password_email_subject' => array( 'id' => 'change_password_email_subject', 'name' => __( 'Change password email', 'userswp' ), 'desc' => "", 'type' => 'text', 'size' => 'regular', 'placeholder' => __( 'Enter change password email Subject', 'userswp' ) ), 'change_password_email_content' => array( 'id' => 'change_password_email_content', 'name' => "", 'desc' => "", 'type' => 'textarea', 'placeholder' => __( 'Enter change password email Content', 'userswp' ) ), 'reset_password_email_subject' => array( 'id' => 'reset_password_email_subject', 'name' => __( 'Reset password email', 'userswp' ), 'desc' => "", 'type' => 'text', 'size' => 'regular', 'placeholder' => __( 'Enter reset password email Subject', 'userswp' ) ), 'reset_password_email_content' => array( 'id' => 'reset_password_email_content', 'name' => "", 'desc' => "", 'type' => 'textarea', 'placeholder' => __( 'Enter reset password email Content', 'userswp' ) ), 'enable_account_update_notification' => array( 'id' => 'enable_account_update_notification', 'name' => __( 'Account update email', 'userswp' ), 'desc' => 'Enable account update notification', 'type' => 'checkbox', 'std' => '0', 'class' => 'uwp_label_inline', ), 'account_update_email_subject' => array( 'id' => 'account_update_email_subject', 'name' => "", 'desc' => "", 'type' => 'text', 'size' => 'regular', 'placeholder' => __( 'Enter account update email Subject', 'userswp' ) ), 'account_update_email_content' => array( 'id' => 'account_update_email_content', 'name' => "", 'desc' => "", 'type' => 'textarea', 'placeholder' => __( 'Enter account update email Content', 'userswp' ) ), ) ), 'admin' => apply_filters( 'uwp_settings_notifications_admin', array( 'registration_success_email_subject_admin' => array( 'id' => 'registration_success_email_subject_admin', 'name' => __( 'New account registration', 'userswp' ), 'desc' => "", 'type' => 'text', 'std' => __( 'New account registration', 'userswp' ), 'size' => 'regular', ), 'registration_success_email_content_admin' => array( 'id' => 'registration_success_email_content_admin', 'name' => "", 'desc' => "", 'type' => 'textarea', 'std' => __("A user has been registered recently on your website. [#extras#]", "userswp"), ), ) ), ), ); $uwp_settings = apply_filters( 'uwp_registered_settings', $uwp_settings ); return $uwp_settings; } public function uwp_get_settings() { $settings = get_option( 'uwp_settings' ); if( empty( $settings ) ) { // Update old settings with new single option $general_settings = is_array( get_option( 'uwp_settings_general' ) ) ? get_option( 'uwp_settings_general' ) : array(); $ext_settings = is_array( get_option( 'uwp_settings_extensions' ) ) ? get_option( 'uwp_settings_extensions' ) : array(); $settings = array_merge( $general_settings, $ext_settings ); update_option( 'uwp_settings', $settings ); } return apply_filters( 'uwp_get_settings', $settings ); } public function uwp_settings_sanitize( $input = array() ) { global $uwp_options; if ( empty( $_POST['_wp_http_referer'] ) ) { return $input; } $parsed_url = wp_parse_url($_POST['_wp_http_referer']); if (!isset($parsed_url['query'])) { return $input; } parse_str( $parsed_url['query'], $referrer ); $settings = $this->uwp_get_registered_settings(); $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'main'; $page = isset( $referrer['page'] ) ? $referrer['page'] : 'userswp'; $input = $input ? $input : array(); $input = apply_filters( 'uwp_settings_'.$page.'_' . $tab . '_sanitize', $input ); // Loop through each setting being saved and pass it through a sanitization filter foreach ( $input as $key => $value ) { // Get the setting type (checkbox, select, etc) $type = isset( $settings[$page][$tab][$key]['type'] ) ? $settings[$page][$tab][$key]['type'] : false; if ( $type ) { // Field type specific filter $input[$key] = apply_filters( 'uwp_settings_sanitize_' . $type, $value, $key ); } // General filter $input[$key] = apply_filters( 'uwp_settings_sanitize', $input[$key], $key ); } // Loop through the whitelist and unset any that are empty for the tab being saved if ( ! empty( $settings[$page][$tab] ) ) { foreach ( $settings[$page][$tab] as $key => $value ) { // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work if ( is_numeric( $key ) ) { $key = $value['id']; } if ( empty( $input[$key] ) ) { unset( $uwp_options[$key] ); } } } // Merge our new settings with the existing $output = array_merge( $uwp_options, $input ); flush_rewrite_rules(); add_settings_error( 'uwp-notices', '', __( 'Settings updated.', 'userswp' ), 'updated' ); return $output; } public function uwp_available_tab_items() { $tabs_arr = array( 'more_info' => __( 'More Info', 'userswp' ), 'posts' => __( 'Posts', 'userswp' ), 'comments' => __( 'Comments', 'userswp' ), ); $tabs_arr = apply_filters('uwp_available_tab_items', $tabs_arr); return $tabs_arr; } public function uwp_available_users_layout() { $tabs_arr = array( 'list' => __( 'List View', 'userswp' ), '2col' => __( 'Grid View - 2 Column', 'userswp' ), '3col' => __( 'Grid View - 3 Column', 'userswp' ), '4col' => __( 'Grid View - 4 Column', 'userswp' ), '5col' => __( 'Grid View - 5 Column', 'userswp' ), ); $tabs_arr = apply_filters('uwp_available_users_layout', $tabs_arr); return $tabs_arr; } }