2011-11-28 13:47:16 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Admin Settings API used by Shipping Methods and Payment Gateways
|
|
|
|
*
|
2012-08-14 20:19:41 +00:00
|
|
|
* @class WC_Settings_API
|
2013-11-12 17:43:30 +00:00
|
|
|
* @version 2.1.0
|
2013-02-20 17:14:46 +00:00
|
|
|
* @package WooCommerce/Abstracts
|
|
|
|
* @category Abstract Class
|
2012-08-14 20:19:41 +00:00
|
|
|
* @author WooThemes
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-31 18:25:09 +00:00
|
|
|
abstract class WC_Settings_API {
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-08-15 17:08:42 +00:00
|
|
|
/** @var string The plugin ID. Used for option names. */
|
2012-12-14 22:01:58 +00:00
|
|
|
public $plugin_id = 'woocommerce_';
|
2012-08-14 20:19:41 +00:00
|
|
|
|
2012-08-15 17:08:42 +00:00
|
|
|
/** @var array Array of setting values. */
|
2012-12-14 22:01:58 +00:00
|
|
|
public $settings = array();
|
2012-08-14 20:19:41 +00:00
|
|
|
|
2012-08-15 17:08:42 +00:00
|
|
|
/** @var array Array of form option fields. */
|
2012-12-14 22:01:58 +00:00
|
|
|
public $form_fields = array();
|
2012-08-14 20:19:41 +00:00
|
|
|
|
2012-08-15 17:08:42 +00:00
|
|
|
/** @var array Array of validation errors. */
|
2012-12-14 22:01:58 +00:00
|
|
|
public $errors = array();
|
2012-08-14 20:19:41 +00:00
|
|
|
|
2012-08-15 17:08:42 +00:00
|
|
|
/** @var array Sanitized fields after validation. */
|
2012-12-14 22:01:58 +00:00
|
|
|
public $sanitized_fields = array();
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* Admin Options
|
|
|
|
*
|
|
|
|
* Setup the gateway settings screen.
|
|
|
|
* Override this in your gateway.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function admin_options() { ?>
|
2012-12-31 12:07:43 +00:00
|
|
|
<h3><?php echo ( ! empty( $this->method_title ) ) ? $this->method_title : __( 'Settings', 'woocommerce' ) ; ?></h3>
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-05-29 12:32:54 +00:00
|
|
|
<?php echo ( ! empty( $this->method_description ) ) ? wpautop( $this->method_description ) : ''; ?>
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-01-21 03:10:59 +00:00
|
|
|
<table class="form-table">
|
|
|
|
<?php $this->generate_settings_html(); ?>
|
|
|
|
</table><?php
|
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* Initialise Settings Form Fields
|
|
|
|
*
|
|
|
|
* Add an array of fields to be displayed
|
|
|
|
* on the gateway's settings screen.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @return string
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-31 12:07:43 +00:00
|
|
|
public function init_form_fields() {}
|
|
|
|
|
2013-12-05 15:57:01 +00:00
|
|
|
/**
|
|
|
|
* Get the form fields after they are initialized
|
2014-07-15 22:41:28 +00:00
|
|
|
*
|
2013-12-05 15:57:01 +00:00
|
|
|
* @return array of options
|
|
|
|
*/
|
|
|
|
public function get_form_fields() {
|
|
|
|
return apply_filters( 'woocommerce_settings_api_form_fields_' . $this->id, $this->form_fields );
|
|
|
|
}
|
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* Admin Panel Options Processing
|
|
|
|
* - Saves the options to the DB
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @return bool
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
|
|
|
public function process_admin_options() {
|
|
|
|
$this->validate_settings_fields();
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
if ( count( $this->errors ) > 0 ) {
|
|
|
|
$this->display_errors();
|
2012-05-30 08:54:35 +00:00
|
|
|
return false;
|
2011-11-28 13:47:16 +00:00
|
|
|
} else {
|
2013-03-13 15:43:45 +00:00
|
|
|
update_option( $this->plugin_id . $this->id . '_settings', apply_filters( 'woocommerce_settings_api_sanitized_fields_' . $this->id, $this->sanitized_fields ) );
|
2013-09-26 16:01:29 +00:00
|
|
|
$this->init_settings();
|
2012-05-30 08:54:35 +00:00
|
|
|
return true;
|
2011-11-28 13:47:16 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* Display admin error messages.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function display_errors() {}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* 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()
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function init_settings() {
|
2012-05-29 12:32:54 +00:00
|
|
|
// Load form_field settings
|
2012-12-31 12:07:43 +00:00
|
|
|
$this->settings = get_option( $this->plugin_id . $this->id . '_settings', null );
|
|
|
|
|
2013-01-02 11:32:26 +00:00
|
|
|
if ( ! $this->settings || ! is_array( $this->settings ) ) {
|
2012-12-31 12:07:43 +00:00
|
|
|
|
2013-02-11 15:07:51 +00:00
|
|
|
$this->settings = array();
|
|
|
|
|
2012-12-31 12:07:43 +00:00
|
|
|
// If there are no settings defined, load defaults
|
2013-12-05 15:57:01 +00:00
|
|
|
if ( $form_fields = $this->get_form_fields() )
|
|
|
|
foreach ( $form_fields as $k => $v )
|
2013-01-02 13:38:33 +00:00
|
|
|
$this->settings[ $k ] = isset( $v['default'] ) ? $v['default'] : '';
|
2012-12-31 12:07:43 +00:00
|
|
|
}
|
|
|
|
|
2013-01-02 11:32:26 +00:00
|
|
|
if ( $this->settings && is_array( $this->settings ) ) {
|
2013-09-26 16:01:29 +00:00
|
|
|
$this->settings = array_map( array( $this, 'format_settings' ), $this->settings );
|
|
|
|
$this->enabled = isset( $this->settings['enabled'] ) && $this->settings['enabled'] == 'yes' ? 'yes' : 'no';
|
2013-01-02 11:32:26 +00:00
|
|
|
}
|
2012-12-31 12:07:43 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-12-31 12:07:43 +00:00
|
|
|
/**
|
|
|
|
* get_option function.
|
|
|
|
*
|
2013-03-03 17:07:31 +00:00
|
|
|
* Gets and option from the settings API, using defaults if necessary to prevent undefined notices.
|
2012-12-31 12:07:43 +00:00
|
|
|
*
|
|
|
|
* @access public
|
2013-11-28 17:59:09 +00:00
|
|
|
* @param string $key
|
2012-12-31 12:07:43 +00:00
|
|
|
* @param mixed $empty_value
|
2013-05-07 11:06:11 +00:00
|
|
|
* @return string The value specified for the option or a default value for the option
|
2012-12-31 12:07:43 +00:00
|
|
|
*/
|
2013-03-28 15:27:14 +00:00
|
|
|
public function get_option( $key, $empty_value = null ) {
|
2012-12-31 12:07:43 +00:00
|
|
|
if ( empty( $this->settings ) )
|
|
|
|
$this->init_settings();
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-12-31 12:07:43 +00:00
|
|
|
// Get option default if unset
|
|
|
|
if ( ! isset( $this->settings[ $key ] ) ) {
|
2013-12-05 15:57:01 +00:00
|
|
|
$form_fields = $this->get_form_fields();
|
|
|
|
$this->settings[ $key ] = isset( $form_fields[ $key ]['default'] ) ? $form_fields[ $key ]['default'] : '';
|
2012-12-31 12:07:43 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2013-03-28 15:27:14 +00:00
|
|
|
if ( ! is_null( $empty_value ) && empty( $this->settings[ $key ] ) )
|
2012-12-31 12:07:43 +00:00
|
|
|
$this->settings[ $key ] = $empty_value;
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-12-31 12:07:43 +00:00
|
|
|
return $this->settings[ $key ];
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode values for settings.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param mixed $value
|
|
|
|
* @return array
|
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function format_settings( $value ) {
|
2013-11-12 17:43:30 +00:00
|
|
|
return is_array( $value ) ? $value : $value;
|
2012-03-14 21:17:18 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* Generate Settings HTML.
|
|
|
|
*
|
|
|
|
* Generate the HTML for the fields on the "settings" screen.
|
|
|
|
*
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @param bool $form_fields (default: false)
|
2011-11-28 13:47:16 +00:00
|
|
|
* @since 1.0.0
|
|
|
|
* @uses method_exists()
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @return string the html for the settings
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2013-11-12 17:43:30 +00:00
|
|
|
public function generate_settings_html( $form_fields = false ) {
|
|
|
|
if ( ! $form_fields )
|
2013-12-05 15:57:01 +00:00
|
|
|
$form_fields = $this->get_form_fields();
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
$html = '';
|
2012-05-29 15:27:12 +00:00
|
|
|
foreach ( $form_fields as $k => $v ) {
|
2013-09-04 13:32:16 +00:00
|
|
|
if ( ! isset( $v['type'] ) || ( $v['type'] == '' ) )
|
|
|
|
$v['type'] = 'text'; // Default to "text" field type.
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
if ( method_exists( $this, 'generate_' . $v['type'] . '_html' ) ) {
|
|
|
|
$html .= $this->{'generate_' . $v['type'] . '_html'}( $k, $v );
|
2012-11-20 17:32:50 +00:00
|
|
|
} else {
|
|
|
|
$html .= $this->{'generate_text_html'}( $k, $v );
|
2011-11-28 13:47:16 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
echo $html;
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
2013-11-12 17:43:30 +00:00
|
|
|
* Get HTML for tooltips
|
|
|
|
* @param array $data
|
2012-08-14 20:19:41 +00:00
|
|
|
* @return string
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2013-11-12 17:43:30 +00:00
|
|
|
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 = '';
|
|
|
|
}
|
2013-01-18 12:10:19 +00:00
|
|
|
|
2013-11-12 17:43:30 +00:00
|
|
|
return $tip ? '<img class="help_tip" data-tip="' . esc_attr( $tip ) . '" src="' . WC()->plugin_url() . '/assets/images/help.png" height="16" width="16" />' : '';
|
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2013-11-12 17:43:30 +00:00
|
|
|
/**
|
|
|
|
* Get HTML for descriptions
|
|
|
|
* @param array $data
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function get_description_html( $data ) {
|
|
|
|
if ( $data['desc_tip'] === true ) {
|
2013-01-18 12:10:19 +00:00
|
|
|
$description = '';
|
|
|
|
} elseif ( ! empty( $data['desc_tip'] ) ) {
|
|
|
|
$description = $data['description'];
|
|
|
|
} elseif ( ! empty( $data['description'] ) ) {
|
|
|
|
$description = $data['description'];
|
|
|
|
} else {
|
2013-11-12 17:43:30 +00:00
|
|
|
$description = '';
|
2013-01-18 12:10:19 +00:00
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2013-11-12 17:43:30 +00:00
|
|
|
return $description ? '<p class="description">' . wp_kses_post( $description ) . '</p>' . "\n" : '';
|
|
|
|
}
|
2012-11-27 16:22:47 +00:00
|
|
|
|
2013-11-12 17:43:30 +00:00
|
|
|
/**
|
|
|
|
* 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'] ) )
|
2012-11-20 17:32:50 +00:00
|
|
|
foreach ( $data['custom_attributes'] as $attribute => $attribute_value )
|
|
|
|
$custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $attribute_value ) . '"';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2013-11-12 17:43:30 +00:00
|
|
|
return implode( ' ', $custom_attributes );
|
|
|
|
}
|
2013-01-18 12:10:19 +00:00
|
|
|
|
2013-11-12 17:43:30 +00:00
|
|
|
/**
|
|
|
|
* 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 ) {
|
|
|
|
$field = $this->plugin_id . $this->id . '_' . $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();
|
|
|
|
?>
|
|
|
|
<tr valign="top">
|
|
|
|
<th scope="row" class="titledesc">
|
|
|
|
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
|
|
|
|
<?php echo $this->get_tooltip_html( $data ); ?>
|
|
|
|
</th>
|
|
|
|
<td class="forminp">
|
|
|
|
<fieldset>
|
|
|
|
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
|
|
|
|
<input class="input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="<?php echo esc_attr( $data['type'] ); ?>" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( $this->get_option( $key ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> />
|
|
|
|
<?php echo $this->get_description_html( $data ); ?>
|
|
|
|
</fieldset>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<?php
|
|
|
|
return ob_get_clean();
|
|
|
|
}
|
2013-01-18 12:10:19 +00:00
|
|
|
|
2013-11-12 17:43:30 +00:00
|
|
|
/**
|
2014-07-15 22:41:28 +00:00
|
|
|
* Generate Price Input HTML.
|
2013-11-12 17:43:30 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param mixed $key
|
|
|
|
* @param mixed $data
|
|
|
|
* @since 1.0.0
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function generate_price_html( $key, $data ) {
|
|
|
|
$field = $this->plugin_id . $this->id . '_' . $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();
|
|
|
|
?>
|
|
|
|
<tr valign="top">
|
|
|
|
<th scope="row" class="titledesc">
|
|
|
|
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
|
|
|
|
<?php echo $this->get_tooltip_html( $data ); ?>
|
|
|
|
</th>
|
|
|
|
<td class="forminp">
|
|
|
|
<fieldset>
|
|
|
|
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
|
|
|
|
<input class="wc_input_price input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( wc_format_localized_price( $this->get_option( $key ) ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> />
|
|
|
|
<?php echo $this->get_description_html( $data ); ?>
|
|
|
|
</fieldset>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<?php
|
|
|
|
return ob_get_clean();
|
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2013-11-12 17:43:30 +00:00
|
|
|
/**
|
2014-07-15 22:41:28 +00:00
|
|
|
* Generate Decimal Input HTML.
|
2013-11-12 17:43:30 +00:00
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param mixed $key
|
|
|
|
* @param mixed $data
|
|
|
|
* @since 1.0.0
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function generate_decimal_html( $key, $data ) {
|
|
|
|
$field = $this->plugin_id . $this->id . '_' . $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();
|
|
|
|
?>
|
|
|
|
<tr valign="top">
|
|
|
|
<th scope="row" class="titledesc">
|
|
|
|
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
|
|
|
|
<?php echo $this->get_tooltip_html( $data ); ?>
|
|
|
|
</th>
|
|
|
|
<td class="forminp">
|
|
|
|
<fieldset>
|
|
|
|
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
|
|
|
|
<input class="wc_input_decimal input-text regular-input <?php echo esc_attr( $data['class'] ); ?>" type="text" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="<?php echo esc_attr( wc_format_localized_decimal( $this->get_option( $key ) ) ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> />
|
|
|
|
<?php echo $this->get_description_html( $data ); ?>
|
|
|
|
</fieldset>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<?php
|
|
|
|
return ob_get_clean();
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
2011-11-28 13:47:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate Password Input HTML.
|
|
|
|
*
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @param mixed $key
|
|
|
|
* @param mixed $data
|
2011-11-28 13:47:16 +00:00
|
|
|
* @since 1.0.0
|
2012-08-14 20:19:41 +00:00
|
|
|
* @return string
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function generate_password_html( $key, $data ) {
|
2013-11-12 17:43:30 +00:00
|
|
|
$data['type'] = 'password';
|
|
|
|
return $this->generate_text_html( $key, $data );
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* Generate Textarea HTML.
|
|
|
|
*
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @param mixed $key
|
|
|
|
* @param mixed $data
|
2011-11-28 13:47:16 +00:00
|
|
|
* @since 1.0.0
|
2012-08-14 20:19:41 +00:00
|
|
|
* @return string
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function generate_textarea_html( $key, $data ) {
|
2013-11-12 17:43:30 +00:00
|
|
|
$field = $this->plugin_id . $this->id . '_' . $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();
|
|
|
|
?>
|
|
|
|
<tr valign="top">
|
|
|
|
<th scope="row" class="titledesc">
|
|
|
|
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
|
|
|
|
<?php echo $this->get_tooltip_html( $data ); ?>
|
|
|
|
</th>
|
|
|
|
<td class="forminp">
|
|
|
|
<fieldset>
|
|
|
|
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
|
|
|
|
<textarea rows="3" cols="20" class="input-text wide-input <?php echo esc_attr( $data['class'] ); ?>" type="<?php echo esc_attr( $data['type'] ); ?>" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" placeholder="<?php echo esc_attr( $data['placeholder'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>><?php echo esc_textarea( $this->get_option( $key ) ); ?></textarea>
|
|
|
|
<?php echo $this->get_description_html( $data ); ?>
|
|
|
|
</fieldset>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<?php
|
|
|
|
return ob_get_clean();
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* Generate Checkbox HTML.
|
|
|
|
*
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @param mixed $key
|
|
|
|
* @param mixed $data
|
2011-11-28 13:47:16 +00:00
|
|
|
* @since 1.0.0
|
2012-08-14 20:19:41 +00:00
|
|
|
* @return string
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function generate_checkbox_html( $key, $data ) {
|
2013-11-12 17:43:30 +00:00
|
|
|
$field = $this->plugin_id . $this->id . '_' . $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();
|
|
|
|
?>
|
|
|
|
<tr valign="top">
|
|
|
|
<th scope="row" class="titledesc">
|
|
|
|
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
|
|
|
|
<?php echo $this->get_tooltip_html( $data ); ?>
|
|
|
|
</th>
|
|
|
|
<td class="forminp">
|
|
|
|
<fieldset>
|
|
|
|
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
|
|
|
|
<label for="<?php echo esc_attr( $field ); ?>">
|
2014-01-08 13:50:59 +00:00
|
|
|
<input <?php disabled( $data['disabled'], true ); ?> class="<?php echo esc_attr( $data['class'] ); ?>" type="checkbox" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" value="1" <?php checked( $this->get_option( $key ), 'yes' ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?> /> <?php echo wp_kses_post( $data['label'] ); ?></label><br/>
|
2013-11-12 17:43:30 +00:00
|
|
|
<?php echo $this->get_description_html( $data ); ?>
|
|
|
|
</fieldset>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<?php
|
|
|
|
return ob_get_clean();
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
2011-11-28 13:47:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate Select HTML.
|
|
|
|
*
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @param mixed $key
|
|
|
|
* @param mixed $data
|
2011-11-28 13:47:16 +00:00
|
|
|
* @since 1.0.0
|
2012-08-14 20:19:41 +00:00
|
|
|
* @return string
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function generate_select_html( $key, $data ) {
|
2013-11-12 17:43:30 +00:00
|
|
|
$field = $this->plugin_id . $this->id . '_' . $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();
|
|
|
|
?>
|
|
|
|
<tr valign="top">
|
|
|
|
<th scope="row" class="titledesc">
|
|
|
|
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
|
|
|
|
<?php echo $this->get_tooltip_html( $data ); ?>
|
|
|
|
</th>
|
|
|
|
<td class="forminp">
|
|
|
|
<fieldset>
|
|
|
|
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
|
|
|
|
<select class="select <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field ); ?>" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>>
|
|
|
|
<?php foreach ( (array) $data['options'] as $option_key => $option_value ) : ?>
|
|
|
|
<option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( $option_key, esc_attr( $this->get_option( $key ) ) ); ?>><?php echo esc_attr( $option_value ); ?></option>
|
|
|
|
<?php endforeach; ?>
|
|
|
|
</select>
|
|
|
|
<?php echo $this->get_description_html( $data ); ?>
|
|
|
|
</fieldset>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<?php
|
|
|
|
return ob_get_clean();
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* Generate Multiselect HTML.
|
|
|
|
*
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @param mixed $key
|
|
|
|
* @param mixed $data
|
2011-11-28 13:47:16 +00:00
|
|
|
* @since 1.0.0
|
2012-08-14 20:19:41 +00:00
|
|
|
* @return string
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function generate_multiselect_html( $key, $data ) {
|
2013-11-12 17:43:30 +00:00
|
|
|
$field = $this->plugin_id . $this->id . '_' . $key;
|
|
|
|
$defaults = array(
|
|
|
|
'title' => '',
|
|
|
|
'disabled' => false,
|
|
|
|
'class' => '',
|
2013-12-29 09:31:44 +00:00
|
|
|
'css' => '',
|
2013-11-12 17:43:30 +00:00
|
|
|
'placeholder' => '',
|
|
|
|
'type' => 'text',
|
|
|
|
'desc_tip' => false,
|
|
|
|
'description' => '',
|
|
|
|
'custom_attributes' => array(),
|
|
|
|
'options' => array()
|
|
|
|
);
|
|
|
|
|
|
|
|
$data = wp_parse_args( $data, $defaults );
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
?>
|
|
|
|
<tr valign="top">
|
|
|
|
<th scope="row" class="titledesc">
|
|
|
|
<label for="<?php echo esc_attr( $field ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></label>
|
|
|
|
<?php echo $this->get_tooltip_html( $data ); ?>
|
|
|
|
</th>
|
|
|
|
<td class="forminp">
|
|
|
|
<fieldset>
|
|
|
|
<legend class="screen-reader-text"><span><?php echo wp_kses_post( $data['title'] ); ?></span></legend>
|
|
|
|
<select multiple="multiple" class="multiselect <?php echo esc_attr( $data['class'] ); ?>" name="<?php echo esc_attr( $field ); ?>[]" id="<?php echo esc_attr( $field ); ?>" style="<?php echo esc_attr( $data['css'] ); ?>" <?php disabled( $data['disabled'], true ); ?> <?php echo $this->get_custom_attribute_html( $data ); ?>>
|
|
|
|
<?php foreach ( (array) $data['options'] as $option_key => $option_value ) : ?>
|
2013-11-13 10:27:09 +00:00
|
|
|
<option value="<?php echo esc_attr( $option_key ); ?>" <?php selected( in_array( $option_key, $this->get_option( $key, array() ) ), true ); ?>><?php echo esc_attr( $option_value ); ?></option>
|
2013-11-12 17:43:30 +00:00
|
|
|
<?php endforeach; ?>
|
|
|
|
</select>
|
|
|
|
<?php echo $this->get_description_html( $data ); ?>
|
|
|
|
</fieldset>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
<?php
|
|
|
|
return ob_get_clean();
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-07-23 18:43:38 +00:00
|
|
|
/**
|
|
|
|
* Generate Title HTML.
|
|
|
|
*
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @param mixed $key
|
|
|
|
* @param mixed $data
|
2012-07-26 14:11:29 +00:00
|
|
|
* @since 1.6.2
|
2012-08-14 20:19:41 +00:00
|
|
|
* @return string
|
2012-07-23 18:43:38 +00:00
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function generate_title_html( $key, $data ) {
|
2013-11-12 17:43:30 +00:00
|
|
|
$defaults = array(
|
|
|
|
'title' => '',
|
|
|
|
'class' => '',
|
|
|
|
'css' => ''
|
|
|
|
);
|
|
|
|
|
|
|
|
$data = wp_parse_args( $data, $defaults );
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
?>
|
|
|
|
</table>
|
|
|
|
<h4 class="<?php echo esc_attr( $data['class'] ); ?>"><?php echo wp_kses_post( $data['title'] ); ?></h4>
|
|
|
|
<?php if ( ! empty( $data['description'] ) ) : ?>
|
|
|
|
<p><?php echo wp_kses_post( $data['description'] ); ?></p>
|
|
|
|
<?php endif; ?>
|
|
|
|
<table class="form-table">
|
|
|
|
<?php
|
|
|
|
return ob_get_clean();
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* Validate Settings Field Data.
|
|
|
|
*
|
|
|
|
* Validate the data on the "Settings" form.
|
|
|
|
*
|
|
|
|
* @since 1.0.0
|
|
|
|
* @uses method_exists()
|
2012-08-14 20:19:41 +00:00
|
|
|
* @param bool $form_fields (default: false)
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function validate_settings_fields( $form_fields = false ) {
|
2012-08-11 15:41:20 +00:00
|
|
|
if ( ! $form_fields )
|
2013-12-05 15:57:01 +00:00
|
|
|
$form_fields = $this->get_form_fields();
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-05-30 08:54:35 +00:00
|
|
|
$this->sanitized_fields = array();
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-05-30 08:54:35 +00:00
|
|
|
foreach ( $form_fields as $k => $v ) {
|
2012-11-27 16:22:47 +00:00
|
|
|
if ( empty( $v['type'] ) )
|
2013-09-04 13:32:16 +00:00
|
|
|
$v['type'] = 'text'; // Default to "text" field type.
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2013-10-16 09:28:24 +00:00
|
|
|
// Look for a validate_FIELDID_field method for special handling
|
|
|
|
if ( method_exists( $this, 'validate_' . $k . '_field' ) ) {
|
|
|
|
$field = $this->{'validate_' . $k . '_field'}( $k );
|
|
|
|
$this->sanitized_fields[ $k ] = $field;
|
|
|
|
|
|
|
|
// Look for a validate_FIELDTYPE_field method
|
|
|
|
} elseif ( method_exists( $this, 'validate_' . $v['type'] . '_field' ) ) {
|
2011-11-28 13:47:16 +00:00
|
|
|
$field = $this->{'validate_' . $v['type'] . '_field'}( $k );
|
2012-10-17 12:46:35 +00:00
|
|
|
$this->sanitized_fields[ $k ] = $field;
|
2014-07-15 22:41:28 +00:00
|
|
|
|
2013-10-16 09:28:24 +00:00
|
|
|
// Default to text
|
2011-11-28 13:47:16 +00:00
|
|
|
} else {
|
2012-11-27 10:37:28 +00:00
|
|
|
$field = $this->{'validate_text_field'}( $k );
|
|
|
|
$this->sanitized_fields[ $k ] = $field;
|
2011-11-28 13:47:16 +00:00
|
|
|
}
|
|
|
|
}
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* Validate Checkbox Field.
|
|
|
|
*
|
|
|
|
* If not set, return "no", otherwise return "yes".
|
2012-08-11 15:41:20 +00:00
|
|
|
*
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @param mixed $key
|
2011-11-28 13:47:16 +00:00
|
|
|
* @since 1.0.0
|
2012-08-14 20:19:41 +00:00
|
|
|
* @return string
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function validate_checkbox_field( $key ) {
|
2011-11-28 13:47:16 +00:00
|
|
|
$status = 'no';
|
2012-10-17 12:46:35 +00:00
|
|
|
if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) && ( 1 == $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
|
2011-11-28 13:47:16 +00:00
|
|
|
$status = 'yes';
|
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
return $status;
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* Validate Text Field.
|
2014-07-15 22:41:28 +00:00
|
|
|
*
|
|
|
|
* Make sure the data is escaped correctly, etc.
|
2011-11-28 13:47:16 +00:00
|
|
|
*
|
2012-08-14 20:19:41 +00:00
|
|
|
* @param mixed $key
|
|
|
|
* @return string
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function validate_text_field( $key ) {
|
2012-12-31 12:07:43 +00:00
|
|
|
$text = $this->get_option( $key );
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2013-11-12 17:43:30 +00:00
|
|
|
if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) )
|
2013-06-14 13:42:24 +00:00
|
|
|
$text = wp_kses_post( trim( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) );
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
return $text;
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 17:43:30 +00:00
|
|
|
/**
|
|
|
|
* Validate Price Field.
|
2014-07-15 22:41:28 +00:00
|
|
|
*
|
|
|
|
* Make sure the data is escaped correctly, etc.
|
2013-11-12 17:43:30 +00:00
|
|
|
*
|
|
|
|
* @param mixed $key
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function validate_price_field( $key ) {
|
|
|
|
$text = $this->get_option( $key );
|
|
|
|
|
|
|
|
if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
|
|
|
|
if ( $_POST[ $this->plugin_id . $this->id . '_' . $key ] !== '' )
|
2013-11-25 13:34:21 +00:00
|
|
|
$text = wc_format_decimal( trim( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) );
|
2013-11-12 17:43:30 +00:00
|
|
|
else
|
|
|
|
$text = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $text;
|
2014-07-15 22:41:28 +00:00
|
|
|
}
|
2013-11-12 17:43:30 +00:00
|
|
|
|
|
|
|
/**
|
2014-07-15 22:41:28 +00:00
|
|
|
* Validate Decimal Field.
|
|
|
|
*
|
|
|
|
* Make sure the data is escaped correctly, etc.
|
2013-11-12 17:43:30 +00:00
|
|
|
*
|
|
|
|
* @param mixed $key
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function validate_decimal_field( $key ) {
|
|
|
|
$text = $this->get_option( $key );
|
|
|
|
|
|
|
|
if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
|
|
|
|
if ( $_POST[ $this->plugin_id . $this->id . '_' . $key ] !== '' )
|
2013-11-25 13:34:21 +00:00
|
|
|
$text = wc_format_decimal( trim( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) );
|
2013-11-12 17:43:30 +00:00
|
|
|
else
|
|
|
|
$text = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
return $text;
|
2014-07-15 22:41:28 +00:00
|
|
|
}
|
2011-11-28 13:47:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate Password Field.
|
|
|
|
*
|
|
|
|
* Make sure the data is escaped correctly, etc.
|
2012-08-11 15:41:20 +00:00
|
|
|
*
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @param mixed $key
|
2011-11-28 13:47:16 +00:00
|
|
|
* @since 1.0.0
|
2012-08-14 20:19:41 +00:00
|
|
|
* @return string
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function validate_password_field( $key ) {
|
2012-12-31 12:07:43 +00:00
|
|
|
$text = $this->get_option( $key );
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-10-17 12:46:35 +00:00
|
|
|
if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
|
2013-11-25 13:34:21 +00:00
|
|
|
$text = wc_clean( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) );
|
2011-11-28 13:47:16 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
return $text;
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* Validate Textarea Field.
|
|
|
|
*
|
|
|
|
* Make sure the data is escaped correctly, etc.
|
2012-08-11 15:41:20 +00:00
|
|
|
*
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @param mixed $key
|
2011-11-28 13:47:16 +00:00
|
|
|
* @since 1.0.0
|
2012-08-14 20:19:41 +00:00
|
|
|
* @return string
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function validate_textarea_field( $key ) {
|
2012-12-31 12:07:43 +00:00
|
|
|
$text = $this->get_option( $key );
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-10-17 12:46:35 +00:00
|
|
|
if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
|
2013-07-19 06:54:51 +00:00
|
|
|
$text = wp_kses( trim( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ),
|
|
|
|
array_merge(
|
|
|
|
array(
|
|
|
|
'iframe' => array( 'src' => true, 'style' => true, 'id' => true, 'class' => true )
|
|
|
|
),
|
|
|
|
wp_kses_allowed_html( 'post' )
|
|
|
|
)
|
|
|
|
);
|
2011-11-28 13:47:16 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
return $text;
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* Validate Select Field.
|
|
|
|
*
|
|
|
|
* Make sure the data is escaped correctly, etc.
|
2012-08-11 15:41:20 +00:00
|
|
|
*
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @param mixed $key
|
2011-11-28 13:47:16 +00:00
|
|
|
* @since 1.0.0
|
2012-08-14 20:19:41 +00:00
|
|
|
* @return string
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function validate_select_field( $key ) {
|
2012-12-31 12:07:43 +00:00
|
|
|
$value = $this->get_option( $key );
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-10-17 12:46:35 +00:00
|
|
|
if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
|
2013-11-25 13:34:21 +00:00
|
|
|
$value = wc_clean( stripslashes( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) );
|
2011-11-28 13:47:16 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
return $value;
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
2011-11-28 13:47:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate Multiselect Field.
|
|
|
|
*
|
|
|
|
* Make sure the data is escaped correctly, etc.
|
2012-08-11 15:41:20 +00:00
|
|
|
*
|
2012-08-14 20:19:41 +00:00
|
|
|
* @access public
|
|
|
|
* @param mixed $key
|
2011-11-28 13:47:16 +00:00
|
|
|
* @since 1.0.0
|
2012-08-14 20:19:41 +00:00
|
|
|
* @return string
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-12-14 22:01:58 +00:00
|
|
|
public function validate_multiselect_field( $key ) {
|
2012-12-31 12:07:43 +00:00
|
|
|
$value = $this->get_option( $key );
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-10-17 12:46:35 +00:00
|
|
|
if ( isset( $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) ) {
|
2013-11-25 13:34:21 +00:00
|
|
|
$value = array_map( 'wc_clean', array_map( 'stripslashes', (array) $_POST[ $this->plugin_id . $this->id . '_' . $key ] ) );
|
2012-08-11 15:41:20 +00:00
|
|
|
} else {
|
|
|
|
$value = '';
|
2011-11-28 13:47:16 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
return $value;
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
2014-07-15 22:41:28 +00:00
|
|
|
}
|