Multiselect
This commit is contained in:
parent
f4e79d5ef1
commit
48ee9fb77a
|
@ -301,6 +301,40 @@ class woocommerce_payment_gateway {
|
|||
return $html;
|
||||
} // End generate_select_html()
|
||||
|
||||
/**
|
||||
* Generate Multiselect HTML.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return $html string
|
||||
*/
|
||||
function generate_multiselect_html ( $key, $data ) {
|
||||
$html = '';
|
||||
|
||||
if ( isset( $data['title'] ) && $data['title'] != '' ) { $title = $data['title']; }
|
||||
$data['options'] = (isset( $data['options'] )) ? (array) $data['options'] : array();
|
||||
|
||||
$html .= '<tr valign="top">' . "\n";
|
||||
$html .= '<th scope="row" class="titledesc">' . $title . '</th>' . "\n";
|
||||
$html .= '<td class="forminp">' . "\n";
|
||||
$html .= '<fieldset><legend class="screen-reader-text"><span>' . $title . '</span></legend>' . "\n";
|
||||
$html .= '<label for="' . $this->plugin_id . $this->id . '_' . $key . '">';
|
||||
$html .= '<select multiple="multiple" style="min-width:25%;height:100px;vertical-align:top;" class="multiselect" name="' . $this->plugin_id . $this->id . '_' . $key . '[]" id="' . $this->plugin_id . $this->id . '_' . $key . '">';
|
||||
|
||||
foreach ($data['options'] as $option_key => $option_value) :
|
||||
$html .= '<option value="'.$option_key.'" ';
|
||||
if (isset($this->settings[$key]) && in_array($option_key, (array) $this->settings[$key])) $html .= 'selected="selected"';
|
||||
$html .= '>'.$option_value.'</option>';
|
||||
endforeach;
|
||||
|
||||
$html .= '</select>';
|
||||
if ( isset( $data['description'] ) && $data['description'] != '' ) { $html .= '<span class="description">' . $data['description'] . '</span>' . "\n"; }
|
||||
$html .= '</fieldset>';
|
||||
$html .= '</td>' . "\n";
|
||||
$html .= '</tr>' . "\n";
|
||||
|
||||
return $html;
|
||||
} // End generate_select_html()
|
||||
|
||||
/**
|
||||
* Validate Settings Field Data.
|
||||
*
|
||||
|
@ -348,7 +382,7 @@ class woocommerce_payment_gateway {
|
|||
* @return $text string
|
||||
*/
|
||||
function validate_text_field ( $key ) {
|
||||
$text = $this->settings[$key];
|
||||
$text = (isset($this->settings[$key])) ? $this->settings[$key] : '';
|
||||
|
||||
if ( isset( $_POST[$this->plugin_id . $this->id . '_' . $key] ) && ( '' != $_POST[$this->plugin_id . $this->id . '_' . $key] ) ) {
|
||||
$text = esc_attr( woocommerce_clean( $_POST[$this->plugin_id . $this->id . '_' . $key] ) );
|
||||
|
@ -366,7 +400,7 @@ class woocommerce_payment_gateway {
|
|||
* @return $text string
|
||||
*/
|
||||
function validate_textarea_field ( $key ) {
|
||||
$text = $this->settings[$key];
|
||||
$text = (isset($this->settings[$key])) ? $this->settings[$key] : '';
|
||||
|
||||
if ( isset( $_POST[$this->plugin_id . $this->id . '_' . $key] ) && ( '' != $_POST[$this->plugin_id . $this->id . '_' . $key] ) ) {
|
||||
$text = esc_attr( woocommerce_clean( $_POST[$this->plugin_id . $this->id . '_' . $key] ) );
|
||||
|
@ -376,7 +410,7 @@ class woocommerce_payment_gateway {
|
|||
} // End validate_textarea_field()
|
||||
|
||||
/**
|
||||
* Validate Text Field.
|
||||
* Validate Select Field.
|
||||
*
|
||||
* Make sure the data is escaped correctly, etc.
|
||||
*
|
||||
|
@ -384,7 +418,7 @@ class woocommerce_payment_gateway {
|
|||
* @return $text string
|
||||
*/
|
||||
function validate_select_field ( $key ) {
|
||||
$value = $this->settings[$key];
|
||||
$value = (isset($this->settings[$key])) ? $this->settings[$key] : '';
|
||||
|
||||
if ( isset( $_POST[$this->plugin_id . $this->id . '_' . $key] ) && ( '' != $_POST[$this->plugin_id . $this->id . '_' . $key] ) ) {
|
||||
$value = esc_attr( woocommerce_clean( $_POST[$this->plugin_id . $this->id . '_' . $key] ) );
|
||||
|
@ -392,4 +426,23 @@ class woocommerce_payment_gateway {
|
|||
|
||||
return $value;
|
||||
} // End validate_select_field()
|
||||
|
||||
/**
|
||||
* Validate Multiselect Field.
|
||||
*
|
||||
* Make sure the data is escaped correctly, etc.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @return $text string
|
||||
*/
|
||||
function validate_multiselect_field ( $key ) {
|
||||
$value = (isset($this->settings[$key])) ? $this->settings[$key] : '';
|
||||
|
||||
if ( isset( $_POST[$this->plugin_id . $this->id . '_' . $key] ) && ( '' != $_POST[$this->plugin_id . $this->id . '_' . $key] ) ) {
|
||||
$value = array_map('esc_attr', array_map('woocommerce_clean', (array) $_POST[$this->plugin_id . $this->id . '_' . $key] ));
|
||||
}
|
||||
|
||||
return $value;
|
||||
} // End validate_select_field()
|
||||
|
||||
}
|
Loading…
Reference in New Issue