-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathwidget.php
More file actions
84 lines (74 loc) · 2.18 KB
/
widget.php
File metadata and controls
84 lines (74 loc) · 2.18 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
// Register and load the widget
function wpb_load_widget() {
register_widget( 'gitHub' );
}
add_action( 'widgets_init', 'wpb_load_widget' );
/**
* Widget class
*
*/
class gitHub extends WP_Widget {
private $fields = array('title' => '','url'=>'');
private $descrField = array('title' => 'Title widget','url'=>'Url to get info');
public function __construct() {//конструктор
parent::__construct("gitHub", "Echo info on url GitHub", array("description" => "Echo info on url GitHub"));
}
/**
* Work on frontend
*
* @param array $args
* @param array $instance
*/
public function widget($args, $instance) {
global $github_embed;
//$instance = defaultValue($instance, $this->fields);
echo $instance['title'];
//echo $instance['url'];
echo $github_embed->mechanicUrl($instance['url'],true)->html;
}
/**
* Work on backend interface
*
* @param array $instance
*/
public function form($instance) {
$this->genField($instance);
}
/**
* Update Settings
*
* @param array $newInstance
* @param array $oldInstance
* @return array
*/
public function update($newInstance, $oldInstance) {//
return $this->genField($newInstance, true);
}
/**
* Gen fields in backend
*
* @param array $instance
* @param array $update
* @return boolean
*/
private function genField($instance, $update = false) {
if ($update) {
$ret = array();
foreach ($this->fields as $k => $v) {
$ret[$k] = $instance[$k];
}
return $ret;
}
foreach ($this->fields as $k => $v) {
$tableId = $this->get_field_id($k);
$tableName = $this->get_field_name($k);
if (isset($instance[$k]))
$value = $instance[$k];
else
$value = '';
echo '<p><label>' . $this->descrField[$k] . '</label><br><input id="' . $tableId . '" type="text" name="' . $tableName . '" value="' . $value . '" placeholder="' . $v . '" class="widefat"></p>';
}
}
}
?>