From cfe15e1e33d6547cfcd2b6bcd56b7d9c2c8d627f Mon Sep 17 00:00:00 2001 From: Illimar Tambek Date: Wed, 10 Sep 2014 11:32:24 +0300 Subject: [PATCH 1/2] Add `id` attribute to woocommerce_form_field args This change allows developers to supply their own id attribute when using the `woocommerce_form_field` template function. The default ID is the escaped key, keeping the default behaviour. --- includes/wc-template-functions.php | 69 +++++++++++++++--------------- 1 file changed, 35 insertions(+), 34 deletions(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 72eb937ff04..9c63017b66d 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -648,7 +648,7 @@ if ( ! function_exists( 'woocommerce_catalog_ordering' ) ) { if ( 1 == $wp_query->found_posts || ! woocommerce_products_will_display() ) { return; } - + $orderby = isset( $_GET['orderby'] ) ? wc_clean( $_GET['orderby'] ) : apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ); $show_default_orderby = 'menu_order' === apply_filters( 'woocommerce_default_catalog_orderby', get_option( 'woocommerce_default_catalog_orderby' ) ); $catalog_orderby_options = apply_filters( 'woocommerce_catalog_orderby', array( @@ -1601,6 +1601,7 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { 'placeholder' => '', 'maxlength' => false, 'required' => false, + 'id' => esc_attr( $key ), 'class' => array(), 'label_class' => array(), 'input_class' => array(), @@ -1608,7 +1609,7 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { 'options' => array(), 'custom_attributes' => array(), 'validate' => array(), - 'default' => '', + 'default' => '', ); $args = wp_parse_args( $args, $defaults ); @@ -1648,14 +1649,14 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { if ( sizeof( $countries ) == 1 ) { - $field = '

'; + $field = '

'; if ( $args['label'] ) $field .= ''; $field .= '' . current( array_values( $countries ) ) . ''; - $field .= ''; + $field .= ''; if ( $args['description'] ) $field .= '' . esc_attr( $args['description'] ) . ''; @@ -1664,9 +1665,9 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { } else { - $field = '

' - . '' - . '' . ''; foreach ( $countries as $ckey => $cvalue ) @@ -1706,11 +1707,11 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { if ( is_array( $states ) && empty( $states ) ) { - $field = '

'; + $field = '

'; if ( $args['label'] ) - $field .= ''; - $field .= ' '; foreach ( $states as $ckey => $cvalue ) @@ -1738,11 +1739,11 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { } else { - $field = '

'; + $field = '

'; if ( $args['label'] ) - $field .= ''; - $field .= ''; + $field .= ''; + $field .= ''; if ( $args['description'] ) $field .= '' . esc_attr( $args['description'] ) . ''; @@ -1754,12 +1755,12 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { break; case "textarea" : - $field = '

'; + $field = '

'; if ( $args['label'] ) - $field .= ''; + $field .= ''; - $field .= ''; + $field .= ''; if ( $args['description'] ) $field .= '' . esc_attr( $args['description'] ) . ''; @@ -1769,9 +1770,9 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { break; case "checkbox" : - $field = '

- - '; + $field = '

+ + '; if ( $args['description'] ) $field .= '' . esc_attr( $args['description'] ) . ''; @@ -1781,12 +1782,12 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { break; case "password" : - $field = '

'; + $field = '

'; if ( $args['label'] ) - $field .= ''; + $field .= ''; - $field .= ''; + $field .= ''; if ( $args['description'] ) $field .= '' . esc_attr( $args['description'] ) . ''; @@ -1796,12 +1797,12 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { break; case "text" : - $field = '

'; + $field = '

'; if ( $args['label'] ) - $field .= ''; + $field .= ''; - $field .= ''; + $field .= ''; if ( $args['description'] ) $field .= '' . esc_attr( $args['description'] ) . ''; @@ -1817,12 +1818,12 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { foreach ( $args['options'] as $option_key => $option_text ) $options .= ''; - $field = '

'; + $field = '

'; if ( $args['label'] ) - $field .= ''; + $field .= ''; - $field .= ' ' . $options . ' '; @@ -1834,15 +1835,15 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { break; case "radio" : - $field = '

'; + $field = '

'; if ( $args['label'] ) $field .= ''; if ( ! empty( $args['options'] ) ) { foreach ( $args['options'] as $option_key => $option_text ) { - $field .= ''; - $field .= ''; + $field .= ''; + $field .= ''; } } From 9215fa76f044718d3dd4135fb3660f4780584c70 Mon Sep 17 00:00:00 2001 From: Illimar Tambek Date: Wed, 10 Sep 2014 12:39:31 +0300 Subject: [PATCH 2/2] Revise id, input_class and label_class escaping --- includes/wc-template-functions.php | 70 +++++++++++++++--------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 9c63017b66d..549751a6c6a 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -1601,7 +1601,7 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { 'placeholder' => '', 'maxlength' => false, 'required' => false, - 'id' => esc_attr( $key ), + 'id' => $key, 'class' => array(), 'label_class' => array(), 'input_class' => array(), @@ -1649,14 +1649,14 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { if ( sizeof( $countries ) == 1 ) { - $field = '

'; + $field = '

'; if ( $args['label'] ) - $field .= ''; + $field .= ''; $field .= '' . current( array_values( $countries ) ) . ''; - $field .= ''; + $field .= ''; if ( $args['description'] ) $field .= '' . esc_attr( $args['description'] ) . ''; @@ -1665,9 +1665,9 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { } else { - $field = '

' - . '' - . '' . ''; foreach ( $countries as $ckey => $cvalue ) @@ -1707,11 +1707,11 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { if ( is_array( $states ) && empty( $states ) ) { - $field = '

'; + $field = '

'; if ( $args['label'] ) - $field .= ''; - $field .= ' '; foreach ( $states as $ckey => $cvalue ) @@ -1739,11 +1739,11 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { } else { - $field = '

'; + $field = '

'; if ( $args['label'] ) - $field .= ''; - $field .= ''; + $field .= ''; + $field .= ''; if ( $args['description'] ) $field .= '' . esc_attr( $args['description'] ) . ''; @@ -1755,12 +1755,12 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { break; case "textarea" : - $field = '

'; + $field = '

'; if ( $args['label'] ) - $field .= ''; + $field .= ''; - $field .= ''; + $field .= ''; if ( $args['description'] ) $field .= '' . esc_attr( $args['description'] ) . ''; @@ -1770,9 +1770,9 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { break; case "checkbox" : - $field = '

- - '; + $field = '

+ + '; if ( $args['description'] ) $field .= '' . esc_attr( $args['description'] ) . ''; @@ -1782,12 +1782,12 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { break; case "password" : - $field = '

'; + $field = '

'; if ( $args['label'] ) - $field .= ''; + $field .= ''; - $field .= ''; + $field .= ''; if ( $args['description'] ) $field .= '' . esc_attr( $args['description'] ) . ''; @@ -1797,12 +1797,12 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { break; case "text" : - $field = '

'; + $field = '

'; if ( $args['label'] ) - $field .= ''; + $field .= ''; - $field .= ''; + $field .= ''; if ( $args['description'] ) $field .= '' . esc_attr( $args['description'] ) . ''; @@ -1818,12 +1818,12 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { foreach ( $args['options'] as $option_key => $option_text ) $options .= ''; - $field = '

'; + $field = '

'; if ( $args['label'] ) - $field .= ''; + $field .= ''; - $field .= ' ' . $options . ' '; @@ -1835,15 +1835,15 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { break; case "radio" : - $field = '

'; + $field = '

'; if ( $args['label'] ) - $field .= ''; + $field .= ''; if ( ! empty( $args['options'] ) ) { foreach ( $args['options'] as $option_key => $option_text ) { - $field .= ''; - $field .= ''; + $field .= ''; + $field .= ''; } }