page_id = 'advanced_settings'; $this->init_constants(); } public static function instance() { if(is_null(self::$_instance)){ self::$_instance = new self(); } return self::$_instance; } public function init_constants(){ $this->cell_props = array( 'label_cell_props' => 'class="label"', 'input_cell_props' => 'class="field"', 'input_width' => '260px', 'label_cell_th' => true ); $this->cell_props_TA = array( 'label_cell_props' => 'class="label"', 'input_cell_props' => 'class="field"', 'rows' => 10, 'cols' => 100, ); $this->cell_props_CB = array( 'label_props' => 'style="margin-right: 40px;"', ); $this->settings_fields = $this->get_advanced_settings_fields(); } public function get_advanced_settings_fields(){ return array( 'enable_label_override' => array( 'name'=>'enable_label_override', 'label'=>__('Enable label override for address fields.', 'woo-checkout-field-editor-pro'), 'type'=>'checkbox', 'value'=>'1', 'checked'=>1 ), 'enable_placeholder_override' => array( 'name'=>'enable_placeholder_override', 'label'=>__('Enable placeholder override for address fields.', 'woo-checkout-field-editor-pro'), 'type'=>'checkbox', 'value'=>'1', 'checked'=>1 ), 'enable_class_override' => array( 'name'=>'enable_class_override', 'label'=>__('Enable class override for address fields.', 'woo-checkout-field-editor-pro'), 'type'=>'checkbox', 'value'=>'1', 'checked'=>1 ), 'enable_priority_override' => array( 'name'=>'enable_priority_override', 'label'=>__('Enable priority override for address fields.', 'woo-checkout-field-editor-pro'), 'type'=>'checkbox', 'value'=>'1', 'checked'=>1 ), 'enable_required_override' => array( 'name'=>'enable_required_override', 'label'=>__('Enable required validation override for address fields.', 'woo-checkout-field-editor-pro'), 'type'=>'checkbox', 'value'=>'1', 'checked'=>1 ), ); } public function render_page(){ $this->render_tabs(); $this->render_content(); } public function save_advanced_settings($settings){ $result = update_option(THWCFD_Utils::OPTION_KEY_ADVANCED_SETTINGS, $settings, 'no'); return $result; } private function reset_settings(){ $nonse = isset($_REQUEST['thwcfd_security_advanced_settings']) ? $_REQUEST['thwcfd_security_advanced_settings'] : false; $capability = THWCFD_Utils::wcfd_capability(); if(!wp_verify_nonce($nonse, 'thwcfd_advanced_settings') || !current_user_can($capability)){ die(); } delete_option(THWCFD_Utils::OPTION_KEY_ADVANCED_SETTINGS); $this->print_notices(__('Settings successfully reset.', 'woo-checkout-field-editor-pro'), 'updated', false); } private function save_settings(){ $nonse = isset($_REQUEST['thwcfd_security_advanced_settings']) ? $_REQUEST['thwcfd_security_advanced_settings'] : false; $capability = THWCFD_Utils::wcfd_capability(); if(!wp_verify_nonce($nonse, 'thwcfd_advanced_settings') || !current_user_can($capability)){ die(); } $settings = array(); foreach( $this->settings_fields as $name => $field ) { $value = ''; if($field['type'] === 'checkbox'){ $value = !empty( $_POST['i_'.$name] ) ? '1' : ''; }else if($field['type'] === 'multiselect_grouped'){ $value = !empty( $_POST['i_'.$name] ) ? $_POST['i_'.$name] : ''; $value = is_array($value) ? implode(',', wc_clean(wp_unslash($value))) : wc_clean(wp_unslash($value)); }else if($field['type'] === 'text' || $field['type'] === 'textarea'){ $value = !empty( $_POST['i_'.$name] ) ? $_POST['i_'.$name] : ''; $value = !empty($value) ? wc_clean( wp_unslash($value)) : ''; }else{ $value = !empty( $_POST['i_'.$name] ) ? $_POST['i_'.$name] : ''; $value = !empty($value) ? wc_clean( wp_unslash($value)) : ''; } $settings[$name] = $value; } $result = $this->save_advanced_settings($settings); if ($result == true) { $this->print_notices(__('Your changes were saved.', 'woo-checkout-field-editor-pro'), 'updated', false); } else { $this->print_notices(__('Your changes were not saved due to an error (or you made none!).', 'woo-checkout-field-editor-pro'), 'error', false); } } private function render_content(){ if(isset($_POST['reset_settings'])) $this->reset_settings(); if(isset($_POST['save_settings'])) $this->save_settings(); if(isset($_POST['save_plugin_settings'])) $result = $this->save_plugin_settings(); $this->render_plugin_settings(); $this->render_import_export_settings(); } private function render_plugin_settings(){ $settings = THWCFD_Utils::get_advanced_settings(); ?>