From a322b05f240320e052b3361ec0180ec0f50ba584 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Mon, 11 Jan 2016 12:04:37 +0000 Subject: [PATCH] Avoid confusion between fields and field keys --- .../abstracts/abstract-wc-settings-api.php | 134 +++++++++--------- 1 file changed, 66 insertions(+), 68 deletions(-) diff --git a/includes/abstracts/abstract-wc-settings-api.php b/includes/abstracts/abstract-wc-settings-api.php index bbed7af9ff2..2eb00b0026b 100644 --- a/includes/abstracts/abstract-wc-settings-api.php +++ b/includes/abstracts/abstract-wc-settings-api.php @@ -313,8 +313,8 @@ abstract class WC_Settings_API { * @return string */ public function generate_text_html( $key, $data ) { - $field = $this->get_field_key( $key ); - $defaults = array( + $field_key = $this->get_field_key( $key ); + $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', @@ -332,13 +332,13 @@ abstract class WC_Settings_API { ?> - + get_tooltip_html( $data ); ?>
- get_custom_attribute_html( $data ); ?> /> + get_custom_attribute_html( $data ); ?> /> get_description_html( $data ); ?>
@@ -357,8 +357,8 @@ abstract class WC_Settings_API { * @return string */ public function generate_price_html( $key, $data ) { - $field = $this->get_field_key( $key ); - $defaults = array( + $field_key = $this->get_field_key( $key ); + $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', @@ -376,13 +376,13 @@ abstract class WC_Settings_API { ?> - + get_tooltip_html( $data ); ?>
- get_custom_attribute_html( $data ); ?> /> + get_custom_attribute_html( $data ); ?> /> get_description_html( $data ); ?>
@@ -401,8 +401,8 @@ abstract class WC_Settings_API { * @return string */ public function generate_decimal_html( $key, $data ) { - $field = $this->get_field_key( $key ); - $defaults = array( + $field_key = $this->get_field_key( $key ); + $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', @@ -420,13 +420,13 @@ abstract class WC_Settings_API { ?> - + get_tooltip_html( $data ); ?>
- get_custom_attribute_html( $data ); ?> /> + get_custom_attribute_html( $data ); ?> /> get_description_html( $data ); ?>
@@ -458,8 +458,8 @@ abstract class WC_Settings_API { * @return string */ public function generate_color_html( $key, $data ) { - $field = $this->get_field_key( $key ); - $defaults = array( + $field_key = $this->get_field_key( $key ); + $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', @@ -476,15 +476,15 @@ abstract class WC_Settings_API { ?> - + get_tooltip_html( $data ); ?>
- get_custom_attribute_html( $data ); ?> /> - + get_custom_attribute_html( $data ); ?> /> + get_description_html( $data ); ?>
@@ -503,8 +503,8 @@ abstract class WC_Settings_API { * @return string */ public function generate_textarea_html( $key, $data ) { - $field = $this->get_field_key( $key ); - $defaults = array( + $field_key = $this->get_field_key( $key ); + $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', @@ -522,13 +522,13 @@ abstract class WC_Settings_API { ?> - + get_tooltip_html( $data ); ?>
- + get_description_html( $data ); ?>
@@ -547,8 +547,8 @@ abstract class WC_Settings_API { * @return string */ public function generate_checkbox_html( $key, $data ) { - $field = $this->get_field_key( $key ); - $defaults = array( + $field_key = $this->get_field_key( $key ); + $defaults = array( 'title' => '', 'label' => '', 'disabled' => false, @@ -570,14 +570,14 @@ abstract class WC_Settings_API { ?> - + get_tooltip_html( $data ); ?>
-
+
get_description_html( $data ); ?>
@@ -596,8 +596,8 @@ abstract class WC_Settings_API { * @return string */ public function generate_select_html( $key, $data ) { - $field = $this->get_field_key( $key ); - $defaults = array( + $field_key = $this->get_field_key( $key ); + $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', @@ -616,13 +616,13 @@ abstract class WC_Settings_API { ?> - + get_tooltip_html( $data ); ?>
- get_custom_attribute_html( $data ); ?>> $option_value ) : ?> @@ -645,8 +645,8 @@ abstract class WC_Settings_API { * @return string */ public function generate_multiselect_html( $key, $data ) { - $field = $this->get_field_key( $key ); - $defaults = array( + $field_key = $this->get_field_key( $key ); + $defaults = array( 'title' => '', 'disabled' => false, 'class' => '', @@ -666,13 +666,13 @@ abstract class WC_Settings_API { ?> - + get_tooltip_html( $data ); ?>
- get_custom_attribute_html( $data ); ?>> $option_value ) : ?> @@ -695,8 +695,8 @@ abstract class WC_Settings_API { * @return string */ public function generate_title_html( $key, $data ) { - $field = $this->get_field_key( $key ); - $defaults = array( + $field_key = $this->get_field_key( $key ); + $defaults = array( 'title' => '', 'class' => '' ); @@ -706,7 +706,7 @@ abstract class WC_Settings_API { ob_start(); ?> -

+

@@ -721,15 +721,15 @@ abstract class WC_Settings_API { * * Make sure the data is escaped correctly, etc. * - * @param mixed $key + * @param string $key * @return string */ public function validate_text_field( $key ) { - $text = $this->get_option( $key ); - $field = $this->get_field_key( $key ); + $text = $this->get_option( $key ); + $field_key = $this->get_field_key( $key ); - if ( isset( $_POST[ $field ] ) ) { - $text = wp_kses_post( trim( stripslashes( $_POST[ $field ] ) ) ); + if ( isset( $_POST[ $field_key ] ) ) { + $text = wp_kses_post( trim( stripslashes( $_POST[ $field_key ] ) ) ); } return $text; @@ -740,17 +740,17 @@ abstract class WC_Settings_API { * * Make sure the data is escaped correctly, etc. * - * @param mixed $key + * @param string $key * @return string */ public function validate_price_field( $key ) { - $text = $this->get_option( $key ); - $field = $this->get_field_key( $key ); + $text = $this->get_option( $key ); + $field_key = $this->get_field_key( $key ); - if ( isset( $_POST[ $field ] ) ) { + if ( isset( $_POST[ $field_key ] ) ) { - if ( $_POST[ $field ] !== '' ) { - $text = wc_format_decimal( trim( stripslashes( $_POST[ $field ] ) ) ); + if ( $_POST[ $field_key ] !== '' ) { + $text = wc_format_decimal( trim( stripslashes( $_POST[ $field_key ] ) ) ); } else { $text = ''; } @@ -764,18 +764,17 @@ abstract class WC_Settings_API { * * Make sure the data is escaped correctly, etc. * - * @param mixed $key + * @param string $key * @return string */ public function validate_decimal_field( $key ) { + $text = $this->get_option( $key ); + $field_key = $this->get_field_key( $key ); - $text = $this->get_option( $key ); - $field = $this->get_field_key( $key ); + if ( isset( $_POST[ $field_key ] ) ) { - if ( isset( $_POST[ $field ] ) ) { - - if ( $_POST[ $field ] !== '' ) { - $text = wc_format_decimal( trim( stripslashes( $_POST[ $field ] ) ) ); + if ( $_POST[ $field_key ] !== '' ) { + $text = wc_format_decimal( trim( stripslashes( $_POST[ $field_key ] ) ) ); } else { $text = ''; } @@ -789,13 +788,12 @@ abstract class WC_Settings_API { * * Make sure the data is escaped correctly, etc. * - * @param mixed $key - * @since 1.0.0 + * @param string $key * @return string */ public function validate_password_field( $key ) { - $field = $this->get_field_key( $key ); - $value = wp_kses_post( trim( stripslashes( $_POST[ $field ] ) ) ); + $field_key = $this->get_field_key( $key ); + $value = wp_kses_post( trim( stripslashes( $_POST[ $field_key ] ) ) ); return $value; } @@ -806,10 +804,10 @@ abstract class WC_Settings_API { * @return string */ public function validate_textarea_field( $key ) { - $field = $this->get_field_key( $key ); + $field_key = $this->get_field_key( $key ); - if ( isset( $_POST[ $field ] ) ) { - $text = wp_kses( trim( stripslashes( $_POST[ $field ] ) ), + if ( isset( $_POST[ $field_key ] ) ) { + $text = wp_kses( trim( stripslashes( $_POST[ $field_key ] ) ), array_merge( array( 'iframe' => array( 'src' => true, 'style' => true, 'id' => true, 'class' => true ) @@ -833,8 +831,8 @@ abstract class WC_Settings_API { * @return string */ public function validate_checkbox_field( $key ) { - $field = $this->get_field_key( $key ); - return isset( $_POST[ $field ] ) && '1' === $_POST[ $field ] ? 'yes' : 'no'; + $field_key = $this->get_field_key( $key ); + return isset( $_POST[ $field_key ] ) && '1' === $_POST[ $field_key ] ? 'yes' : 'no'; } /** @@ -844,8 +842,8 @@ abstract class WC_Settings_API { * @return string */ public function validate_select_field( $key ) { - $field = $this->get_field_key( $key ); - return isset( $_POST[ $field ] ) ? wc_clean( stripslashes( $_POST[ $field ] ) ) : $this->get_option( $key ); + $field_key = $this->get_field_key( $key ); + return isset( $_POST[ $field_key ] ) ? wc_clean( stripslashes( $_POST[ $field_key ] ) ) : $this->get_option( $key ); } /** @@ -855,8 +853,8 @@ abstract class WC_Settings_API { * @return string */ public function validate_multiselect_field( $key ) { - $field = $this->get_field_key( $key ); - return isset( $_POST[ $field ] ) ? array_map( 'wc_clean', array_map( 'stripslashes', (array) $_POST[ $field ] ) ) : ''; + $field_key = $this->get_field_key( $key ); + return isset( $_POST[ $field_key ] ) ? array_map( 'wc_clean', array_map( 'stripslashes', (array) $_POST[ $field_key ] ) ) : ''; } /**