From 48ee9fb77a8422af7a941057a7549350a6a702c0 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 27 Sep 2011 10:38:29 +0100 Subject: [PATCH] Multiselect --- classes/gateways/gateway.class.php | 61 ++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 4 deletions(-) diff --git a/classes/gateways/gateway.class.php b/classes/gateways/gateway.class.php index 925b7f6338e..1d1a966d80a 100644 --- a/classes/gateways/gateway.class.php +++ b/classes/gateways/gateway.class.php @@ -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 .= '' . "\n"; + $html .= '' . $title . '' . "\n"; + $html .= '' . "\n"; + $html .= '
' . $title . '' . "\n"; + $html .= '
'; + $html .= '' . "\n"; + $html .= '' . "\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() + } \ No newline at end of file