1
1
<?php
2
+
2
3
/**
3
4
* Ad Position Widget
4
5
*
5
6
* Simple widget to include an ad position
6
7
*/
7
-
8
8
class DFP_Ads_Widget extends WP_Widget {
9
9
10
10
/**
@@ -50,51 +50,54 @@ public function __construct() {
50
50
$ this ->get_widget_slug (),
51
51
__ ( 'DFP Ad Position ' , $ this ->get_widget_slug () ),
52
52
array (
53
- 'classname ' => $ this ->get_widget_slug (). '-class ' ,
53
+ 'classname ' => $ this ->get_widget_slug () . '-class ' ,
54
54
'description ' => __ ( 'Displays an ad position ' , $ this ->get_widget_slug () )
55
55
)
56
56
);
57
57
58
58
// 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 ' ) );
60
60
add_action ( 'deleted_post ' , array ( $ this , 'flush_widget_cache ' ) );
61
61
add_action ( 'switch_theme ' , array ( $ this , 'flush_widget_cache ' ) );
62
62
}
63
63
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
-
76
64
/**
77
65
* Outputs the content of the widget.
78
66
*
79
67
* @since 0.0.1
80
68
* @access public
81
69
*
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
84
72
*/
85
73
public function widget ( $ args , $ instance ) {
86
74
echo $ args ['before_widget ' ];
87
- do_shortcode ( ' [dfp_ads id= ' . __ ( $ instance ['position_title ' ]) . ' ] ' );
75
+ dfp_ad_position ( $ instance ['position_title ' ] );
88
76
echo $ args ['after_widget ' ];
89
77
}
78
+
90
79
/**
91
- * Flushes the cache
80
+ * Generates the administration form for the widget.
92
81
*
93
82
* @since 0.0.1
94
83
* @access public
84
+ *
85
+ * @param array instance The array of keys and values for the widget.
86
+ *
87
+ * @return mixed
95
88
*/
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
98
101
}
99
102
100
103
/**
@@ -111,34 +114,33 @@ public function flush_widget_cache() {
111
114
public function update ( $ new_instance , $ old_instance ) {
112
115
113
116
foreach ( $ this ->fields as $ field ) {
114
- $ instance [$ field ] = $ new_instance [$ field ];
117
+ $ instance [ $ field ] = $ new_instance [ $ field ];
115
118
}
116
119
117
120
return $ instance ;
118
121
}
119
122
120
123
/**
121
- * Generates the administration form for the widget.
124
+ * Return the widget slug .
122
125
*
123
126
* @since 0.0.1
124
127
* @access public
125
128
*
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
127
138
*
128
- * @return mixed
139
+ * @since 0.0.1
140
+ * @access public
129
141
*/
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 ' );
142
144
}
143
145
144
146
}
0 commit comments