PodsWidgetSingle

The Pods - Custom Content Types and Fields PodsWidgetSingle class.

Defined (1)

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

/classes/widgets/PodsWidgetSingle.php  
  1. class PodsWidgetSingle 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_single', $name = 'Pods - Single Item', $widget_options = array(), $control_options = array() ) { 
  16. parent::__construct( 
  17. 'pods_widget_single',  
  18. 'Pods - Single Item',  
  19. array( 'classname' => 'pods_widget_single', 'description' => 'Display a Single Pod Item' ),  
  20. array( 'width' => 200 ) 
  21. ); 
  22.  
  23. /** 
  24. * Output of widget 
  25. */ 
  26. public function widget ( $args, $instance ) { 
  27. extract( $args ); 
  28.  
  29. // Get widget field values 
  30. $title = apply_filters( 'widget_title', $instance[ 'title' ] ); 
  31.  
  32. $args = array( 
  33. 'name' => trim( pods_var_raw( 'pod_type', $instance, '' ) ),  
  34. 'slug' => trim( pods_var_raw( 'slug', $instance, '' ) ),  
  35. 'template' => trim( pods_var_raw( 'template', $instance, '' ) ) 
  36. ); 
  37.  
  38. $content = trim( pods_var_raw( 'template_custom', $instance, '' ) ); 
  39.  
  40. if ( 0 < strlen( $args[ 'name' ] ) && 0 < strlen( $args[ 'slug' ] ) && ( 0 < strlen( $args[ 'template' ] ) || 0 < strlen( $content ) ) ) { 
  41. require PODS_DIR . 'ui/front/widgets.php'; 
  42.  
  43. /** 
  44. * Updates the new instance of widget arguments 
  45. * @returns array $instance Updated instance 
  46. */ 
  47. public function update ( $new_instance, $old_instance ) { 
  48. $instance = $old_instance; 
  49.  
  50. $instance[ 'title' ] = pods_var_raw( 'title', $new_instance, '' ); 
  51. $instance[ 'pod_type' ] = pods_var_raw( 'pod_type', $new_instance, '' ); 
  52. $instance[ 'slug' ] = pods_var_raw( 'slug', $new_instance, '' ); 
  53. $instance[ 'template' ] = pods_var_raw( 'template', $new_instance, '' ); 
  54. $instance[ 'template_custom' ] = pods_var_raw( 'template_custom', $new_instance, '' ); 
  55.  
  56. return $instance; 
  57.  
  58. /** 
  59. * Widget Form 
  60. */ 
  61. public function form ( $instance ) { 
  62. $title = pods_var_raw( 'title', $instance, '' ); 
  63. $slug = pods_var_raw( 'slug', $instance, '' ); 
  64. $pod_type = pods_var_raw( 'pod_type', $instance, '' ); 
  65. $template = pods_var_raw( 'template', $instance, '' ); 
  66. $template_custom = pods_var_raw( 'template_custom', $instance, '' ); 
  67.  
  68. require PODS_DIR . 'ui/admin/widgets/single.php';