-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtpm_widget_sidebar.inc.php
executable file
·106 lines (81 loc) · 3.1 KB
/
tpm_widget_sidebar.inc.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* Add function to widgets_init that'll load our widget.
* @since 0.1
*/
add_action( 'widgets_init', 'tpm_load_widgets' );
/**
* Register our widget.
* 'Topperss_Widget' is the widget class used below.
*
* @since 0.1
*/
function tpm_load_widgets() {
register_widget( 'Tinypay_Top_Widget' );
}
/**
* Topperss Widget class.
* This class handles everything that needs to be handled with the widget:
* the settings, form, display, and update. Nice!
*
* @since 0.1
*/
class Tinypay_Top_Widget extends WP_Widget {
/**
* Widget setup.
*/
function Tinypay_Top_Widget() {
/* Widget settings. */
$widget_ops = array( 'classname' => 'default', 'description' => __('Tinypay top items widget', 'default') );
/* Widget control settings. */
$control_ops = array( 'width' => 300, 'height' => 350, 'id_base' => 'tpm-top-widget' );
/* Create the widget. */
$this->WP_Widget( 'tpm-top-widget', __('Tinypay top items widget', 'default'), $widget_ops, $control_ops );
}
/**
* How to display the widget on the screen.
*/
function widget( $args, $instance ) {
extract( $args );
/* Our variables from the widget settings. */
$tpm_sidebar_title = apply_filters('widget_title', $instance['tpm_sidebar_title'] );
$tpm_sidebar_number = $instance['tpm_sidebar_number'];
/* Before widget (defined by themes). */
echo $before_widget;
include ('tpm_widget_sidebar.tpl.php');
/* After widget (defined by themes). */
echo $after_widget;
}
/**
* Update the widget settings.
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
/* Strip tags for title and number to remove HTML (important for text inputs). */
$instance['tpm_sidebar_title'] = strip_tags( $new_instance['tpm_sidebar_title'] );
$instance['tpm_sidebar_number'] = strip_tags( $new_instance['tpm_sidebar_number'] );
return $instance;
}
/**
* Displays the widget settings controls on the widget panel.
* Make use of the get_field_id() and get_field_name() function
* when creating your form elements. This handles the confusing stuff.
*/
function form( $instance ) {
/* Set up some default widget settings. */
$defaults = array( 'tpm_sidebar_title' => __('Marketplace top items', 'default'), 'tpm_sidebar_number' => __('4', 'default'));
$instance = wp_parse_args( (array) $instance, $defaults ); ?>
<!-- Widget Title: Text Input -->
<p>
<label for="<?php echo $this->get_field_id( 'tpm_sidebar_title' ); ?>"><?php _e('Title:', 'hybrid'); ?></label>
<input id="<?php echo $this->get_field_id( 'tpm_sidebar_title' ); ?>" name="<?php echo $this->get_field_name( 'tpm_sidebar_title' ); ?>" value="<?php echo $instance['tpm_sidebar_title']; ?>" style="width:100%;" />
</p>
<!-- Number of items: Text Input -->
<p>
<label for="<?php echo $this->get_field_id( 'tpm_sidebar_number' ); ?>"><?php _e('Number of items to display:', '4'); ?></label>
<input id="<?php echo $this->get_field_id( 'tpm_sidebar_number' ); ?>" name="<?php echo $this->get_field_name( 'tpm_sidebar_number' ); ?>" value="<?php echo $instance['tpm_sidebar_number']; ?>" style="width:30%;" />
</p>
<?php
}
}
?>