WordAds_Sidebar_Widget

Widget for inserting an ad into your sidebar.

Defined (1)

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

/modules/wordads/php/widgets.php  
  1. class WordAds_Sidebar_Widget extends WP_Widget { 
  2.  
  3. private static $allowed_tags = array( 'mrec', 'wideskyscraper' ); 
  4.  
  5. function __construct() { 
  6. parent::__construct( 
  7. 'wordads_sidebar_widget',  
  8. /** This filter is documented in modules/widgets/facebook-likebox.php */ 
  9. apply_filters( 'jetpack_widget_name', 'Ads' ),  
  10. array( 
  11. 'description' => __( 'Insert an ad unit wherever you can place a widget.', 'jetpack' ),  
  12. 'customize_selective_refresh' => true 
  13. ); 
  14.  
  15. public function widget( $args, $instance ) { 
  16. global $wordads; 
  17. if ( $wordads->should_bail() ) { 
  18. return false; 
  19.  
  20. if ( ! isset( $instance['unit'] ) ) { 
  21. $instance['unit'] = 'mrec'; 
  22.  
  23. $about = __( 'Advertisements', 'jetpack' ); 
  24. $width = WordAds::$ad_tag_ids[$instance['unit']]['width']; 
  25. $height = WordAds::$ad_tag_ids[$instance['unit']]['height']; 
  26.  
  27. $snippet = ''; 
  28. if ( $wordads->option( 'wordads_house', true ) ) { 
  29. $unit = 'mrec'; 
  30. if ( 'leaderboard' == $instance['unit'] && ! $this->params->mobile_device ) { 
  31. $unit = 'leaderboard'; 
  32. } else if ( 'wideskyscraper' == $instance['unit'] ) { 
  33. $unit = 'widesky'; 
  34.  
  35. $snippet = $wordads->get_house_ad( $unit ); 
  36. } else { 
  37. $section_id = 0 === $wordads->params->blog_id ? WORDADS_API_TEST_ID : $wordads->params->blog_id . '3'; 
  38. $data_tags = ( $wordads->params->cloudflare ) ? ' data-cfasync="false"' : ''; 
  39. $snippet = <<<HTML 
  40. <script$data_tags type='text/javascript'> 
  41. (function(g) {g.__ATA.initAd({sectionId:$section_id, width:$width, height:$height});})(window); 
  42. </script> 
  43. HTML; 
  44.  
  45. echo <<< HTML 
  46. <div class="wpcnt"> 
  47. <div class="wpa"> 
  48. <span class="wpa-about">$about</span> 
  49. <div class="u {$instance['unit']}"> 
  50. $snippet 
  51. </div> 
  52. </div> 
  53. </div> 
  54. HTML; 
  55.  
  56. public function form( $instance ) { 
  57. // ad unit type 
  58. if ( isset( $instance['unit'] ) ) { 
  59. $unit = $instance['unit']; 
  60. } else { 
  61. $unit = 'mrec'; 
  62. ?> 
  63. <p> 
  64. <label for="<?php echo esc_attr( $this->get_field_id( 'unit' ) ); ?>"><?php _e( 'Tag Dimensions:', 'jetpack' ); ?></label> 
  65. <select class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'unit' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'unit' ) ); ?>"> 
  66. <?php 
  67. foreach ( WordAds::$ad_tag_ids as $ad_unit => $properties ) { 
  68. if ( ! in_array( $ad_unit, self::$allowed_tags ) ) { 
  69. continue; 
  70.  
  71. $splits = explode( '_', $properties['tag'] ); 
  72. $unit_pretty = "{$splits[0]} {$splits[1]}"; 
  73. $selected = selected( $ad_unit, $unit, false ); 
  74. echo "<option value='", esc_attr( $ad_unit ) , "' ", $selected, '>', esc_html( $unit_pretty ) , '</option>'; 
  75. ?> 
  76. </select> 
  77. </p> 
  78. <?php 
  79.  
  80. public function update( $new_instance, $old_instance ) { 
  81. $instance = $old_instance; 
  82.  
  83. if ( in_array( $new_instance['unit'], self::$allowed_tags ) ) { 
  84. $instance['unit'] = $new_instance['unit']; 
  85. } else { 
  86. $instance['unit'] = 'mrec'; 
  87.  
  88. return $instance;