-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbarehtmlwidget.php
More file actions
65 lines (60 loc) · 1.82 KB
/
Copy pathbarehtmlwidget.php
File metadata and controls
65 lines (60 loc) · 1.82 KB
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
<?php
/*
Plugin Name: BareHtmlWidget
Plugin URI: http://chinotsubo.com/barehtmlwidget
Description: Output **bare** html snippet as a widget.
Version: 1.0
Author: Motoyan
Author URI: http://chinotsubo.com/
License: GPLv2
*/
class BareHtmlWidget extends WP_Widget{
/**
* Register this widget.
*/
function __construct() {
parent::__construct(
'bare_html_widget', // Base ID
'BareHtmlWidget', // Name
array( 'description' => 'Bare Html Widget is the widget to implements tiny html snippet without any wrapper html codes. This is used to display Google Adsense and so on.', ) // Args
);
}
/**
* display this Widget
*
* @param array $args 'register_sidebar'
* @param array $instance instance
*/
public function widget( $args, $instance ) {
$snippet = $instance['snippet'];
echo $snippet;
}
/** display this Widget's control panel
*
* @param array $instance instance
* @return string|void
*/
public function form( $instance ){
$snippet = $instance['snippet'];
$snippet_name = $this->get_field_name('snippet');
$snippet_id = $this->get_field_id('snippet');
?>
<p>
<textarea class="widefat" id="<?php echo $snippet_id; ?>" name="<?php echo $snippet_name; ?>"><?php echo esc_html( $snippet ); ?></textarea>
</p>
<?php
}
/**
* validate new parameters
*
* @param array $new_instance new_instance made at form()
* @param array $old_instance old instance
* @return array
*/
function update($new_instance, $old_instance) {
return $new_instance;
}
}
add_action( 'widgets_init', function () {
register_widget( 'BareHtmlWidget' ); //register widget
} );