method_title ) ) ? $this->method_title : __( 'Settings', 'woocommerce' ) ; ?>
method_description ) ) ? wpautop( $this->method_description ) : ''; ?>
validate_settings_fields();
if ( count( $this->errors ) > 0 ) {
$this->display_errors();
return false;
} else {
update_option( $this->plugin_id . $this->id . '_settings', $this->sanitized_fields );
return true;
}
}
/**
* Display admin error messages.
*
* @since 1.0.0
* @access public
* @return void
*/
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()
* @access public
* @return void
*/
public function init_settings() {
if ( ! empty( $this->settings ) )
return;
// 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 ( $this->form_fields )
foreach ( $this->form_fields as $k => $v )
$this->settings[ $k ] = isset( $v['default'] ) ? $v['default'] : '';
}
if ( $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 neccessary to prevent undefined notices.
*
* @access public
* @param mixed $key
* @param mixed $empty_value
* @return void
*/
public function get_option( $key, $empty_value = '' ) {
if ( empty( $this->settings ) )
$this->init_settings();
// Get option default if unset
if ( ! isset( $this->settings[ $key ] ) ) {
$this->settings[ $key ] = isset( $this->form_fields[ $key ]['default'] ) ? $this->form_fields[ $key ]['default'] : '';
}
if ( empty( $this->settings[ $key ] ) )
$this->settings[ $key ] = $empty_value;
return $this->settings[ $key ];
}
/**
* Decode values for settings.
*
* @access public
* @param mixed $value
* @return array
*/
public function format_settings( $value ) {
return ( is_array( $value ) ) ? $value : html_entity_decode( $value );
}
/**
* Generate Settings HTML.
*
* Generate the HTML for the fields on the "settings" screen.
*
* @access public
* @param bool $form_fields (default: false)
* @since 1.0.0
* @uses method_exists()
* @access public
* @return string the html for the settings
*/
public function generate_settings_html ( $form_fields = false ) {
if ( ! $form_fields ) {
$form_fields = $this->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;
}
/**
* Generate Text Input HTML.
*
* @access public
* @param mixed $key
* @param mixed $data
* @since 1.0.0
* @return string
*/
public function generate_text_html( $key, $data ) {
global $woocommerce;
$html = '';
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
$data['disabled'] = empty( $data['disabled'] ) ? false : true;
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$data['placeholder'] = isset( $data['placeholder'] ) ? $data['placeholder'] : '';
$data['type'] = isset( $data['type'] ) ? $data['type'] : 'text';
$data['desc_tip'] = isset( $data['desc_tip'] ) ? $data['desc_tip'] : false;
$data['description'] = isset( $data['description'] ) ? $data['description'] : '';
// Description handling
if ( $data['desc_tip'] === true ) {
$description = '';
$tip = $data['description'];
} elseif ( ! empty( $data['desc_tip'] ) ) {
$description = $data['description'];
$tip = $data['desc_tip'];
} elseif ( ! empty( $data['description'] ) ) {
$description = $data['description'];
$tip = '';
} else {
$description = $tip = '';
}
// Custom attribute handling
$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 ) . '"';
$html .= '' . "\n";
$html .= '';
$html .= '';
if ( $tip )
$html .= '';
$html .= ' | ' . "\n";
$html .= '' . "\n";
$html .= '';
$html .= ' | ' . "\n";
$html .= '
' . "\n";
return $html;
}
/**
* Generate Password Input HTML.
*
* @access public
* @param mixed $key
* @param mixed $data
* @since 1.0.0
* @return string
*/
public function generate_password_html( $key, $data ) {
global $woocommerce;
$html = '';
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
$data['disabled'] = empty( $data['disabled'] ) ? false : true;
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$data['desc_tip'] = isset( $data['desc_tip'] ) ? $data['desc_tip'] : false;
$data['description'] = isset( $data['description'] ) ? $data['description'] : '';
// Description handling
if ( $data['desc_tip'] === true ) {
$description = '';
$tip = $data['description'];
} elseif ( ! empty( $data['desc_tip'] ) ) {
$description = $data['description'];
$tip = $data['desc_tip'];
} elseif ( ! empty( $data['description'] ) ) {
$description = $data['description'];
$tip = '';
} else {
$description = $tip = '';
}
// Custom attribute handling
$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 ) . '"';
$html .= '' . "\n";
$html .= '';
$html .= '';
if ( $tip )
$html .= '';
$html .= ' | ' . "\n";
$html .= '' . "\n";
$html .= '';
$html .= ' | ' . "\n";
$html .= '
' . "\n";
return $html;
}
/**
* Generate Textarea HTML.
*
* @access public
* @param mixed $key
* @param mixed $data
* @since 1.0.0
* @return string
*/
public function generate_textarea_html( $key, $data ) {
global $woocommerce;
$html = '';
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
$data['disabled'] = empty( $data['disabled'] ) ? false : true;
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$data['desc_tip'] = isset( $data['desc_tip'] ) ? $data['desc_tip'] : false;
$data['description'] = isset( $data['description'] ) ? $data['description'] : '';
$data['placeholder'] = isset( $data['placeholder'] ) ? $data['placeholder'] : '';
// Description handling
if ( $data['desc_tip'] === true ) {
$description = '';
$tip = $data['description'];
} elseif ( ! empty( $data['desc_tip'] ) ) {
$description = $data['description'];
$tip = $data['desc_tip'];
} elseif ( ! empty( $data['description'] ) ) {
$description = $data['description'];
$tip = '';
} else {
$description = $tip = '';
}
// Custom attribute handling
$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 ) . '"';
$html .= '' . "\n";
$html .= '';
$html .= '';
if ( $tip )
$html .= '';
$html .= ' | ' . "\n";
$html .= '' . "\n";
$html .= '';
$html .= ' | ' . "\n";
$html .= '
' . "\n";
return $html;
}
/**
* Generate Checkbox HTML.
*
* @access public
* @param mixed $key
* @param mixed $data
* @since 1.0.0
* @return string
*/
public function generate_checkbox_html( $key, $data ) {
global $woocommerce;
$html = '';
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
$data['label'] = isset( $data['label'] ) ? $data['label'] : $data['title'];
$data['disabled'] = empty( $data['disabled'] ) ? false : true;
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$data['desc_tip'] = isset( $data['desc_tip'] ) ? $data['desc_tip'] : false;
$data['description'] = isset( $data['description'] ) ? $data['description'] : '';
// Description handling
if ( $data['desc_tip'] === true ) {
$description = '';
$tip = $data['description'];
} elseif ( ! empty( $data['desc_tip'] ) ) {
$description = $data['description'];
$tip = $data['desc_tip'];
} elseif ( ! empty( $data['description'] ) ) {
$description = $data['description'];
$tip = '';
} else {
$description = $tip = '';
}
// Custom attribute handling
$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 ) . '"';
$html .= '' . "\n";
$html .= '' . $data['title'];
if ( $tip )
$html .= '';
$html .= ' | ' . "\n";
$html .= '' . "\n";
$html .= '';
$html .= ' | ' . "\n";
$html .= '
' . "\n";
return $html;
}
/**
* Generate Select HTML.
*
* @access public
* @param mixed $key
* @param mixed $data
* @since 1.0.0
* @return string
*/
public function generate_select_html( $key, $data ) {
global $woocommerce;
$html = '';
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
$data['disabled'] = empty( $data['disabled'] ) ? false : true;
$data['options'] = isset( $data['options'] ) ? (array) $data['options'] : array();
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$data['desc_tip'] = isset( $data['desc_tip'] ) ? $data['desc_tip'] : false;
$data['description'] = isset( $data['description'] ) ? $data['description'] : '';
// Description handling
if ( $data['desc_tip'] === true ) {
$description = '';
$tip = $data['description'];
} elseif ( ! empty( $data['desc_tip'] ) ) {
$description = $data['description'];
$tip = $data['desc_tip'];
} elseif ( ! empty( $data['description'] ) ) {
$description = $data['description'];
$tip = '';
} else {
$description = $tip = '';
}
// Custom attribute handling
$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 ) . '"';
$html .= '' . "\n";
$html .= '';
$html .= '';
if ( $tip )
$html .= '';
$html .= ' | ' . "\n";
$html .= '' . "\n";
$html .= '';
$html .= ' | ' . "\n";
$html .= '
' . "\n";
return $html;
}
/**
* Generate Multiselect HTML.
*
* @access public
* @param mixed $key
* @param mixed $data
* @since 1.0.0
* @return string
*/
public function generate_multiselect_html( $key, $data ) {
global $woocommerce;
$html = '';
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
$data['disabled'] = empty( $data['disabled'] ) ? false : true;
$data['options'] = isset( $data['options'] ) ? (array) $data['options'] : array();
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$data['desc_tip'] = isset( $data['desc_tip'] ) ? $data['desc_tip'] : false;
$data['description'] = isset( $data['description'] ) ? $data['description'] : '';
// Description handling
if ( $data['desc_tip'] === true ) {
$description = '';
$tip = $data['description'];
} elseif ( ! empty( $data['desc_tip'] ) ) {
$description = $data['description'];
$tip = $data['desc_tip'];
} elseif ( ! empty( $data['description'] ) ) {
$description = $data['description'];
$tip = '';
} else {
$description = $tip = '';
}
// Custom attribute handling
$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 ) . '"';
$html .= '' . "\n";
$html .= '';
$html .= '';
if ( $tip )
$html .= '';
$html .= ' | ' . "\n";
$html .= '' . "\n";
$html .= '';
$html .= ' | ' . "\n";
$html .= '
' . "\n";
return $html;
}
/**
* Generate Title HTML.
*
* @access public
* @param mixed $key
* @param mixed $data
* @since 1.6.2
* @return string
*/
public function generate_title_html( $key, $data ) {
$html = '';
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
$html .= '' . "\n";
$html .= '' . wp_kses_post( $data['title'] ) . '
' . "\n";
if ( isset( $data['description'] ) && $data['description'] != '' ) { $html .= '' . wp_kses_post( $data['description'] ) . '
' . "\n"; }
$html .= '