forked from NickCL2/ultimate-posts-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathultimate-posts-widget.php
More file actions
724 lines (598 loc) · 32.9 KB
/
ultimate-posts-widget.php
File metadata and controls
724 lines (598 loc) · 32.9 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
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
<?php
/*
Plugin Name: Ultimate Posts Widget
Plugin URI: http://wordpress.org/plugins/ultimate-posts-widget/
Description: The ultimate widget for displaying posts, custom post types or sticky posts with an array of options.
Version: 2.0.5
Author: Boston Dell-Vandenberg
Author URI: http://pomelodesign.com
Text Domain: upw
Domain Path: /languages/
License: MIT
*/
if ( !class_exists( 'WP_Widget_Ultimate_Posts' ) ) {
class WP_Widget_Ultimate_Posts extends WP_Widget {
function __construct() {
$widget_options = array(
'classname' => 'widget_ultimate_posts',
'description' => __( 'Displays list of posts with an array of options', 'upw' )
);
$control_options = array(
'width' => 450
);
parent::__construct(
'sticky-posts',
__( 'Ultimate Posts', 'upw' ),
$widget_options,
$control_options
);
$this->alt_option_name = 'widget_ultimate_posts';
add_action('save_post', array(&$this, 'flush_widget_cache'));
add_action('deleted_post', array(&$this, 'flush_widget_cache'));
add_action('switch_theme', array(&$this, 'flush_widget_cache'));
add_action('admin_enqueue_scripts', array(&$this, 'enqueue_admin_scripts'));
if (apply_filters('upw_enqueue_styles', true) && !is_admin()) {
add_action('wp_enqueue_scripts', array(&$this, 'enqueue_theme_scripts'));
}
load_plugin_textdomain('upw', false, basename( dirname( __FILE__ ) ) . '/languages' );
}
function enqueue_admin_scripts() {
wp_register_style('upw_admin_styles', plugins_url('css/upw-admin.min.css', __FILE__));
wp_enqueue_style('upw_admin_styles');
wp_register_script('upw_admin_scripts', plugins_url('js/upw-admin.min.js', __FILE__), array('jquery'), null, true);
wp_enqueue_script('upw_admin_scripts');
}
function enqueue_theme_scripts() {
wp_register_style('upw_theme_standard', plugins_url('css/upw-theme-standard.min.css', __FILE__));
wp_enqueue_style('upw_theme_standard');
}
function widget( $args, $instance ) {
global $post;
$current_post_id = $post->ID;
$cache = wp_cache_get( 'widget_ultimate_posts', 'widget' );
if ( !is_array( $cache ) )
$cache = array();
if ( isset( $cache[$args['widget_id']] ) ) {
echo $cache[$args['widget_id']];
return;
}
ob_start();
extract( $args );
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title'], $instance, $this->id_base);
$title_link = $instance['title_link'];
$class = $instance['class'];
$number = empty($instance['number']) ? -1 : $instance['number'];
$types = empty($instance['types']) ? 'any' : explode(',', $instance['types']);
$cats = empty($instance['cats']) ? '' : explode(',', $instance['cats']);
$tags = empty($instance['tags']) ? '' : explode(',', $instance['tags']);
$atcat = $instance['atcat'] ? true : false;
$thumb_size = $instance['thumb_size'];
$attag = $instance['attag'] ? true : false;
$excerpt_length = $instance['excerpt_length'];
$excerpt_readmore = $instance['excerpt_readmore'];
$sticky = $instance['sticky'];
$order = $instance['order'];
$orderby = $instance['orderby'];
$meta_key = $instance['meta_key'];
$custom_fields = $instance['custom_fields'];
// Sticky posts
if ($sticky == 'only') {
$sticky_query = array( 'post__in' => get_option( 'sticky_posts' ) );
} elseif ($sticky == 'hide') {
$sticky_query = array( 'post__not_in' => get_option( 'sticky_posts' ) );
} else {
$sticky_query = null;
}
// If $atcat true and in category
if ($atcat && is_category()) {
$cats = get_query_var('cat');
}
// If $atcat true and is single post
if ($atcat && is_single()) {
$cats = '';
foreach (get_the_category() as $catt) {
$cats .= $catt->term_id.' ';
}
$cats = str_replace(' ', ',', trim($cats));
}
// If $attag true and in tag
if ($attag && is_tag()) {
$tags = get_query_var('tag_id');
}
// If $attag true and is single post
if ($attag && is_single()) {
$tags = '';
$thetags = get_the_tags();
if ($thetags) {
foreach ($thetags as $tagg) {
$tags .= $tagg->term_id . ' ';
}
}
$tags = str_replace(' ', ',', trim($tags));
}
// Excerpt more filter
$new_excerpt_more = create_function('$more', 'return "...";');
add_filter('excerpt_more', $new_excerpt_more);
// Excerpt length filter
$new_excerpt_length = create_function('$length', "return " . $excerpt_length . ";");
if ( $instance['excerpt_length'] > 0 ) add_filter('excerpt_length', $new_excerpt_length);
if( $class ) {
$before_widget = str_replace('class="', 'class="'. $class . ' ', $before_widget);
}
echo $before_widget;
if ( $title ) {
echo $before_title;
if ( $title_link ) echo "<a href='$title_link'>";
echo $title;
if ( $title_link ) echo '</a>';
echo $after_title;
}
$args = array(
'posts_per_page' => $number,
'order' => $order,
'orderby' => $orderby,
'category__in' => $cats,
'tag__in' => $tags,
'post_type' => $types
);
if ($orderby === 'meta_value') {
$args['meta_key'] = $meta_key;
}
if (!empty($sticky_query)) {
$args[key($sticky_query)] = reset($sticky_query);
}
$args = apply_filters('upw_wp_query_args', $args, $instance, $this->id_base);
$upw_query = new WP_Query($args);
if ($instance['template'] === 'custom') {
$custom_template_path = apply_filters('upw_custom_template_path', '/upw/' . $instance['template_custom'] . '.php', $instance, $this->id_base);
if (locate_template($custom_template_path)) {
include get_stylesheet_directory() . $custom_template_path;
} else {
include 'templates/standard.php';
}
} elseif ($instance['template']) {
include 'templates/' . $instance['template'] . '.php';
} else {
include 'templates/legacy.php';
}
// Reset the global $the_post as this query will have stomped on it
wp_reset_postdata();
echo $after_widget;
if ($cache) {
$cache[$args['widget_id']] = ob_get_flush();
}
wp_cache_set( 'widget_ultimate_posts', $cache, 'widget' );
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['class'] = strip_tags( $new_instance['class']);
$instance['title_link'] = strip_tags( $new_instance['title_link'] );
$instance['number'] = strip_tags( $new_instance['number'] );
$instance['types'] = (isset( $new_instance['types'] )) ? implode(',', (array) $new_instance['types']) : '';
$instance['cats'] = (isset( $new_instance['cats'] )) ? implode(',', (array) $new_instance['cats']) : '';
$instance['tags'] = (isset( $new_instance['tags'] )) ? implode(',', (array) $new_instance['tags']) : '';
$instance['atcat'] = isset( $new_instance['atcat'] );
$instance['attag'] = isset( $new_instance['attag'] );
$instance['show_excerpt'] = isset( $new_instance['show_excerpt'] );
$instance['show_content'] = isset( $new_instance['show_content'] );
$instance['show_thumbnail'] = isset( $new_instance['show_thumbnail'] );
$instance['show_date'] = isset( $new_instance['show_date'] );
$instance['date_format'] = strip_tags( $new_instance['date_format'] );
$instance['show_title'] = isset( $new_instance['show_title'] );
$instance['show_author'] = isset( $new_instance['show_author'] );
$instance['show_comments'] = isset( $new_instance['show_comments'] );
$instance['thumb_size'] = strip_tags( $new_instance['thumb_size'] );
$instance['show_readmore'] = isset( $new_instance['show_readmore']);
$instance['excerpt_length'] = strip_tags( $new_instance['excerpt_length'] );
$instance['excerpt_readmore'] = strip_tags( $new_instance['excerpt_readmore'] );
$instance['sticky'] = $new_instance['sticky'];
$instance['order'] = $new_instance['order'];
$instance['orderby'] = $new_instance['orderby'];
$instance['meta_key'] = $new_instance['meta_key'];
$instance['show_cats'] = isset( $new_instance['show_cats'] );
$instance['show_tags'] = isset( $new_instance['show_tags'] );
$instance['custom_fields'] = strip_tags( $new_instance['custom_fields'] );
$instance['template'] = strip_tags( $new_instance['template'] );
$instance['template_custom'] = strip_tags( $new_instance['template_custom'] );
if (current_user_can('unfiltered_html')) {
$instance['before_posts'] = $new_instance['before_posts'];
$instance['after_posts'] = $new_instance['after_posts'];
} else {
$instance['before_posts'] = wp_filter_post_kses($new_instance['before_posts']);
$instance['after_posts'] = wp_filter_post_kses($new_instance['after_posts']);
}
$this->flush_widget_cache();
$alloptions = wp_cache_get( 'alloptions', 'options' );
if ( isset( $alloptions['widget_ultimate_posts'] ) )
delete_option( 'widget_ultimate_posts' );
return $instance;
}
function flush_widget_cache() {
wp_cache_delete( 'widget_ultimate_posts', 'widget' );
}
function form( $instance ) {
// Set default arguments
$instance = wp_parse_args( (array) $instance, array(
'title' => __('Ultimate Posts', 'upw'),
'class' => '',
'title_link' => '' ,
'number' => '5',
'types' => 'post',
'cats' => '',
'tags' => '',
'atcat' => false,
'thumb_size' => 'thumbnail',
'attag' => false,
'excerpt_length' => 10,
'excerpt_readmore' => __('Read more →', 'upw'),
'order' => 'DESC',
'orderby' => 'date',
'meta_key' => '',
'sticky' => 'show',
'show_cats' => false,
'show_tags' => false,
'show_title' => true,
'show_date' => true,
'date_format' => get_option('date_format') . ' ' . get_option('time_format'),
'show_author' => true,
'show_comments' => false,
'show_excerpt' => true,
'show_content' => false,
'show_readmore' => true,
'show_thumbnail' => true,
'custom_fields' => '',
// Set template to 'legacy' if field from UPW < 2.0 is set.
'template' => empty($instance['morebutton_text']) ? 'standard' : 'legacy',
'template_custom' => '',
'before_posts' => '',
'after_posts' => ''
) );
// Or use the instance
$title = strip_tags($instance['title']);
$class = strip_tags($instance['class']);
$title_link = strip_tags($instance['title_link']);
$number = strip_tags($instance['number']);
$types = $instance['types'];
$cats = $instance['cats'];
$tags = $instance['tags'];
$atcat = $instance['atcat'];
$thumb_size = $instance['thumb_size'];
$attag = $instance['attag'];
$excerpt_length = strip_tags($instance['excerpt_length']);
$excerpt_readmore = strip_tags($instance['excerpt_readmore']);
$order = $instance['order'];
$orderby = $instance['orderby'];
$meta_key = $instance['meta_key'];
$sticky = $instance['sticky'];
$show_cats = $instance['show_cats'];
$show_tags = $instance['show_tags'];
$show_title = $instance['show_title'];
$show_date = $instance['show_date'];
$date_format = $instance['date_format'];
$show_author = $instance['show_author'];
$show_comments = $instance['show_comments'];
$show_excerpt = $instance['show_excerpt'];
$show_content = $instance['show_content'];
$show_readmore = $instance['show_readmore'];
$show_thumbnail = $instance['show_thumbnail'];
$custom_fields = strip_tags($instance['custom_fields']);
$template = $instance['template'];
$template_custom = strip_tags($instance['template_custom']);
$before_posts = format_to_edit($instance['before_posts']);
$after_posts = format_to_edit($instance['after_posts']);
// Let's turn $types, $cats, and $tags into an array if they are set
if (!empty($types)) $types = explode(',', $types);
if (!empty($cats)) $cats = explode(',', $cats);
if (!empty($tags)) $tags = explode(',', $tags);
// Count number of post types for select box sizing
$cpt_types = get_post_types( array( 'public' => true ), 'names' );
if ($cpt_types) {
foreach ($cpt_types as $cpt ) {
$cpt_ar[] = $cpt;
}
$n = count($cpt_ar);
if($n > 6) { $n = 6; }
} else {
$n = 3;
}
// Count number of categories for select box sizing
$cat_list = get_categories( 'hide_empty=0' );
if ($cat_list) {
foreach ($cat_list as $cat) {
$cat_ar[] = $cat;
}
$c = count($cat_ar);
if($c > 6) { $c = 6; }
} else {
$c = 3;
}
// Count number of tags for select box sizing
$tag_list = get_tags( 'hide_empty=0' );
if ($tag_list) {
foreach ($tag_list as $tag) {
$tag_ar[] = $tag;
}
$t = count($tag_ar);
if($t > 6) { $t = 6; }
} else {
$t = 3;
}
?>
<div class="upw-tabs">
<a class="upw-tab-item active" data-toggle="upw-tab-general"><?php _e('General', 'upw'); ?></a>
<a class="upw-tab-item" data-toggle="upw-tab-display"><?php _e('Display', 'upw'); ?></a>
<a class="upw-tab-item" data-toggle="upw-tab-filter"><?php _e('Filter', 'upw'); ?></a>
<a class="upw-tab-item" data-toggle="upw-tab-order"><?php _e('Order', 'upw'); ?></a>
</div>
<div class="upw-tab upw-tab-general">
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'upw' ); ?>:</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 $title; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'title_link' ); ?>"><?php _e( 'Title URL', 'upw' ); ?>:</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'title_link' ); ?>" name="<?php echo $this->get_field_name( 'title_link' ); ?>" type="text" value="<?php echo $title_link; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'class' ); ?>"><?php _e( 'CSS class', 'upw' ); ?>:</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'class' ); ?>" name="<?php echo $this->get_field_name( 'class' ); ?>" type="text" value="<?php echo $class; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('before_posts'); ?>"><?php _e('Before posts', 'upw'); ?>:</label>
<textarea class="widefat" id="<?php echo $this->get_field_id('before_posts'); ?>" name="<?php echo $this->get_field_name('before_posts'); ?>" rows="5"><?php echo $before_posts; ?></textarea>
</p>
<p>
<label for="<?php echo $this->get_field_id('after_posts'); ?>"><?php _e('After posts', 'upw'); ?>:</label>
<textarea class="widefat" id="<?php echo $this->get_field_id('after_posts'); ?>" name="<?php echo $this->get_field_name('after_posts'); ?>" rows="5"><?php echo $after_posts; ?></textarea>
</p>
</div>
<div class="upw-tab upw-hide upw-tab-display">
<p>
<label for="<?php echo $this->get_field_id('template'); ?>"><?php _e('Template', 'upw'); ?>:</label>
<select name="<?php echo $this->get_field_name('template'); ?>" id="<?php echo $this->get_field_id('template'); ?>" class="widefat">
<option value="legacy"<?php if( $template == 'legacy') echo ' selected'; ?>><?php _e('Legacy', 'upw'); ?></option>
<option value="standard"<?php if( $template == 'standard') echo ' selected'; ?>><?php _e('Standard', 'upw'); ?></option>
<option value="custom"<?php if( $template == 'custom') echo ' selected'; ?>><?php _e('Custom', 'upw'); ?></option>
</select>
</p>
<p<?php if ($template !== 'custom') echo ' style="display:none;"'; ?>>
<label for="<?php echo $this->get_field_id('template_custom'); ?>"><?php _e('Custom Template Name', 'upw'); ?>:</label>
<input class="widefat" id="<?php echo $this->get_field_id('template_custom'); ?>" name="<?php echo $this->get_field_name('template_custom'); ?>" type="text" value="<?php echo $template_custom; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id( 'number' ); ?>"><?php _e( 'Number of posts', 'upw' ); ?>:</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'number' ); ?>" name="<?php echo $this->get_field_name( 'number' ); ?>" type="number" value="<?php echo $number; ?>" min="-1" />
</p>
<p>
<input class="checkbox" id="<?php echo $this->get_field_id( 'show_title' ); ?>" name="<?php echo $this->get_field_name( 'show_title' ); ?>" type="checkbox" <?php checked( (bool) $show_title, true ); ?> />
<label for="<?php echo $this->get_field_id( 'show_title' ); ?>"><?php _e( 'Show title', 'upw' ); ?></label>
</p>
<p>
<input class="checkbox" id="<?php echo $this->get_field_id( 'show_date' ); ?>" name="<?php echo $this->get_field_name( 'show_date' ); ?>" type="checkbox" <?php checked( (bool) $show_date, true ); ?> />
<label for="<?php echo $this->get_field_id( 'show_date' ); ?>"><?php _e( 'Show published date', 'upw' ); ?></label>
</p>
<p<?php if (!$show_date) echo ' style="display:none;"'; ?>>
<label for="<?php echo $this->get_field_id('date_format'); ?>"><?php _e( 'Date format', 'upw' ); ?>:</label>
<input class="widefat" type="text" id="<?php echo $this->get_field_id('date_format'); ?>" name="<?php echo $this->get_field_name('date_format'); ?>" value="<?php echo $date_format; ?>" />
</p>
<p>
<input class="checkbox" id="<?php echo $this->get_field_id( 'show_author' ); ?>" name="<?php echo $this->get_field_name( 'show_author' ); ?>" type="checkbox" <?php checked( (bool) $show_author, true ); ?> />
<label for="<?php echo $this->get_field_id( 'show_author' ); ?>"><?php _e( 'Show post author', 'upw' ); ?></label>
</p>
<p>
<input class="checkbox" id="<?php echo $this->get_field_id( 'show_comments' ); ?>" name="<?php echo $this->get_field_name( 'show_comments' ); ?>" type="checkbox" <?php checked( (bool) $show_comments, true ); ?> />
<label for="<?php echo $this->get_field_id( 'show_comments' ); ?>"><?php _e( 'Show comments count', 'upw' ); ?></label>
</p>
<p>
<input class="checkbox" id="<?php echo $this->get_field_id( 'show_excerpt' ); ?>" name="<?php echo $this->get_field_name( 'show_excerpt' ); ?>" type="checkbox" <?php checked( (bool) $show_excerpt, true ); ?> />
<label for="<?php echo $this->get_field_id( 'show_excerpt' ); ?>"><?php _e( 'Show excerpt', 'upw' ); ?></label>
</p>
<p<?php if (!$show_excerpt) echo ' style="display:none;"'; ?>>
<label for="<?php echo $this->get_field_id('excerpt_length'); ?>"><?php _e( 'Excerpt length (in words)', 'upw' ); ?>:</label>
<input class="widefat" type="number" id="<?php echo $this->get_field_id('excerpt_length'); ?>" name="<?php echo $this->get_field_name('excerpt_length'); ?>" value="<?php echo $excerpt_length; ?>" min="-1" />
</p>
<p>
<input class="checkbox" id="<?php echo $this->get_field_id( 'show_content' ); ?>" name="<?php echo $this->get_field_name( 'show_content' ); ?>" type="checkbox" <?php checked( (bool) $show_content, true ); ?> />
<label for="<?php echo $this->get_field_id( 'show_content' ); ?>"><?php _e( 'Show content', 'upw' ); ?></label>
</p>
<p<?php if (!$show_excerpt && !$show_content) echo ' style="display:none;"'; ?>>
<label for="<?php echo $this->get_field_id('show_readmore'); ?>">
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_readmore'); ?>" name="<?php echo $this->get_field_name('show_readmore'); ?>"<?php checked( (bool) $show_readmore, true ); ?> />
<?php _e( 'Show read more link', 'upw' ); ?>
</label>
</p>
<p<?php if (!$show_readmore || (!$show_excerpt && !$show_content)) echo ' style="display:none;"'; ?>>
<input class="widefat" type="text" id="<?php echo $this->get_field_id('excerpt_readmore'); ?>" name="<?php echo $this->get_field_name('excerpt_readmore'); ?>" value="<?php echo $excerpt_readmore; ?>" />
</p>
<?php if ( function_exists('the_post_thumbnail') && current_theme_supports( 'post-thumbnails' ) ) : ?>
<?php $sizes = get_intermediate_image_sizes(); ?>
<p>
<input class="checkbox" id="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>" name="<?php echo $this->get_field_name( 'show_thumbnail' ); ?>" type="checkbox" <?php checked( (bool) $show_thumbnail, true ); ?> />
<label for="<?php echo $this->get_field_id( 'show_thumbnail' ); ?>"><?php _e( 'Show thumbnail', 'upw' ); ?></label>
</p>
<p<?php if (!$show_thumbnail) echo ' style="display:none;"'; ?>>
<select id="<?php echo $this->get_field_id('thumb_size'); ?>" name="<?php echo $this->get_field_name('thumb_size'); ?>" class="widefat">
<?php foreach ($sizes as $size) : ?>
<option value="<?php echo $size; ?>"<?php if ($thumb_size == $size) echo ' selected'; ?>><?php echo $size; ?></option>
<?php endforeach; ?>
<option value="full"<?php if ($thumb_size == $size) echo ' selected'; ?>><?php _e('full'); ?></option>
</select>
</p>
<?php endif; ?>
<p>
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_cats'); ?>" name="<?php echo $this->get_field_name('show_cats'); ?>" <?php checked( (bool) $show_cats, true ); ?> />
<label for="<?php echo $this->get_field_id('show_cats'); ?>"> <?php _e('Show post categories', 'upw'); ?></label>
</p>
<p>
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('show_tags'); ?>" name="<?php echo $this->get_field_name('show_tags'); ?>" <?php checked( (bool) $show_tags, true ); ?> />
<label for="<?php echo $this->get_field_id('show_tags'); ?>"> <?php _e('Show post tags', 'upw'); ?></label>
</p>
<p>
<label for="<?php echo $this->get_field_id( 'custom_fields' ); ?>"><?php _e( 'Show custom fields (comma separated)', 'upw' ); ?>:</label>
<input class="widefat" id="<?php echo $this->get_field_id( 'custom_fields' ); ?>" name="<?php echo $this->get_field_name( 'custom_fields' ); ?>" type="text" value="<?php echo $custom_fields; ?>" />
</p>
</div>
<div class="upw-tab upw-hide upw-tab-filter">
<p>
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('atcat'); ?>" name="<?php echo $this->get_field_name('atcat'); ?>" <?php checked( (bool) $atcat, true ); ?> />
<label for="<?php echo $this->get_field_id('atcat'); ?>"> <?php _e('Show posts only from current category', 'upw');?></label>
</p>
<p>
<label for="<?php echo $this->get_field_id('cats'); ?>"><?php _e( 'Categories', 'upw' ); ?>:</label>
<select name="<?php echo $this->get_field_name('cats'); ?>[]" id="<?php echo $this->get_field_id('cats'); ?>" class="widefat" style="height: auto;" size="<?php echo $c ?>" multiple>
<option value="" <?php if (empty($cats)) echo 'selected="selected"'; ?>><?php _e('– Show All –') ?></option>
<?php
$categories = get_categories( 'hide_empty=0' );
foreach ($categories as $category ) { ?>
<option value="<?php echo $category->term_id; ?>" <?php if(is_array($cats) && in_array($category->term_id, $cats)) echo 'selected="selected"'; ?>><?php echo $category->cat_name;?></option>
<?php } ?>
</select>
</p>
<?php if ($tag_list) : ?>
<p>
<input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('attag'); ?>" name="<?php echo $this->get_field_name('attag'); ?>" <?php checked( (bool) $attag, true ); ?> />
<label for="<?php echo $this->get_field_id('attag'); ?>"> <?php _e('Show posts only from current tag', 'upw');?></label>
</p>
<p>
<label for="<?php echo $this->get_field_id('tags'); ?>"><?php _e( 'Tags', 'upw' ); ?>:</label>
<select name="<?php echo $this->get_field_name('tags'); ?>[]" id="<?php echo $this->get_field_id('tags'); ?>" class="widefat" style="height: auto;" size="<?php echo $t ?>" multiple>
<option value="" <?php if (empty($tags)) echo 'selected="selected"'; ?>><?php _e('– Show All –') ?></option>
<?php
foreach ($tag_list as $tag) { ?>
<option value="<?php echo $tag->term_id; ?>" <?php if (is_array($tags) && in_array($tag->term_id, $tags)) echo 'selected="selected"'; ?>><?php echo $tag->name;?></option>
<?php } ?>
</select>
</p>
<?php endif; ?>
<p>
<label for="<?php echo $this->get_field_id('types'); ?>"><?php _e( 'Post types', 'upw' ); ?>:</label>
<select name="<?php echo $this->get_field_name('types'); ?>[]" id="<?php echo $this->get_field_id('types'); ?>" class="widefat" style="height: auto;" size="<?php echo $n ?>" multiple>
<option value="" <?php if (empty($types)) echo 'selected="selected"'; ?>><?php _e('– Show All –') ?></option>
<?php
$args = array( 'public' => true );
$post_types = get_post_types( $args, 'names' );
foreach ($post_types as $post_type ) { ?>
<option value="<?php echo $post_type; ?>" <?php if(is_array($types) && in_array($post_type, $types)) { echo 'selected="selected"'; } ?>><?php echo $post_type;?></option>
<?php } ?>
</select>
</p>
<p>
<label for="<?php echo $this->get_field_id('sticky'); ?>"><?php _e( 'Sticky posts', 'upw' ); ?>:</label>
<select name="<?php echo $this->get_field_name('sticky'); ?>" id="<?php echo $this->get_field_id('sticky'); ?>" class="widefat">
<option value="show"<?php if( $sticky === 'show') echo ' selected'; ?>><?php _e('Show All Posts', 'upw'); ?></option>
<option value="hide"<?php if( $sticky == 'hide') echo ' selected'; ?>><?php _e('Hide Sticky Posts', 'upw'); ?></option>
<option value="only"<?php if( $sticky == 'only') echo ' selected'; ?>><?php _e('Show Only Sticky Posts', 'upw'); ?></option>
</select>
</p>
</div>
<div class="upw-tab upw-hide upw-tab-order">
<p>
<label for="<?php echo $this->get_field_id('orderby'); ?>"><?php _e('Order by', 'upw'); ?>:</label>
<select name="<?php echo $this->get_field_name('orderby'); ?>" id="<?php echo $this->get_field_id('orderby'); ?>" class="widefat">
<option value="date"<?php if( $orderby == 'date') echo ' selected'; ?>><?php _e('Published Date', 'upw'); ?></option>
<option value="title"<?php if( $orderby == 'title') echo ' selected'; ?>><?php _e('Title', 'upw'); ?></option>
<option value="comment_count"<?php if( $orderby == 'comment_count') echo ' selected'; ?>><?php _e('Comment Count', 'upw'); ?></option>
<option value="rand"<?php if( $orderby == 'rand') echo ' selected'; ?>><?php _e('Random'); ?></option>
<option value="meta_value"<?php if( $orderby == 'meta_value') echo ' selected'; ?>><?php _e('Custom Field', 'upw'); ?></option>
<option value="menu_order"<?php if( $orderby == 'menu_order') echo ' selected'; ?>><?php _e('Menu Order', 'upw'); ?></option>
</select>
</p>
<p<?php if ($orderby !== 'meta_value') echo ' style="display:none;"'; ?>>
<label for="<?php echo $this->get_field_id( 'meta_key' ); ?>"><?php _e('Custom field', 'upw'); ?>:</label>
<input class="widefat" id="<?php echo $this->get_field_id('meta_key'); ?>" name="<?php echo $this->get_field_name('meta_key'); ?>" type="text" value="<?php echo $meta_key; ?>" />
</p>
<p>
<label for="<?php echo $this->get_field_id('order'); ?>"><?php _e('Order', 'upw'); ?>:</label>
<select name="<?php echo $this->get_field_name('order'); ?>" id="<?php echo $this->get_field_id('order'); ?>" class="widefat">
<option value="DESC"<?php if( $order == 'DESC') echo ' selected'; ?>><?php _e('Descending', 'upw'); ?></option>
<option value="ASC"<?php if( $order == 'ASC') echo ' selected'; ?>><?php _e('Ascending', 'upw'); ?></option>
</select>
</p>
</div>
<p class="upw-credits">
<?php _e('Enjoy this plugin? Please <a href="http://pomelodesign.com/donate/" target="_blank">donate to support development</a>.', 'upw'); ?>
</p>
<?php if ( $instance ) { ?>
<script>
jQuery(document).ready(function($){
var show_excerpt = $("#<?php echo $this->get_field_id( 'show_excerpt' ); ?>");
var show_content = $("#<?php echo $this->get_field_id( 'show_content' ); ?>");
var show_readmore = $("#<?php echo $this->get_field_id( 'show_readmore' ); ?>");
var show_readmore_wrap = $("#<?php echo $this->get_field_id( 'show_readmore' ); ?>").parents('p');
var show_thumbnail = $("#<?php echo $this->get_field_id( 'show_thumbnail' ); ?>");
var show_date = $("#<?php echo $this->get_field_id( 'show_date' ); ?>");
var date_format = $("#<?php echo $this->get_field_id( 'date_format' ); ?>").parents('p');
var excerpt_length = $("#<?php echo $this->get_field_id( 'excerpt_length' ); ?>").parents('p');
var excerpt_readmore_wrap = $("#<?php echo $this->get_field_id( 'excerpt_readmore' ); ?>").parents('p');
var thumb_size_wrap = $("#<?php echo $this->get_field_id( 'thumb_size' ); ?>").parents('p');
var order = $("#<?php echo $this->get_field_id('orderby'); ?>");
var meta_key_wrap = $("#<?php echo $this->get_field_id( 'meta_key' ); ?>").parents('p');
var template = $("#<?php echo $this->get_field_id('template'); ?>");
var template_custom = $("#<?php echo $this->get_field_id('template_custom'); ?>").parents('p');
var toggleReadmore = function() {
if (show_excerpt.is(':checked') || show_content.is(':checked')) {
show_readmore_wrap.show('fast');
} else {
show_readmore_wrap.hide('fast');
}
toggleExcerptReadmore();
}
var toggleExcerptReadmore = function() {
if ((show_excerpt.is(':checked') || show_content.is(':checked')) && show_readmore.is(':checked')) {
excerpt_readmore_wrap.show('fast');
} else {
excerpt_readmore_wrap.hide('fast');
}
}
// Toggle read more option
show_excerpt.click(function() {
toggleReadmore();
});
// Toggle read more option
show_content.click(function() {
toggleReadmore();
});
// Toggle excerpt length on click
show_excerpt.click(function(){
excerpt_length.toggle('fast');
});
// Toggle excerpt length on click
show_readmore.click(function(){
toggleExcerptReadmore();
});
// Toggle date format on click
show_date.click(function(){
date_format.toggle('fast');
});
// Toggle excerpt length on click
show_thumbnail.click(function(){
thumb_size_wrap.toggle('fast');
});
// Show or hide custom field meta_key value on order change
order.change(function(){
if ($(this).val() === 'meta_value') {
meta_key_wrap.show('fast');
} else {
meta_key_wrap.hide('fast');
}
});
// Show or hide custom template field
template.change(function(){
if ($(this).val() === 'custom') {
template_custom.show('fast');
} else {
template_custom.hide('fast');
}
});
});
</script>
<?php
}
}
}
function init_wp_widget_ultimate_posts() {
register_widget( 'WP_Widget_Ultimate_Posts' );
}
add_action( 'widgets_init', 'init_wp_widget_ultimate_posts' );
}