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