advantage_widget_field

The Advantage advantage widget field function.

Description

advantage_widget_field( $widget, $args, $value ); 

Parameters (3)

0. $widget
The widget.
1. $args
The args.
2. $value
The value.

Usage

  1. if ( !function_exists( 'advantage_widget_field' ) ) { 
  2. require_once '/inc/widgets.php'; 
  3.  
  4. // The widget. 
  5. $widget = null; 
  6.  
  7. // The args. 
  8. $args = null; 
  9.  
  10. // The value. 
  11. $value = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = advantage_widget_field($widget, $args, $value); 
  15.  

Defined (1)

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

/inc/widgets.php  
  1. function advantage_widget_field( $widget, $args = array(), $value ) { 
  2. $args = wp_parse_args($args, array (  
  3. 'field' => 'title',  
  4. 'type' => 'text',  
  5. 'label' => '',  
  6. 'desc' => '',  
  7. 'class' => 'widefat',  
  8. 'options' => array(),  
  9. 'label_all' => '',  
  10. 'ptag' => true,  
  11. ) ); 
  12. extract( $args, EXTR_SKIP ); 
  13.  
  14. $field_id = esc_attr( $widget->get_field_id( $field ) ); 
  15. $field_name = esc_attr( $widget->get_field_name( $field ) ); 
  16.  
  17. if ( $ptag ) 
  18. echo '<p>'; 
  19. if ( ! empty( $label ) ) { 
  20. echo '<label for="' . $field_id . '">'; 
  21. echo $label . '</label>'; 
  22. switch ( $type ) { 
  23. case 'media': 
  24. echo '<input class="media-upload-url" id="' . $field_id; 
  25. echo '" name="' . $field_name . '" type="hidden" value="'; 
  26. echo esc_attr( $value ) . '" />'; 
  27. echo '<input class="media-upload-btn" id="' . $field_id; 
  28. echo '_btn" name="' . $field_name . '_btn" type="button" value="'. __( 'Choose', 'advantage' ) . '">'; 
  29. echo '<input class="media-upload-del" id="' . $field_id; 
  30. echo '_del" name="' . $field_name . '_del" type="button" value="'. __( 'Remove', 'advantage' ) . '">'; 
  31. break; 
  32. case 'text': 
  33. case 'hidden': 
  34. echo '<input class="' . $class . '" id="' . $field_id; 
  35. echo '" name="' . $field_name . '" type="' . $type .'" value="'; 
  36. echo esc_attr( $value ) . '" />'; 
  37. break; 
  38. case 'url': 
  39. echo '<input class="' . $class . '" id="' . $field_id; 
  40. echo '" name="' . $field_name . '" type="' . $type .'" value="'; 
  41. echo esc_url( $value ) . '" />'; 
  42. break; 
  43. case 'textarea': 
  44. echo '<textarea class="' . $class . '" id="' . $field_id; 
  45. echo '" name="' . $field_name . '" type="' . $type .'" row="10" col="20">'; 
  46. echo esc_textarea( $value ) . '</textarea>'; 
  47. break; 
  48. case 'number': 
  49. echo '<input class="' . $class . '" id="' . $field_id; 
  50. echo '" name="' . $field_name . '" type="text" size="3" value="'; 
  51. echo esc_attr( $value ) . '" />'; 
  52. break; 
  53. case 'checkbox': 
  54. echo '<input class="' . $class . '" id="' . $field_id; 
  55. echo '" name="' . $field_name . '" type="' . $type .'" value="1" '; 
  56. echo checked( '1', $value, false ) . ' /> '; 
  57. echo '<label for="' . $field_id . '"> ' . $desc . '</label>'; 
  58. break; 
  59. case 'category': 
  60. echo '<select id="' . $field_id . '" name="' . $field_name . '">'; 
  61. if ( ! empty( $label_all ) ) { 
  62. if ( 0 == $value ) 
  63. $selected = 'selected="selected"';  
  64. else 
  65. $selected = ''; 
  66. echo '<option value="0" ' . $selected; 
  67. echo '>' . $label_all . '</option>';  
  68. foreach ( $options as $option ) { 
  69. if ( $option->term_id == $value ) 
  70. $selected = 'selected="selected"'; 
  71. else 
  72. $selected = '';  
  73. echo '<option value="' . $option->term_id . '" ' . $selected; 
  74. echo '>' . $option->name . '</option>'; 
  75. echo '</select>'; 
  76. break; 
  77. case 'select': 
  78. echo '<select id="' . $field_id . '" name="' . $field_name . '">'; 
  79. foreach ( $options as $option ) { 
  80. if ( $option['key'] == $value ) 
  81. $selected = 'selected="selected"'; 
  82. else 
  83. $selected = '';  
  84. echo '<option value="' . $option['key'] . '" ' . $selected; 
  85. echo '>' . $option['name'] . '</option>'; 
  86. echo '</select>'; 
  87. break; 
  88. if ( $ptag ) 
  89. echo '</p>';