Skip to content

Commit f385f43

Browse files
committed
Merge pull request #30 from ThatGerber/hotfix-29
Fixes #29. Widget issue
2 parents 000bc3a + 85e3acf commit f385f43

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

widget/widget.ad_position.php

+39-37
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
2+
23
/**
34
* Ad Position Widget
45
*
56
* Simple widget to include an ad position
67
*/
7-
88
class DFP_Ads_Widget extends WP_Widget {
99

1010
/**
@@ -50,51 +50,54 @@ public function __construct() {
5050
$this->get_widget_slug(),
5151
__( 'DFP Ad Position', $this->get_widget_slug() ),
5252
array(
53-
'classname' => $this->get_widget_slug().'-class',
53+
'classname' => $this->get_widget_slug() . '-class',
5454
'description' => __( 'Displays an ad position', $this->get_widget_slug() )
5555
)
5656
);
5757

5858
// Refreshing the widget's cached output with each new post
59-
add_action( 'save_post', array( $this, 'flush_widget_cache' ) );
59+
add_action( 'save_post', array( $this, 'flush_widget_cache' ) );
6060
add_action( 'deleted_post', array( $this, 'flush_widget_cache' ) );
6161
add_action( 'switch_theme', array( $this, 'flush_widget_cache' ) );
6262
}
6363

64-
/**
65-
* Return the widget slug.
66-
*
67-
* @since 0.0.1
68-
* @access public
69-
*
70-
* @return Plugin slug variable.
71-
*/
72-
public function get_widget_slug() {
73-
return $this->widget_slug;
74-
}
75-
7664
/**
7765
* Outputs the content of the widget.
7866
*
7967
* @since 0.0.1
8068
* @access public
8169
*
82-
* @param array args The array of form elements
83-
* @param array instance The current instance of the widget
70+
* @param array $args The array of form elements
71+
* @param array $instance The current instance of the widget
8472
*/
8573
public function widget( $args, $instance ) {
8674
echo $args['before_widget'];
87-
do_shortcode( '[dfp_ads id=' . __($instance['position_title']) . ']' );
75+
dfp_ad_position( $instance['position_title'] );
8876
echo $args['after_widget'];
8977
}
78+
9079
/**
91-
* Flushes the cache
80+
* Generates the administration form for the widget.
9281
*
9382
* @since 0.0.1
9483
* @access public
84+
*
85+
* @param array instance The array of keys and values for the widget.
86+
*
87+
* @return mixed
9588
*/
96-
public function flush_widget_cache() {
97-
wp_cache_delete( $this->get_widget_slug(), 'widget' );
89+
public function form( $instance ) {
90+
$id = ( $this->get_field_id( 'position_title' ) !== null ? $this->get_field_id( 'position_title' ) : '' );
91+
$name = ( $this->get_field_name( 'position_title' ) !== null ? $this->get_field_name( 'position_title' ) : '' );
92+
$value = ( isset( $instance['position_title'] ) ? $instance['position_title'] : '' );
93+
?>
94+
<h4><label for="<?php _e( $id ); ?>"><?php _e( 'Ad Position', 'dfp-ads' ); ?></label></h4>
95+
<p>
96+
<select class="widefat" name="<?php _e( $name ); ?>" id="<?php _e( $id ); ?>">
97+
<?php dfp_ad_select_options( $value ); ?>
98+
</select>
99+
</p>
100+
<?php
98101
}
99102

100103
/**
@@ -111,34 +114,33 @@ public function flush_widget_cache() {
111114
public function update( $new_instance, $old_instance ) {
112115

113116
foreach ( $this->fields as $field ) {
114-
$instance[$field] = $new_instance[$field];
117+
$instance[ $field ] = $new_instance[ $field ];
115118
}
116119

117120
return $instance;
118121
}
119122

120123
/**
121-
* Generates the administration form for the widget.
124+
* Return the widget slug.
122125
*
123126
* @since 0.0.1
124127
* @access public
125128
*
126-
* @param array instance The array of keys and values for the widget.
129+
* @return string Plugin slug variable.
130+
*/
131+
public function get_widget_slug() {
132+
133+
return $this->widget_slug;
134+
}
135+
136+
/**
137+
* Flushes the cache
127138
*
128-
* @return mixed
139+
* @since 0.0.1
140+
* @access public
129141
*/
130-
public function form( $instance ) {
131-
$id = ( $this->get_field_id('position_title') !== null ? $this->get_field_id('position_title') : '' );
132-
$name = ( $this->get_field_name('position_title') !== null ? $this->get_field_name('position_title') : '' );
133-
$value = ( isset( $instance['position_title'] ) ? $instance['position_title'] : '' );
134-
?>
135-
<h4><label for="<?php _e( $id ); ?>"><?php _e( 'Ad Position', 'dfp-ads'); ?></label></h4>
136-
<p>
137-
<select class="widefat" name="<?php _e( $name ); ?>" id="<?php _e( $id ); ?>">
138-
<?php dfp_ad_select_options( $value ); ?>
139-
</select>
140-
</p>
141-
<?php
142+
public function flush_widget_cache() {
143+
wp_cache_delete( $this->get_widget_slug(), 'widget' );
142144
}
143145

144146
}

0 commit comments

Comments
 (0)