forked from OneSignal/OneSignal-WordPress-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathonesignal-widget.php
48 lines (39 loc) · 1.84 KB
/
onesignal-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
<?php
defined( 'ABSPATH' ) or die('This page may not be accessed directly.');
class OneSignalWidget extends WP_Widget {
function __construct() {
parent::__construct('OneSignalWidget', 'OneSignal', array( 'description' => 'Subscribe to notifications'));
}
// Admin editor
function form($instance) {
$title = ! empty( $instance['title'] ) ? $instance['title'] : 'Follow';
$text = ! empty( $instance['text'] ) ? $instance['text'] : 'Subscribe to notifications';
?>
<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 ); ?>">
<label for="<?php echo $this->get_field_id( 'text' ); ?>"><?php _e( 'Body:' ); ?></label>
<input class="widefat" id="<?php echo $this->get_field_id( 'text' ); ?>" name="<?php echo $this->get_field_name( 'text' ); ?>" type="text" value="<?php echo esc_attr( $text ); ?>">
</p>
<?php
}
function update($new_instance, $old_instance) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
$instance['text'] = ( ! empty( $new_instance['text'] ) ) ? strip_tags( $new_instance['text'] ) : '';
return $instance;
}
// Public display
function widget($args, $instance) {
echo $args['before_widget'];
if ( ! empty( $instance['title'] ) ) {
echo $args['before_title'] . apply_filters( 'widget_title', $instance['title'] ). $args['after_title'];
}
if ( ! empty( $instance['text'] ) ) {
echo '<a href="#" class="OneSignal-prompt">' . $instance['text'] . '</a>';
}
echo $args['after_widget'];
}
}
add_action('widgets_init', create_function('', 'return register_widget("OneSignalWidget");'));
?>