method_title ) ) ? $this->method_title : __( 'Settings', 'woocommerce' ) ; ?>

method_description ) ) ? wpautop( $this->method_description ) : ''; ?> generate_settings_html(); ?>
id, $this->form_fields ); } /** * Admin Panel Options Processing. * - Saves the options to the DB. * * @since 1.0.0 * @return bool */ public function process_admin_options() { $this->validate_settings_fields(); if ( count( $this->errors ) > 0 ) { $this->display_errors(); return false; } else { update_option( $this->plugin_id . $this->id . '_settings', apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->sanitized_fields ) ); $this->init_settings(); return true; } } /** * Display admin error messages. * * @since 1.0.0 */ public function display_errors() {} /** * Initialise Gateway Settings. * * Store all settings in a single database entry * and make sure the $settings array is either the default * or the settings stored in the database. * * @since 1.0.0 * @uses get_option(), add_option() */ public function init_settings() { // Load form_field settings. $this->settings = get_option( $this->plugin_id . $this->id . '_settings', null ); if ( ! $this->settings || ! is_array( $this->settings ) ) { $this->settings = array(); // If there are no settings defined, load defaults. if ( $form_fields = $this->get_form_fields() ) { foreach ( $form_fields as $k => $v ) { $this->settings[ $k ] = isset( $v['default'] ) ? $v['default'] : ''; } } } if ( ! empty( $this->settings ) && is_array( $this->settings ) ) { $this->settings = array_map( array( $this, 'format_settings' ), $this->settings ); $this->enabled = isset( $this->settings['enabled'] ) && $this->settings['enabled'] == 'yes' ? 'yes' : 'no'; } } /** * get_option function. * * Gets and option from the settings API, using defaults if necessary to prevent undefined notices. * * @param string $key * @param mixed $empty_value * @return mixed The value specified for the option or a default value for the option. */ public function get_option( $key, $empty_value = null ) { if ( empty( $this->settings ) ) { $this->init_settings(); } // Get option default if unset. if ( ! isset( $this->settings[ $key ] ) ) { $form_fields = $this->get_form_fields(); $this->settings[ $key ] = isset( $form_fields[ $key ]['default'] ) ? $form_fields[ $key ]['default'] : ''; } if ( ! is_null( $empty_value ) && empty( $this->settings[ $key ] ) && '' === $this->settings[ $key ] ) { $this->settings[ $key ] = $empty_value; } return $this->settings[ $key ]; } /** * Prefix key for settings. * * @param mixed $key * @return string */ public function get_field_key( $key ) { return $this->plugin_id . $this->id . '_' . $key; } /** * Decode values for settings. * * @param mixed $value * @return array */ public function format_settings( $value ) { return is_array( $value ) ? $value : $value; } /** * Generate Settings HTML. * * Generate the HTML for the fields on the "settings" screen. * * @param array $form_fields (default: array()) * @since 1.0.0 * @uses method_exists() * @return string the html for the settings */ public function generate_settings_html( $form_fields = array() ) { if ( empty( $form_fields ) ) { $form_fields = $this->get_form_fields(); } $html = ''; foreach ( $form_fields as $k => $v ) { if ( ! isset( $v['type'] ) || ( $v['type'] == '' ) ) { $v['type'] = 'text'; // Default to "text" field type. } if ( method_exists( $this, 'generate_' . $v['type'] . '_html' ) ) { $html .= $this->{'generate_' . $v['type'] . '_html'}( $k, $v ); } else { $html .= $this->{'generate_text_html'}( $k, $v ); } } echo $html; } /** * Get HTML for tooltips. * * @param array $data * @return string */ public function get_tooltip_html( $data ) { if ( $data['desc_tip'] === true ) { $tip = $data['description']; } elseif ( ! empty( $data['desc_tip'] ) ) { $tip = $data['desc_tip']; } else { $tip = ''; } return $tip ? wc_help_tip( $tip, true ) : ''; } /** * Get HTML for descriptions. * * @param array $data * @return string */ public function get_description_html( $data ) { if ( $data['desc_tip'] === true ) { $description = ''; } elseif ( ! empty( $data['desc_tip'] ) ) { $description = $data['description']; } elseif ( ! empty( $data['description'] ) ) { $description = $data['description']; } else { $description = ''; } return $description ? '

' . wp_kses_post( $description ) . '

' . "\n" : ''; } /** * Get custom attributes. * * @param array $data * @return string */ public function get_custom_attribute_html( $data ) { $custom_attributes = array(); if ( ! empty( $data['custom_attributes'] ) && is_array( $data['custom_attributes'] ) ) { foreach ( $data['custom_attributes'] as $attribute => $attribute_value ) { $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"'; } } return implode( ' ', $custom_attributes ); } /** * Generate Text Input HTML. * * @param mixed $key * @param mixed $data * @since 1.0.0 * @return string */ public function generate_text_html( $key, $data ) { $field = $this->get_field_key( $key ); $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', 'css' => '', 'placeholder' => '', 'type' => 'text', 'desc_tip' => false, 'description' => '', 'custom_attributes' => array() ); $data = wp_parse_args( $data, $defaults ); ob_start(); ?> get_tooltip_html( $data ); ?>
get_custom_attribute_html( $data ); ?> /> get_description_html( $data ); ?>
get_field_key( $key ); $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', 'css' => '', 'placeholder' => '', 'type' => 'text', 'desc_tip' => false, 'description' => '', 'custom_attributes' => array() ); $data = wp_parse_args( $data, $defaults ); ob_start(); ?> get_tooltip_html( $data ); ?>
get_custom_attribute_html( $data ); ?> /> get_description_html( $data ); ?>
get_field_key( $key ); $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', 'css' => '', 'placeholder' => '', 'type' => 'text', 'desc_tip' => false, 'description' => '', 'custom_attributes' => array() ); $data = wp_parse_args( $data, $defaults ); ob_start(); ?> get_tooltip_html( $data ); ?>
get_custom_attribute_html( $data ); ?> /> get_description_html( $data ); ?>
generate_text_html( $key, $data ); } /** * Generate Color Picker Input HTML. * * @param mixed $key * @param mixed $data * @since 1.0.0 * @return string */ public function generate_color_html( $key, $data ) { $field = $this->get_field_key( $key ); $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', 'css' => '', 'placeholder' => '', 'desc_tip' => false, 'description' => '', 'custom_attributes' => array() ); $data = wp_parse_args( $data, $defaults ); ob_start(); ?> get_tooltip_html( $data ); ?>
get_custom_attribute_html( $data ); ?> /> get_description_html( $data ); ?>
get_field_key( $key ); $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', 'css' => '', 'placeholder' => '', 'type' => 'text', 'desc_tip' => false, 'description' => '', 'custom_attributes' => array() ); $data = wp_parse_args( $data, $defaults ); ob_start(); ?> get_tooltip_html( $data ); ?>
get_description_html( $data ); ?>
get_field_key( $key ); $defaults = array( 'title' => '', 'label' => '', 'disabled' => false, 'class' => '', 'css' => '', 'type' => 'text', 'desc_tip' => false, 'description' => '', 'custom_attributes' => array() ); $data = wp_parse_args( $data, $defaults ); if ( ! $data['label'] ) { $data['label'] = $data['title']; } ob_start(); ?> get_tooltip_html( $data ); ?>

get_description_html( $data ); ?>
get_field_key( $key ); $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', 'css' => '', 'placeholder' => '', 'type' => 'text', 'desc_tip' => false, 'description' => '', 'custom_attributes' => array(), 'options' => array() ); $data = wp_parse_args( $data, $defaults ); ob_start(); ?> get_tooltip_html( $data ); ?>
get_description_html( $data ); ?>
get_field_key( $key ); $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', 'css' => '', 'placeholder' => '', 'type' => 'text', 'desc_tip' => false, 'description' => '', 'custom_attributes' => array(), 'options' => array() ); $data = wp_parse_args( $data, $defaults ); $value = (array) $this->get_option( $key, array() ); ob_start(); ?> get_tooltip_html( $data ); ?>
get_description_html( $data ); ?>
get_field_key( $key ); $defaults = array( 'title' => '', 'class' => '' ); $data = wp_parse_args( $data, $defaults ); ob_start(); ?>

get_form_fields(); } $this->sanitized_fields = array(); foreach ( $form_fields as $key => $field ) { // Default to "text" field type. $type = empty( $field['type'] ) ? 'text' : $field['type']; // Look for a validate_FIELDID_field method for special handling if ( method_exists( $this, 'validate_' . $key . '_field' ) ) { $field = $this->{'validate_' . $key . '_field'}( $key ); // Exclude certain types from saving } elseif ( in_array( $type, array( 'title' ) ) ) { continue; // Look for a validate_FIELDTYPE_field method } elseif ( method_exists( $this, 'validate_' . $type . '_field' ) ) { $field = $this->{'validate_' . $type . '_field'}( $key ); // Fallback to text } else { $field = $this->validate_text_field( $key ); } $this->sanitized_fields[ $key ] = $field; } } /** * Validate Text Field. * * Make sure the data is escaped correctly, etc. * * @param mixed $key * @return string */ public function validate_text_field( $key ) { $text = $this->get_option( $key ); $field = $this->get_field_key( $key ); if ( isset( $_POST[ $field ] ) ) { $text = wp_kses_post( trim( stripslashes( $_POST[ $field ] ) ) ); } return $text; } /** * Validate Price Field. * * Make sure the data is escaped correctly, etc. * * @param mixed $key * @return string */ public function validate_price_field( $key ) { $text = $this->get_option( $key ); $field = $this->get_field_key( $key ); if ( isset( $_POST[ $field ] ) ) { if ( $_POST[ $field ] !== '' ) { $text = wc_format_decimal( trim( stripslashes( $_POST[ $field ] ) ) ); } else { $text = ''; } } return $text; } /** * Validate Decimal Field. * * Make sure the data is escaped correctly, etc. * * @param mixed $key * @return string */ public function validate_decimal_field( $key ) { $text = $this->get_option( $key ); $field = $this->get_field_key( $key ); if ( isset( $_POST[ $field ] ) ) { if ( $_POST[ $field ] !== '' ) { $text = wc_format_decimal( trim( stripslashes( $_POST[ $field ] ) ) ); } else { $text = ''; } } return $text; } /** * Validate Password Field. * * Make sure the data is escaped correctly, etc. * * @param mixed $key * @since 1.0.0 * @return string */ public function validate_password_field( $key ) { $field = $this->get_field_key( $key ); $value = wp_kses_post( trim( stripslashes( $_POST[ $field ] ) ) ); return $value; } /** * Validate Textarea Field. * * Make sure the data is escaped correctly, etc. * * @param mixed $key * @since 1.0.0 * @return string */ public function validate_textarea_field( $key ) { $text = $this->get_option( $key ); $field = $this->get_field_key( $key ); if ( isset( $_POST[ $field ] ) ) { $text = wp_kses( trim( stripslashes( $_POST[ $field ] ) ), array_merge( array( 'iframe' => array( 'src' => true, 'style' => true, 'id' => true, 'class' => true ) ), wp_kses_allowed_html( 'post' ) ) ); } return $text; } /** * Validate Checkbox Field. * * If not set, return "no", otherwise return "yes". * * @param mixed $key * @since 1.0.0 * @return string */ public function validate_checkbox_field( $key ) { $status = 'no'; $field = $this->get_field_key( $key ); if ( isset( $_POST[ $field ] ) && ( 1 == $_POST[ $field ] ) ) { $status = 'yes'; } return $status; } /** * Validate Select Field. * * Make sure the data is escaped correctly, etc. * * @param mixed $key * @since 1.0.0 * @return string */ public function validate_select_field( $key ) { $value = $this->get_option( $key ); $field = $this->get_field_key( $key ); if ( isset( $_POST[ $field ] ) ) { $value = wc_clean( stripslashes( $_POST[ $field ] ) ); } return $value; } /** * Validate Multiselect Field. * * Make sure the data is escaped correctly, etc. * * @param mixed $key * @since 1.0.0 * @return string */ public function validate_multiselect_field( $key ) { $field = $this->get_field_key( $key ); if ( isset( $_POST[ $field ] ) ) { $value = array_map( 'wc_clean', array_map( 'stripslashes', (array) $_POST[ $field ] ) ); } else { $value = ''; } return $value; } }