PodsWidgetField

The Pods - Custom Content Types and Fields PodsWidgetField class.

Defined (1)

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

/classes/widgets/PodsWidgetField.php  
  1. class PodsWidgetField extends WP_Widget { 
  2.  
  3. /** 
  4. * Register the widget 
  5. * @since 2.5.4 
  6. * Note: params are totally ignored. Included for the sake of strict standards. 
  7. * @param string $id_base Optional Base ID for the widget, lowercase and unique. If left empty,  
  8. * a portion of the widget's class name will be used Has to be unique. 
  9. * @param string $name Name for the widget displayed on the configuration page. 
  10. * @param array $widget_options Optional. Widget options. See {@see wp_register_sidebar_widget()} for 
  11. * information on accepted arguments. Default empty array. 
  12. * @param array $control_options Optional. Widget control options. See {@see wp_register_widget_control()} 
  13. * for information on accepted arguments. Default empty array. 
  14. */ 
  15. public function __construct( $id_base = 'pods_widget_field', $name = 'Pods - Field Value', $widget_options = array(), $control_options = array() ) { 
  16. parent::__construct( 
  17. 'pods_widget_field',  
  18. 'Pods - Field Value',  
  19. array( 'classname' => 'pods_widget_field', 'description' => "Display a single Pod item's field value" ),  
  20. array( 'width' => 200 ) 
  21. ); 
  22.  
  23.  
  24. /** 
  25. * Output of widget 
  26. */ 
  27. public function widget ( $args, $instance ) { 
  28. extract( $args ); 
  29.  
  30. // Get widget fields 
  31. $title = apply_filters( 'widget_title', $instance[ 'title' ] ); 
  32.  
  33. $args = array( 
  34. 'name' => trim( pods_var_raw( 'pod_type', $instance, '' ) ),  
  35. 'slug' => trim( pods_var_raw( 'slug', $instance, '' ) ),  
  36. 'field' => trim( pods_var_raw( 'field', $instance, '' ) ) 
  37. ); 
  38.  
  39. if ( 0 < strlen( $args[ 'name' ] ) && 0 < strlen( $args[ 'slug' ] ) && 0 < strlen( $args[ 'field' ] ) ) { 
  40. require PODS_DIR . 'ui/front/widgets.php'; 
  41.  
  42. /** 
  43. * Updates the new instance of widget arguments 
  44. * @returns array $instance Updated instance 
  45. */ 
  46. public function update ( $new_instance, $old_instance ) { 
  47. $instance = $old_instance; 
  48. $instance[ 'title' ] = pods_var_raw( 'title', $new_instance, '' ); 
  49. $instance[ 'pod_type' ] = pods_var_raw( 'pod_type', $new_instance, '' ); 
  50. $instance[ 'slug' ] = pods_var_raw( 'slug', $new_instance, '' ); 
  51. $instance[ 'field' ] = pods_var_raw( 'field', $new_instance, '' ); 
  52.  
  53. return $instance; 
  54.  
  55. /** 
  56. * Widget Form 
  57. */ 
  58. public function form ( $instance ) { 
  59. $title = pods_var_raw( 'title', $instance, '' ); 
  60. $pod_type = pods_var_raw( 'pod_type', $instance, '' ); 
  61. $slug = pods_var_raw( 'slug', $instance, '' ); 
  62. $field = pods_var_raw( 'field', $instance, '' ); 
  63.  
  64. require PODS_DIR . 'ui/admin/widgets/field.php';