-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuwebdesign-widgets.php
274 lines (227 loc) · 7.96 KB
/
uwebdesign-widgets.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?php
/**
* Plugin Name: uWebDesign Widgets
* Plugin URI: https://github.com/websanya/uwebdesign-widgets
* Description: Плагин с виджетами для комьюнити сайта uWebDesign.
* Version: 1.1.7
* Author: Alexander Goncharov
* Author URI: https://websanya.ru
* GitHub Plugin URI: https://github.com/websanya/uwebdesign-widgets
* GitHub Branch: master
*/
/**
* Creating the widget for displaying ad banners.
*/
class uwd_widget_banner extends WP_Widget {
function __construct() {
parent::__construct(
'uwd_banner_widget', //* Widget ID.
'[uWebDesign] Баннер в сайдбар', //* Widget Title.
array(
'description' => 'Случайным образом выбирает баннер и отображает его',
) //* Widget Description.
);
}
//* Creating widget front-end. This is where the action happens.
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
//* Before and after widget arguments are defined by themes.
echo $args['before_widget'];
if ( ! empty( $title ) ) {
echo $args['before_title'] . $title . $args['after_title'];
} else {
$args['before_title'] = '<h5 class="widget-title widgettitle screen-reader-text">';
$no_title = true;
}
$query_args = array(
'post_type' => 'banner',
'orderby' => 'rand',
'posts_per_page' => 1,
);
$query = new WP_Query( $query_args );
while ( $query->have_posts() ) : $query->the_post();
if ( ! empty( $no_title ) ) {
echo $args['before_title'] . get_the_title() . $args['after_title'];
}
?>
<a href="<?php the_field( 'banner_url' ); ?>?ban=sidebar" rel="nofollow">
<img width="770" height="770" src="<?php the_field( 'banner_img_sidebar' ); ?>"
alt="<?php the_title(); ?>">
</a>
<?php
endwhile;
//* Reset Post Data.
wp_reset_postdata();
echo $args['after_widget'];
}
//* Widget Backend.
public function form( $instance ) {
if ( isset( $instance['title'] ) ) {
$title = $instance['title'];
} else {
$title = '';
}
//* Widget admin form.
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php echo 'Заголовок'; ?></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 ); ?>"/>
</p>
<?php
}
//* Updating widget replacing old instances with new.
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
}
/**
* Creating the widget for displaying podcast themes.
*/
class uwd_widget_themes extends WP_Widget {
function __construct() {
parent::__construct(
'uwd_widget_themes', //* Widget ID.
'[uWebDesign] Темы к подкасту в сайдбар', //* Widget Title.
array(
'description' => 'Темы к крайнему подкасту в сайдбар',
) //* Widget Description.
);
}
//* Creating widget front-end. This is where the action happens.
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
$query_args = array(
'post_type' => 'post',
'posts_per_page' => 1,
'tax_query' => array(
array(
'taxonomy' => 'category',
'field' => 'slug',
'terms' => 'podcast-topics',
),
),
);
$query = new WP_Query( $query_args );
$query->the_post();
//* Before and after widget arguments are defined by themes.
echo $args['before_widget'];
$comments = ' <small class="uwd-widget-meta">(' . russian_comments( get_comments_number( get_the_ID() ), array(
'комментарий',
'комментария',
'комментариев',
) ) . ')</small>';
if ( ! empty( $title ) ) {
echo $args['before_title'] . $title . $comments . $args['after_title'];
} else {
echo $args['before_title'] . 'Темы к ближайшему подкасту' . ' ' . $comments . ' ' . $args['after_title'];
}
?>
<a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail( 'medium' ); ?>
</a>
<?php the_content(); ?>
<p>
<a href="<?php the_permalink(); ?>#respond">Предложить тему →</a>
</p>
<?php
//* Reset Post Data.
wp_reset_postdata();
echo $args['after_widget'];
}
//* Widget Backend.
public function form( $instance ) {
if ( isset( $instance['title'] ) ) {
$title = $instance['title'];
} else {
$title = '';
}
//* Widget admin form.
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php echo 'Заголовок'; ?></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 ); ?>"/>
</p>
<?php
}
//* Updating widget replacing old instances with new.
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
}
/**
* Creating the widget for displaying user flow information.
*/
class uwd_widget_userflow extends WP_Widget {
function __construct() {
parent::__construct(
'uwd_widget_userflow', //* Widget ID.
'[uWebDesign] Информация о входе и регистрации', //* Widget Title.
array(
'description' => 'Сообщения о возможность регистрации, а также входа/выхода для зарегистрированных',
) //* Widget Description.
);
}
//* Creating widget front-end. This is where the action happens.
public function widget( $args, $instance ) {
$title = apply_filters( 'widget_title', $instance['title'] );
//* Before and after widget arguments are defined by themes.
echo $args['before_widget'];
//* Cache lots of user stuff.
$current_user = wp_get_current_user();
$current_user_id = $current_user->ID;
//* Cache page urls.
$login_url = wp_login_url();
$reg_url = wp_registration_url();
$profile_url = admin_url( 'profile.php' );
$logout_url = wp_logout_url();
//* Output da instructions.
if ( $current_user_id ) {
$current_user_displayname = $current_user->data->display_name;
echo "<p>Привет, $current_user_displayname!</p>";
echo "<ul><li><a href='$profile_url'>Мой профиль</a></li><li><a href='$logout_url'>Выйти с сайта</a></li></ul>";
} else {
echo "<p>uWebDesign настоятельно рекомендует!</p>";
echo "<ul><li><a href='$login_url'>Войти на сайт</a></li><li><a href='$reg_url'>Зарегистрироваться</a></li></ul>";
}
//* Before and after widget arguments are defined by themes.
echo $args['after_widget'];
}
//* Widget Backend.
public function form( $instance ) {
if ( isset( $instance['title'] ) ) {
$title = $instance['title'];
} else {
$title = '';
}
//* Widget admin form.
?>
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php echo 'Заголовок'; ?></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 ); ?>"/>
</p>
<?php
}
//* Updating widget replacing old instances with new.
public function update( $new_instance, $old_instance ) {
$instance = array();
$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
return $instance;
}
}
//* Register and load the widget.
add_action( 'widgets_init', 'wpb_load_widget' );
function wpb_load_widget() {
register_widget( 'uwd_widget_banner' );
register_widget( 'uwd_widget_themes' );
register_widget( 'uwd_widget_userflow' );
}