forked from WPGov/telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwidget.php
50 lines (45 loc) · 3 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
<?php
class telegram_widget extends WP_Widget {
function __construct() {
parent::__construct(
'telegram_widget',
'Telegram',
array( 'description' => __( 'Add bot or channel link to your website', 'telegram-bot' ), )
);
}
public 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'];
}
($instance['target']=='bot')?$link = 'https://telegram.me/'.telegram_option('username'):$link='https://telegram.me/'.str_replace('@', '', telegram_option('channelusername'));
echo '<a href="'.$link.'" style="background: #28a5e7; border-radius: 2px; color: white; padding: 5px 10px; display: inline-block; margin: 10px; font-size: 12px; cursor: pointer;">
<img src="'.plugins_url().'/telegram-bot/img/telegramiconmini.jpg" style="float:left; width: 24px; margin: 0 10px 0 0;" alt="telegram-icon">'.$instance['text'].'</a>';
echo $args['after_widget'];
}
public function form( $instance ) {
$text = ! empty( $instance['text'] ) ? $instance['text'] : __( 'Follow us on Telegram', 'telegram-bot' );
$target = ! empty( $instance['target'] ) ? $instance['target'] : 'bot';
?>
<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( 'Text:' ); ?></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 ); ?>">
<label for="<?php echo $this->get_field_id( 'target' ); ?> "><?php _e('Target', 'telegram-bot'); ?>:</label>
<select id="<?php echo $this->get_field_id( 'target' ); ?>" name="<?php echo $this->get_field_name( 'target' ); ?>">
<option value="bot" <?php echo ($target=='bot')?'selected':''; ?>><?php _e('Bot', 'telegram-bot'); ?></option>
<option value="channel" <?php echo ($target=='channel')?'selected':''; ?>><?php _e('Channel', 'telegram-bot'); ?></option>
</select>
</p>
<?php
}
public function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['text'] = strip_tags($new_instance['text']);
$instance['target'] = strip_tags($new_instance['target']);
return $instance;
}
}
?>