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
|
|
|
|
* @version 1.6.4
|
2012-08-14 22:43:48 +00:00
|
|
|
* @package WooCommerce/Classes
|
2012-08-14 20:19:41 +00:00
|
|
|
* @author WooThemes
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-01-30 19:24:52 +00:00
|
|
|
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. */
|
2011-11-28 13:47:16 +00:00
|
|
|
var $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. */
|
2011-11-28 13:47:16 +00:00
|
|
|
var $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. */
|
2011-11-28 13:47:16 +00:00
|
|
|
var $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. */
|
2011-11-28 13:47:16 +00:00
|
|
|
var $errors = array();
|
2012-08-14 20:19:41 +00:00
|
|
|
|
2012-08-15 17:08:42 +00:00
|
|
|
/** @var array Sanitized fields after validation. */
|
2011-11-28 13:47:16 +00:00
|
|
|
var $sanitized_fields = array();
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-08-14 20:19:41 +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-01-21 03:10:59 +00:00
|
|
|
function admin_options() { ?>
|
2012-05-29 12:32:54 +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-08-14 20:19:41 +00:00
|
|
|
function init_form_fields() {
|
|
|
|
return __( 'This function needs to be overridden by your payment gateway class.', 'woocommerce' );
|
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
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 {
|
|
|
|
update_option( $this->plugin_id . $this->id . '_settings', $this->sanitized_fields );
|
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
|
|
|
|
*/
|
|
|
|
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-05-29 12:32:54 +00:00
|
|
|
function init_settings() {
|
2011-11-28 15:50:19 +00:00
|
|
|
|
2012-05-29 12:32:54 +00:00
|
|
|
// Load form_field settings
|
|
|
|
if ( $this->form_fields ) {
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-05-29 12:32:54 +00:00
|
|
|
$form_field_settings = ( array ) get_option( $this->plugin_id . $this->id . '_settings' );
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-05-29 12:32:54 +00:00
|
|
|
if ( ! $form_field_settings ) {
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-05-29 12:32:54 +00:00
|
|
|
// If there are no settings defined, load defaults
|
|
|
|
foreach ( $this->form_fields as $k => $v )
|
|
|
|
$form_field_settings[ $k ] = isset( $v['default'] ) ? $v['default'] : '';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-05-29 12:32:54 +00:00
|
|
|
} else {
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-05-29 12:32:54 +00:00
|
|
|
// Prevent "undefined index" errors.
|
|
|
|
foreach ( $this->form_fields as $k => $v )
|
2012-07-27 12:59:51 +00:00
|
|
|
$form_field_settings[ $k ] = isset( $form_field_settings[ $k ] ) ? $form_field_settings[ $k ] : ( isset( $v['default'] ) ? $v['default'] : '' );
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-05-29 12:32:54 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-05-29 12:32:54 +00:00
|
|
|
// Set and decode escaped values
|
|
|
|
$this->settings = array_map( array( &$this, 'format_settings' ), $form_field_settings );
|
2011-11-28 13:47:16 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
|
|
|
if ( isset( $this->settings['enabled'] ) && ( $this->settings['enabled'] == 'yes' ) )
|
2012-05-29 12:32:54 +00:00
|
|
|
$this->enabled = 'yes';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-08-14 20:19:41 +00:00
|
|
|
}
|
|
|
|
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-08-14 20:19:41 +00:00
|
|
|
/**
|
|
|
|
* Decode values for settings.
|
|
|
|
*
|
|
|
|
* @access public
|
|
|
|
* @param mixed $value
|
|
|
|
* @return array
|
|
|
|
*/
|
2012-03-14 21:17:18 +00:00
|
|
|
function format_settings( $value ) {
|
2012-05-29 12:32:54 +00:00
|
|
|
return ( is_array( $value ) ) ? $value : html_entity_decode( $value );
|
2012-03-14 21:17:18 +00:00
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-08-14 20:19:41 +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
|
|
|
*/
|
2012-05-30 08:54:35 +00:00
|
|
|
function generate_settings_html ( $form_fields = false ) {
|
2012-08-11 15:41:20 +00:00
|
|
|
|
|
|
|
if ( ! $form_fields )
|
2012-05-29 15:27:12 +00:00
|
|
|
$form_fields = $this->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 ) {
|
2011-11-28 13:47: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-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
|
|
|
}
|
|
|
|
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
/**
|
|
|
|
* Generate Text 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-10-18 13:47:21 +00:00
|
|
|
function generate_text_html( $key, $data ) {
|
2011-11-28 13:47:16 +00:00
|
|
|
$html = '';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-11-15 11:46:18 +00:00
|
|
|
$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'] : '';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '<tr valign="top">' . "\n";
|
2012-05-01 09:39:48 +00:00
|
|
|
$html .= '<th scope="row" class="titledesc">';
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<label for="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '">' . wp_kses_post( $data['title'] ) . '</label>';
|
2012-05-01 09:39:48 +00:00
|
|
|
$html .= '</th>' . "\n";
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '<td class="forminp">' . "\n";
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<fieldset><legend class="screen-reader-text"><span>' . wp_kses_post( $data['title'] ) . '</span></legend>' . "\n";
|
2012-04-13 11:37:13 +00:00
|
|
|
$value = ( isset( $this->settings[ $key ] ) ) ? esc_attr( $this->settings[ $key ] ) : '';
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<input class="input-text regular-input ' . esc_attr( $data['class'] ) . '" type="text" name="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" id="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" style="' . esc_attr( $data['css'] ) . '" value="' . $value . '" placeholder="' . esc_attr( $data['placeholder'] ) . '" ' . disabled( $data['disabled'], true, false ) . ' />';
|
2012-10-17 12:46:35 +00:00
|
|
|
if ( isset( $data['description'] ) && $data['description'] != '' ) { $html .= ' <p class="description">' . wp_kses_post( $data['description'] ) . '</p>' . "\n"; }
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '</fieldset>';
|
|
|
|
$html .= '</td>' . "\n";
|
|
|
|
$html .= '</tr>' . "\n";
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
return $html;
|
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-10-18 13:47:21 +00:00
|
|
|
function generate_password_html( $key, $data ) {
|
2011-11-28 13:47:16 +00:00
|
|
|
$html = '';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-11-15 11:46:18 +00:00
|
|
|
$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'] : '';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '<tr valign="top">' . "\n";
|
2012-05-01 09:39:48 +00:00
|
|
|
$html .= '<th scope="row" class="titledesc">';
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<label for="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '">' . wp_kses_post( $data['title'] ) . '</label>';
|
2012-05-01 09:39:48 +00:00
|
|
|
$html .= '</th>' . "\n";
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '<td class="forminp">' . "\n";
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<fieldset><legend class="screen-reader-text"><span>' . wp_kses_post( $data['title'] ) . '</span></legend>' . "\n";
|
2012-04-13 11:37:13 +00:00
|
|
|
$value = ( isset( $this->settings[ $key ] ) ) ? esc_attr( $this->settings[ $key ] ) : '';
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<input class="input-text regular-input ' . esc_attr( $data['class'] ) . '" type="password" name="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" id="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" style="' . esc_attr( $data['css'] ) . '" value="' . $value . '" ' . disabled( $data['disabled'], true, false ) . ' />';
|
2012-10-17 12:46:35 +00:00
|
|
|
if ( isset( $data['description'] ) && $data['description'] != '' ) { $html .= ' <p class="description">' . esc_attr( $data['description'] ) . '</p>' . "\n"; }
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '</fieldset>';
|
|
|
|
$html .= '</td>' . "\n";
|
|
|
|
$html .= '</tr>' . "\n";
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
return $html;
|
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
|
|
|
*/
|
|
|
|
function generate_textarea_html( $key, $data ) {
|
|
|
|
$html = '';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-11-15 11:46:18 +00:00
|
|
|
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
|
|
|
|
$data['disabled'] = empty( $data['disabled'] ) ? false : true;
|
2012-03-30 15:15:11 +00:00
|
|
|
if ( ! isset( $this->settings[$key] ) ) $this->settings[$key] = '';
|
2012-11-15 11:46:18 +00:00
|
|
|
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
|
|
|
|
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '<tr valign="top">' . "\n";
|
2012-05-01 09:39:48 +00:00
|
|
|
$html .= '<th scope="row" class="titledesc">';
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<label for="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '">' . wp_kses_post( $data['title'] ) . '</label>';
|
2012-05-01 09:39:48 +00:00
|
|
|
$html .= '</th>' . "\n";
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '<td class="forminp">' . "\n";
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<fieldset><legend class="screen-reader-text"><span>' . wp_kses_post( $data['title'] ) . '</span></legend>' . "\n";
|
2012-10-18 13:47:21 +00:00
|
|
|
$value = ( isset( $this->settings[ $key ] ) ) ? esc_textarea( $this->settings[ $key ] ) : '';
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<textarea rows="3" cols="20" class="input-text wide-input ' . esc_attr( $data['class'] ) . '" name="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" id="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" style="' . esc_attr( $data['css'] ) . '" ' . disabled( $data['disabled'], true, false ) . '>' . $value . '</textarea>';
|
2012-10-17 12:46:35 +00:00
|
|
|
if ( isset( $data['description'] ) && $data['description'] != '' ) { $html .= ' <p class="description">' . wp_kses_post( $data['description'] ) . '</p>' . "\n"; }
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '</fieldset>';
|
|
|
|
$html .= '</td>' . "\n";
|
|
|
|
$html .= '</tr>' . "\n";
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
return $html;
|
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-10-18 13:47:21 +00:00
|
|
|
function generate_checkbox_html( $key, $data ) {
|
2011-11-28 13:47:16 +00:00
|
|
|
$html = '';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-11-15 11:46:18 +00:00
|
|
|
$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'] : '';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '<tr valign="top">' . "\n";
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<th scope="row" class="titledesc">' . $data['title'] . '</th>' . "\n";
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '<td class="forminp">' . "\n";
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<fieldset><legend class="screen-reader-text"><span>' . wp_kses_post( $data['title'] ) . '</span></legend>' . "\n";
|
2012-10-17 12:46:35 +00:00
|
|
|
$html .= '<label for="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '">';
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<input style="' . esc_attr( $data['css'] ) . '" name="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" id="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" type="checkbox" value="1" ' . checked( $this->settings[$key], 'yes', false ) . ' class="' . esc_attr( $data['class'] ).'" ' . disabled( $data['disabled'], true, false ) . ' /> ' . wp_kses_post( $data['label'] ) . '</label><br />' . "\n";
|
2012-10-17 12:46:35 +00:00
|
|
|
if ( isset( $data['description'] ) && $data['description'] != '' ) { $html .= ' <p class="description">' . wp_kses_post( $data['description'] ) . '</p>' . "\n"; }
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '</fieldset>';
|
|
|
|
$html .= '</td>' . "\n";
|
|
|
|
$html .= '</tr>' . "\n";
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
return $html;
|
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-10-18 13:47:21 +00:00
|
|
|
function generate_select_html( $key, $data ) {
|
2011-11-28 13:47:16 +00:00
|
|
|
$html = '';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-11-15 11:46:18 +00:00
|
|
|
$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'] : '';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '<tr valign="top">' . "\n";
|
2012-05-01 09:39:48 +00:00
|
|
|
$html .= '<th scope="row" class="titledesc">';
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<label for="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '">' . wp_kses_post( $data['title'] ) . '</label>';
|
2012-05-01 09:39:48 +00:00
|
|
|
$html .= '</th>' . "\n";
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '<td class="forminp">' . "\n";
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<fieldset><legend class="screen-reader-text"><span>' . wp_kses_post( $data['title'] ) . '</span></legend>' . "\n";
|
|
|
|
$html .= '<select name="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" id="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" style="' . esc_attr( $data['css'] ) . '" class="select ' .esc_attr( $data['class'] ) . '" ' . disabled( $data['disabled'], true, false ) . '>';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
foreach ($data['options'] as $option_key => $option_value) :
|
2012-10-17 12:46:35 +00:00
|
|
|
$html .= '<option value="' . esc_attr( $option_key ) . '" '.selected($option_key, esc_attr($this->settings[$key]), false).'>' . esc_attr( $option_value ) . '</option>';
|
2011-11-28 13:47:16 +00:00
|
|
|
endforeach;
|
|
|
|
|
|
|
|
$html .= '</select>';
|
2012-10-17 12:46:35 +00:00
|
|
|
if ( isset( $data['description'] ) && $data['description'] != '' ) { $html .= ' <p class="description">' . wp_kses_post( $data['description'] ) . '</p>' . "\n"; }
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '</fieldset>';
|
|
|
|
$html .= '</td>' . "\n";
|
|
|
|
$html .= '</tr>' . "\n";
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
return $html;
|
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-10-18 13:47:21 +00:00
|
|
|
function generate_multiselect_html( $key, $data ) {
|
2011-11-28 13:47:16 +00:00
|
|
|
$html = '';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-11-15 11:46:18 +00:00
|
|
|
$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'] : '';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '<tr valign="top">' . "\n";
|
2012-05-01 09:39:48 +00:00
|
|
|
$html .= '<th scope="row" class="titledesc">';
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<label for="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '">' . wp_kses_post( $data['title'] ) . '</label>';
|
2012-05-01 09:39:48 +00:00
|
|
|
$html .= '</th>' . "\n";
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '<td class="forminp">' . "\n";
|
2012-11-15 11:46:18 +00:00
|
|
|
$html .= '<fieldset><legend class="screen-reader-text"><span>' . wp_kses_post( $data['title'] ) . '</span></legend>' . "\n";
|
|
|
|
$html .= '<select multiple="multiple" style="' . esc_attr( $data['css'] ) . '" class="multiselect ' . esc_attr( $data['class'] ) . '" name="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '[]" id="' . esc_attr( $this->plugin_id . $this->id . '_' . $key ) . '" ' . disabled( $data['disabled'], true, false ) . '>';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-10-17 12:46:35 +00:00
|
|
|
foreach ( $data['options'] as $option_key => $option_value) {
|
|
|
|
$html .= '<option value="' . esc_attr( $option_key ) . '" ';
|
|
|
|
if ( isset( $this->settings[ $key ] ) && in_array( $option_key, (array) $this->settings[ $key ] ) ) $html .= 'selected="selected"';
|
|
|
|
$html .= '>' . esc_attr( $option_value ) . '</option>';
|
|
|
|
}
|
2011-11-28 13:47:16 +00:00
|
|
|
|
|
|
|
$html .= '</select>';
|
2012-10-17 12:46:35 +00:00
|
|
|
if ( isset( $data['description'] ) && $data['description'] != '' ) { $html .= '<p class="description">' . wp_kses_post( $data['description'] ) . '</p>' . "\n"; }
|
2011-11-28 13:47:16 +00:00
|
|
|
$html .= '</fieldset>';
|
|
|
|
$html .= '</td>' . "\n";
|
|
|
|
$html .= '</tr>' . "\n";
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
return $html;
|
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-07-26 14:11:29 +00:00
|
|
|
function generate_title_html( $key, $data ) {
|
2012-07-23 18:43:38 +00:00
|
|
|
$html = '';
|
2012-07-26 14:11:29 +00:00
|
|
|
|
2012-11-15 11:46:18 +00:00
|
|
|
$data['title'] = isset( $data['title'] ) ? $data['title'] : '';
|
|
|
|
$data['class'] = isset( $data['class'] ) ? $data['class'] : '';
|
|
|
|
$data['css'] = isset( $data['css'] ) ? $data['css'] : '';
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-07-23 18:43:38 +00:00
|
|
|
$html .= '</table>' . "\n";
|
2012-10-17 12:46:35 +00:00
|
|
|
$html .= '<h4 class="' . esc_attr( $data['class'] ) . '">' . wp_kses_post( $data['title'] ) . '</h4>' . "\n";
|
|
|
|
if ( isset( $data['description'] ) && $data['description'] != '' ) { $html .= '<p>' . wp_kses_post( $data['description'] ) . '</p>' . "\n"; }
|
2012-07-23 18:43:38 +00:00
|
|
|
$html .= '<table class="form-table">' . "\n";
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2012-07-23 18:43:38 +00:00
|
|
|
return $html;
|
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 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)
|
|
|
|
* @return void
|
2011-11-28 13:47:16 +00:00
|
|
|
*/
|
2012-05-30 08:54:35 +00:00
|
|
|
function validate_settings_fields( $form_fields = false ) {
|
2012-08-11 15:41:20 +00:00
|
|
|
|
|
|
|
if ( ! $form_fields )
|
2012-05-30 08:54:35 +00:00
|
|
|
$form_fields = $this->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-10-18 13:47:21 +00:00
|
|
|
if ( empty( $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, 'validate_' . $v['type'] . '_field' ) ) {
|
|
|
|
$field = $this->{'validate_' . $v['type'] . '_field'}( $k );
|
2012-10-17 12:46:35 +00:00
|
|
|
$this->sanitized_fields[ $k ] = $field;
|
2011-11-28 13:47:16 +00:00
|
|
|
} else {
|
2012-10-17 12:46:35 +00:00
|
|
|
$this->sanitized_fields[ $k ] = $this->settings[ $k ];
|
2011-11-28 13:47:16 +00:00
|
|
|
}
|
|
|
|
}
|
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 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-10-18 13:47:21 +00:00
|
|
|
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.
|
|
|
|
*
|
|
|
|
* 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-10-18 13:47:21 +00:00
|
|
|
function validate_text_field( $key ) {
|
2012-10-17 12:46:35 +00:00
|
|
|
$text = ( isset( $this->settings[ $key ] ) ) ? $this->settings[ $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 ] ) ) {
|
|
|
|
$text = esc_attr( trim( 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
|
|
|
}
|
|
|
|
|
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-10-18 13:47:21 +00:00
|
|
|
function validate_password_field( $key ) {
|
2011-11-28 13:47:16 +00:00
|
|
|
$text = (isset($this->settings[$key])) ? $this->settings[$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 ] ) ) {
|
|
|
|
$text = esc_attr( woocommerce_clean( $_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-10-18 13:47:21 +00:00
|
|
|
function validate_textarea_field( $key ) {
|
2012-10-17 12:46:35 +00:00
|
|
|
$text = ( isset( $this->settings[ $key ] ) ) ? $this->settings[ $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 ] ) ) {
|
|
|
|
$text = esc_attr( trim( 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 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-10-18 13:47:21 +00:00
|
|
|
function validate_select_field( $key ) {
|
2012-10-17 12:46:35 +00:00
|
|
|
$value = ( isset( $this->settings[ $key ] ) ) ? $this->settings[ $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 ] ) ) {
|
|
|
|
$value = esc_attr( woocommerce_clean( $_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-10-18 13:47:21 +00:00
|
|
|
function validate_multiselect_field( $key ) {
|
2012-10-17 12:46:35 +00:00
|
|
|
$value = ( isset( $this->settings[ $key ] ) ) ? $this->settings[ $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 ] ) ) {
|
|
|
|
$value = array_map('esc_attr', array_map('woocommerce_clean', (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
|
|
|
}
|
2012-08-11 15:41:20 +00:00
|
|
|
|
2011-11-28 13:47:16 +00:00
|
|
|
}
|