-
Notifications
You must be signed in to change notification settings - Fork 2
/
hdfys_widget.php
81 lines (69 loc) · 1.83 KB
/
hdfys_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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* Widget
*
* @link https://developer.wordpress.org/themes/functionality/widgets/
*
* @package Hello Dolly For Your Song
* @since 0.17
*/
// Avoids code execution if WordPress is not loaded (Security Measure)
if (!defined('ABSPATH'))
{
exit;
}
/**
* Create the unbelievable widget ;-)
*
* @since 0.4
*/
class hdfys_widget extends WP_Widget {
// Widget Definition
public function __construct() {
parent::__construct(
'hdfys_widget',
'Hello Dolly For Your Song',
array( 'description' => __( 'Displays a random line of your text', 'hello-dolly-for-your-song' ), )
);
}
// Widget Output
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
$widget_line=hdfys_get_anything();
echo '<aside class="widget hdfys">';
echo '<h3 class="widget-title hdfys">';
if ( ! empty( $title ) )
echo esc_html($title);
echo '</h3>';
echo '<p class="widget-hdfys">'.esc_html($widget_line).'</p>';
echo '</aside>';
}
// Widget Form
public function form( $instance ) {
if ( isset( $instance[ 'title' ] ) ) {
$title = $instance[ 'title' ];
}
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
</p>
<?php
}
// Widget Update
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
}
/**
* Activate the widget.
*
* @since 0.4
*/
function register_hdfys_widget() {
register_widget( 'hdfys_widget' );
}
add_action( 'widgets_init', 'register_hdfys_widget' );
?>