-
Notifications
You must be signed in to change notification settings - Fork 0
/
MM_Favorites_Widget.php
51 lines (35 loc) · 1.27 KB
/
MM_Favorites_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
<?php
class MM_Favorites_Widget extends WP_Widget{
//Настройка вида (название, описание) виджета в списе виджетов
public function __construct(){
$args=[
'name' => 'Favorite posts',
'description' => 'Showing list of favorite user posts'
];
//mm-favorites-widget - идентификатор, применяется в class
parent::__construct('mm-favorites-widget','',$args);
}
//Форма виджета в админке
public function form($instance){
var_dump($instance);
extract($instance);
$title = !empty($title)? esc_attr($title):'Favorite posts';
?>
<p>
<label for ="<?php echo $this->get_field_id('title') ?>">Title:</label>
<input type="text" name="<?php echo $this->get_field_name('title')?> " value="<?php echo $instance['title'] ?>" id="<?php echo $this->get_field_id('title') ?>" class="widefat">
</p>
<?php
}
// виджет в пользовательской части
//$args - массив разметки
public function widget($args, $instance){
if(!is_user_logged_in())return;
echo $args['before_widget'];
echo $args['before_title'];
echo $instance['title'];
echo $args['after_title'];
mm_show_dashboard_widget();
echo $args['after_widget'];
}
}