NGG_Media_RSS_Widget

The NextCellent Media RSS widget.

Defined (1)

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

/widgets/class-ngg-media-rss-widget.php  
  1. class NGG_Media_RSS_Widget extends WP_Widget { 
  2.  
  3. /** 
  4. * Register the widget. 
  5. */ 
  6. public function __construct() { 
  7. parent::__construct( 'ngg-mrssw', __( 'NextCellent Media RSS', 'nggallery' ), array( 
  8. 'classname' => 'ngg_mrssw',  
  9. 'description' => __( 'Widget that displays a Media RSS links for NextCellent Gallery.', 'nggallery' ) 
  10. ) ); 
  11.  
  12. /** 
  13. * Front-end display of widget. 
  14. * @see WP_Widget::widget() 
  15. * @param array $args Widget arguments. 
  16. * @param array $instance Saved values from the database. 
  17. */ 
  18. public function widget( $args, $instance ) { 
  19.  
  20. $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? ' ' : $instance['title'], $instance, $this->id_base ); 
  21.  
  22. $out = $args['before_widget']; 
  23. $out .= $args['before_title'] . $title . $args['after_title']; 
  24. $out .= "<div class='ngg-media-rss-widget'>"; 
  25. $out .= "<a href='" . nggMediaRss::get_mrss_url() . "' title='" . $instance['mrss_title'] . "' class='ngg-media-rss-link'>"; 
  26. if ( $instance['show_icon'] ) { 
  27. $out .= '<span class="dashicons dashicons-rss" style="padding-right: 1.5em"></span>'; 
  28. if ( $instance['show_global_mrss'] ) { 
  29. $out .= $instance['mrss_text']; 
  30. $out .= "</a></div>"; 
  31. $out .= $args['after_widget']; 
  32. echo $out; 
  33.  
  34. /** 
  35. * Sanitize widget form values as they are saved. 
  36. * @see WP_Widget::update() 
  37. * @param array $new_instance Values just sent to be saved. 
  38. * @param array $old_instance Previously saved values from database. 
  39. * @return array Updated safe values to be saved. 
  40. */ 
  41. public function update( $new_instance, $old_instance ) { 
  42. $instance = $old_instance; 
  43.  
  44. $instance['title'] = sanitize_text_field( $new_instance['title'] ); 
  45. $instance['show_global_mrss'] = (bool) $new_instance['show_global_mrss']; 
  46. $instance['show_icon'] = (bool) $new_instance['show_icon']; 
  47. $instance['mrss_text'] = sanitize_text_field( $new_instance['mrss_text'] ); 
  48. $instance['mrss_title'] = sanitize_text_field( $new_instance['mrss_title'] ); 
  49.  
  50. return $instance; 
  51.  
  52. /** 
  53. * Back-end widget form. 
  54. * @see WP_Widget::form() 
  55. * @param array $instance Previously saved values from database. 
  56. * @return string Default return is 'noform'. 
  57. */ 
  58. function form( $instance ) { 
  59.  
  60. //Defaults 
  61. $instance = wp_parse_args( (array) $instance, array( 
  62. 'title' => __( 'Media RSS', 'nggallery' ),  
  63. 'show_global_mrss' => true,  
  64. 'mrss_text' => __( 'Media RSS', 'nggallery' ),  
  65. 'mrss_title' => __( 'Link to the main image feed', 'nggallery' ),  
  66. 'show_icon' => true 
  67. ) ); 
  68.  
  69. // The widget form 
  70. ?> 
  71. <p> 
  72. <label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'nggallery' ); ?>:</label> 
  73. <input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" 
  74. name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" 
  75. value="<?php esc_attr_e( $instance['title'] ); ?>"> 
  76. </p> 
  77. <p> 
  78. <input id="<?php echo $this->get_field_id( 'show_icon' ); ?>" 
  79. name="<?php echo $this->get_field_name( 'show_icon' ); ?>" 
  80. type="checkbox" value="true" <?php checked( true, $instance['show_icon'] ); ?>> 
  81. <label for="<?php echo $this->get_field_id( 'show_icon' ); ?>"> 
  82. <?php _e( 'Show the RSS icon', 'nggallery' ); ?> 
  83. </label> 
  84. </p> 
  85. <p> 
  86. <input id="<?php echo $this->get_field_id( 'show_global_mrss' ); ?>" 
  87. name="<?php echo $this->get_field_name( 'show_global_mrss' ); ?>" type="checkbox" 
  88. value="true" <?php checked( true, $instance['show_global_mrss'] ); ?>> 
  89. <label for="<?php echo $this->get_field_id( 'show_global_mrss' ); ?>"> 
  90. <?php _e( 'Show the link text', 'nggallery' ); ?> 
  91. </label> 
  92. </p> 
  93. <p> 
  94. <label for="<?php echo $this->get_field_id( 'mrss_text' ); ?>"> 
  95. <?php _e( 'Text for Media RSS link', 'nggallery' ); ?>: 
  96. </label> 
  97. <input class="widefat" id="<?php echo $this->get_field_id( 'mrss_text' ); ?>" 
  98. name="<?php echo $this->get_field_name( 'mrss_text' ); ?>" type="text" 
  99. value="<?php esc_attr_e( $instance['mrss_text'] ); ?>"> 
  100. </p> 
  101. <p> 
  102. <label for="<?php echo $this->get_field_id( 'mrss_title' ); ?>"> 
  103. <?php _e( 'Tooltip text for Media RSS link', 'nggallery' ); ?>: 
  104. </label> 
  105. <input class="widefat" id="<?php echo $this->get_field_id( 'mrss_title' ); ?>" 
  106. name="<?php echo $this->get_field_name( 'mrss_title' ); ?>" type="text" 
  107. value="<?php esc_attr_e( $instance['mrss_title'] ); ?>"> 
  108. </p> 
  109.  
  110. <?php