woocommerce_wp_text_input

Output a text input box.

Description

woocommerce_wp_text_input( (array) $field ); 

Parameters (1)

0. $field (array)
The field.

Usage

  1. if ( !function_exists( 'woocommerce_wp_text_input' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/admin/wc-meta-box-functions.php'; 
  3.  
  4. // The field. 
  5. $field = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = woocommerce_wp_text_input($field); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/admin/wc-meta-box-functions.php  
  1. function woocommerce_wp_text_input( $field ) { 
  2. global $thepostid, $post; 
  3.  
  4. $thepostid = empty( $thepostid ) ? $post->ID : $thepostid; 
  5. $field['placeholder'] = isset( $field['placeholder'] ) ? $field['placeholder'] : ''; 
  6. $field['class'] = isset( $field['class'] ) ? $field['class'] : 'short'; 
  7. $field['style'] = isset( $field['style'] ) ? $field['style'] : ''; 
  8. $field['wrapper_class'] = isset( $field['wrapper_class'] ) ? $field['wrapper_class'] : ''; 
  9. $field['value'] = isset( $field['value'] ) ? $field['value'] : get_post_meta( $thepostid, $field['id'], true ); 
  10. $field['name'] = isset( $field['name'] ) ? $field['name'] : $field['id']; 
  11. $field['type'] = isset( $field['type'] ) ? $field['type'] : 'text'; 
  12. $field['desc_tip'] = isset( $field['desc_tip'] ) ? $field['desc_tip'] : false; 
  13. $data_type = empty( $field['data_type'] ) ? '' : $field['data_type']; 
  14.  
  15. switch ( $data_type ) { 
  16. case 'price' : 
  17. $field['class'] .= ' wc_input_price'; 
  18. $field['value'] = wc_format_localized_price( $field['value'] ); 
  19. break; 
  20. case 'decimal' : 
  21. $field['class'] .= ' wc_input_decimal'; 
  22. $field['value'] = wc_format_localized_decimal( $field['value'] ); 
  23. break; 
  24. case 'stock' : 
  25. $field['class'] .= ' wc_input_stock'; 
  26. $field['value'] = wc_stock_amount( $field['value'] ); 
  27. break; 
  28. case 'url' : 
  29. $field['class'] .= ' wc_input_url'; 
  30. $field['value'] = esc_url( $field['value'] ); 
  31. break; 
  32.  
  33. default : 
  34. break; 
  35.  
  36. // Custom attribute handling 
  37. $custom_attributes = array(); 
  38.  
  39. if ( ! empty( $field['custom_attributes'] ) && is_array( $field['custom_attributes'] ) ) { 
  40.  
  41. foreach ( $field['custom_attributes'] as $attribute => $value ) { 
  42. $custom_attributes[] = esc_attr( $attribute ) . '="' . esc_attr( $value ) . '"'; 
  43.  
  44. echo '<p class="form-field ' . esc_attr( $field['id'] ) . '_field ' . esc_attr( $field['wrapper_class'] ) . '"> 
  45. <label for="' . esc_attr( $field['id'] ) . '">' . wp_kses_post( $field['label'] ) . '</label>'; 
  46.  
  47. if ( ! empty( $field['description'] ) && false !== $field['desc_tip'] ) { 
  48. echo wc_help_tip( $field['description'] ); 
  49.  
  50. echo '<input type="' . esc_attr( $field['type'] ) . '" class="' . esc_attr( $field['class'] ) . '" style="' . esc_attr( $field['style'] ) . '" name="' . esc_attr( $field['name'] ) . '" id="' . esc_attr( $field['id'] ) . '" value="' . esc_attr( $field['value'] ) . '" placeholder="' . esc_attr( $field['placeholder'] ) . '" ' . implode( ' ', $custom_attributes ) . ' /> '; 
  51.  
  52. if ( ! empty( $field['description'] ) && false === $field['desc_tip'] ) { 
  53. echo '<span class="description">' . wp_kses_post( $field['description'] ) . '</span>'; 
  54.  
  55. echo '</p>';