CWP_Add_banner

Plugin Name: Ads widget Description: add ads images Version: 1.

Defined (1)

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

/widgets/banner-widget/banner-widget.php  
  1. class CWP_Add_banner extends WP_Widget 
  2. function CWP_Add_banner() 
  3. $widget_ops = array('classname' => 'cwp_ddd_banner', 'description' => 'CWP - Add banner' ); 
  4. $this->WP_Widget('CWP_Add_banner', 'CWP - Add banner', $widget_ops); 
  5. function form($instance) 
  6. $instance = wp_parse_args( (array) $instance, array(  
  7. 'image_uri' => '',  
  8. 'destination_uri' => '',  
  9. 'width' => '',  
  10. 'height' => '',  
  11. 'target' => '_blank',  
  12. 'align' => 'center',  
  13. 'title' => '' 
  14. ) ); 
  15.  
  16. $image_uri = $instance['image_uri']; 
  17. $destination_uri = $instance['destination_uri']; 
  18. $width = $instance['width']; 
  19. $height = $instance['height']; 
  20. $target = $instance['target']; 
  21. $align = $instance['align']; 
  22. $title = $instance['title']; 
  23.  
  24. // removed the for loop, you can create new instances of the widget instead 
  25. ?> 
  26. <p> 
  27. <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Widget title:', 'megaresponsive-lite'); ?></label> 
  28. <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /> 
  29. </p> 
  30. <p> 
  31. <label for="<?php echo $this->get_field_id('image_uri'); ?>"><?php _e('Image URL:', 'megaresponsive-lite'); ?></label><br /> 
  32. <input type="text" class="widefat" name="<?php echo $this->get_field_name('image_uri'); ?>" id="<?php echo $this->get_field_id('image_uri'); ?>" value="<?php echo $image_uri; ?>" /> 
  33. </p> 
  34.  
  35. <p> 
  36. <label for="<?php echo $this->get_field_id('destination_uri'); ?>"><?php _e('Destination URL:', 'megaresponsive-lite'); ?></label> 
  37. <input type="text" class="widefat" name="<?php echo $this->get_field_name('destination_uri'); ?>" id="<?php echo $this->get_field_id('destination_uri'); ?>" value="<?php echo $destination_uri; ?>" /> 
  38. </p>  
  39.  
  40. <p> 
  41. <span style="margin-right:10px;"><?php _e('Size:', 'megaresponsive-lite'); ?></span><br/> 
  42. <label for="<?php echo $this->get_field_id('width'); ?>"><?php _e('Width:', 'megaresponsive-lite'); ?></label> 
  43. <input class="widefat" id="<?php echo $this->get_field_id('width'); ?>" name="<?php echo $this->get_field_name('width'); ?>" type="text" value="<?php echo $width; ?>" style="width: 40px; text-align: right;" />px 
  44. <label for="<?php echo $this->get_field_id('height'); ?>"><?php _e('Height:', 'megaresponsive-lite'); ?></label> 
  45. <input class="widefat" id="<?php echo $this->get_field_id('height'); ?>" name="<?php echo $this->get_field_name('height'); ?>" type="text" value="<?php echo $height; ?>" style="width: 40px; text-align: right;" />px 
  46. </p>  
  47.  
  48. <p> 
  49. <label for="<?php echo $this->get_field_id('target'); ?>"><?php _e('Target:', 'megaresponsive-lite'); ?></label> 
  50. <select name="<?php echo $this->get_field_name('target'); ?>" id="<?php echo $this->get_field_id('target'); ?>" class="widefat" style="width: 100px;"> 
  51. <?php 
  52. $options = array('_blank', '_self'); 
  53. foreach ($options as $option) { 
  54. echo '<option value="' . $option . '" id="' . $option . '"', $target == $option ? ' selected="selected"' : '', '>', $option, '</option>'; 
  55. ?> 
  56. </select> 
  57. </p> 
  58.  
  59. <p> 
  60. <label for="<?php echo $this->get_field_id('align'); ?>"><?php _e('Align:', 'megaresponsive-lite'); ?></label> 
  61. <select name="<?php echo $this->get_field_name('align'); ?>" id="<?php echo $this->get_field_id('align'); ?>" class="widefat" style="width: 100px;"> 
  62. <?php 
  63. $options = array('center', 'left', 'right'); 
  64. foreach ($options as $option) { 
  65. echo '<option value="' . $option . '" id="' . $option . '"', $align == $option ? ' selected="selected"' : '', '>', $option, '</option>'; 
  66. ?> 
  67. </select> 
  68. </p> 
  69.  
  70. <?php 
  71.  
  72. function update($new_instance, $old_instance) 
  73.  
  74. $instance = $old_instance; 
  75.  
  76. $instance['image_uri'] = $new_instance['image_uri']; 
  77. $instance['destination_uri'] = $new_instance['destination_uri']; 
  78. $instance['width'] = $new_instance['width']; 
  79. $instance['height'] = $new_instance['height']; 
  80. $instance['target'] = $new_instance['target']; 
  81. $instance['align'] = $new_instance['align']; 
  82. $instance['title'] = $new_instance['title']; 
  83.  
  84. return $instance; 
  85.  
  86. function widget($args, $instance) 
  87. extract($args, EXTR_SKIP); 
  88.  
  89. $image_url = empty($instance['image_uri']) ? ' ' : apply_filters('widget_image_url', $instance['image_uri']); 
  90. $destination_uri = empty($instance['destination_uri']) ? ' ' : apply_filters('widget_destination_uri', $instance['destination_uri']); 
  91. $width = empty($instance['width']) ? ' ' : apply_filters('widget_width', $instance['width']); 
  92. $height = empty($instance['height']) ? ' ' : apply_filters('widget_height', $instance['height']); 
  93. $target = empty($instance['target']) ? ' ' : apply_filters('widget_target', $instance['target']); 
  94. $align = empty($instance['align']) ? ' ' : apply_filters('widget_align', $instance['align']); 
  95. $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']); 
  96. echo '<aside class="widget widget_add_banner">'; 
  97.  
  98. if( trim($title) ) { 
  99. echo '<h1 class="widget-title"><span>'.$title.'</span></h1>'; 
  100.  
  101. echo '<div class="banner-wrap" style="text-align: '.$align.'">'; 
  102. echo '<a href="'.esc_url($instance['destination_uri']).'" title="'.esc_html($instance['title']).'" style="width:'.$width.'px; height:'.$height.'px;" class="banner-link" target="'.$target.'">'; 
  103. echo '<img src="'.esc_url($instance['image_uri']).'" alt="'.esc_html($instance['title']).'" style=" height: '.$height.'px; width: '.$width.'px;">'; 
  104. echo '</a>'; 
  105. echo '</div>'; 
  106.  
  107. echo '</aside>'; 
  108.