-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.php
63 lines (54 loc) · 1.81 KB
/
widget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/*
* Base file for widgets
*/
class WoPP_Widget extends WP_Widget {
public $defaults;
function __construct($widget_id='wopp_widget', $widget_name=null, $widget_ops=null) {
// Widget settings
if($widget_name==null){
$widget_name=__('Widget Name', 'WoPP_locale');
}
if($widget_ops==null){
$widget_ops = array(
'classname' => 'wopp_widget someclass',
'description' => __('Explicit description.', 'WoPP_locale')
);
}
// Create the widget
parent::__construct(
$widget_id,
$widget_name,
$widget_ops
);
$this->defaults = array(
'title'=>''
);
}
// PHP4 caller
function WoPP_Widget(){
$this->__construct();
}
function widget($args, $_instance) {
$instance = wp_parse_args( (array) $_instance, $this->defaults );
echo $args['before_widget'];
if(!empty($instance['title'])){
echo $args['before_title'];
echo $instance['title'];
echo $args['after_title'];
}
// Some content here
echo $args['after_widget'];
}
function update($new_instance, $old_instance) {
return $new_instance;
}
function form($_instance) {
$instance = wp_parse_args( (array) $_instance, $this->defaults );
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title', 'WoPP_locale' ) ?></label>
<input class="widefat" name="<?php echo $this->get_field_name('title'); ?>" id="<?php echo $this->get_field_id('title'); ?>" value="<?php echo $instance['title']; ?>"/>
</p>
<?php
}
}