-
Notifications
You must be signed in to change notification settings - Fork 2
/
super-simple-related-posts.php
555 lines (458 loc) · 26.3 KB
/
super-simple-related-posts.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
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
<?php
/**
* @package Super_Simple_Related_posts
* @version 1.4
*/
/**
* Plugin Name: Super Simple Related Posts
* Plugin URI: http://mightyminnow.com
* Description: A super simple plugin to output related posts based on categories, tags, or custom taxonomies.
* Version: 1.5.4
* Author: MIGHTYminnow
* Author URI: http://mightyminnow.com
* License: GPLv2+
* Text Domain: super-simple-related-posts
* Domain Path: /languages/
*
* Coded By: Mickey Kay
*
*/
/**
* @todo Add shortcode output
*/
// Make sure we don't expose any info if called directly
if ( !function_exists( 'add_action' ) ) {
_e('Hi there! I\'m just a plugin, not much I can do when called directly.', 'super-simple-related-posts');
exit;
}
// Useful global constants
define( 'SSRP_VERSION', '1.5.4' );
define( 'SSRP_URL', plugin_dir_url( __FILE__ ) );
define( 'SSRP_PATH', dirname( __FILE__ ) . '/' );
/**
* Calls initializing function and flushes rewrite rules on plugin activation
*
* @package Super_Simple_Related_Posts
* @since 1.0
*/
function ssrp_activate() {
// First load the init scripts
ssrp_init();
flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'ssrp_activate' );
/**
* Flushes rewrite rules on plugin deactivation
*
* @package Super_Simple_Related_Posts
* @since 1.0
*/
function ssrp_deactivate() {
flush_rewrite_rules();
}
register_deactivation_hook( __FILE__, 'ssrp_deactivate' );
/**
* Registers widget and loads plugin text domain
*
* @package Super_Simple_Related_Posts
* @since 1.0
*/
function ssrp_init() {
// Register widget
register_widget( 'SSRP_Widget');
// Load plugin text domain
load_plugin_textdomain( 'super-simple-related-posts', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
add_action( 'widgets_init', 'ssrp_init' );
/**
* The main Super Simple Related Posts Widget class
*
* @package Super_Simple_Related_Posts
* @since 1.0
*/
class SSRP_Widget extends WP_Widget {
/**
* The default widget values, which is populated in __contstruct
*
* @var array
*/
public $defaults = array();
/**
* Optional array of taxonomy slugs to limit choices
*
* e.g. public $included_taxonomies = array('category', 'post_tag');
* Only 'Category' and 'Tag' will appear in the widget 'Show posts related by:' drop-down <select>
*
* @var array
*/
public $included_taxonomies = array();
/**
* PHP5 constructor - initializes widget and sets defaults
*
* @package Super_Simple_Related_Posts
* @since 1.0
*/
public function __construct() {
// Set widget options
$widget_options = array(
'classname' => 'ssrp',
'description' => __('A list of posts related to the current post/page.', 'super-simple-related-posts') );
parent::__construct('ssrp', __('Super Simple Related Posts', 'super-simple-related-posts'), $widget_options
);
// Set widget defaults
$this->defaults = array(
'title' => '',
'hide_title' => '',
'post_types' => '',
'taxonomy' => 'category',
'orderby' => 'date',
'order' => 'DESC',
'number_of_posts' => -1,
'include_featured_image' => '',
'exclude_duplicates' => '',
'no_posts_action' => 'hide',
'no_posts_message' => __('No posts found', 'super-simple-related-posts'),
'post_heading_links' => '',
'hide_post_type_headings' => '',
'term_heading_links' => '',
'hide_term_headings' => '',
'before_HTML' => '',
'after_HTML' => '',
);
// Add shortcode
add_shortcode( 'ssrp', array( $this, 'ssrp_shortcode' ) );
}
/**
* Output the widget settings form
*
* @package Super_Simple_Related_Posts
* @since 1.0
*
* @param array $instance the current widget settings
*/
public function form( $instance ) {
// Map all undefined $instance properties to defaults
$instance = wp_parse_args( (array) $instance, $this->defaults );
// Output form HTML below
?>
<!-- Title -->
<p>
<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e('Title:', 'super-simple-related-posts'); ?></label>
<input type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo $instance['title']; ?>" class="widefat" />
</p>
<p>
<input type="checkbox" value="1" <?php checked( 1 == $instance['hide_title'] ); ?> id="<?php echo $this->get_field_id( 'hide_title' ); ?>" name="<?php echo $this->get_field_name( 'hide_title' ); ?>">
<label for="<?php echo $this->get_field_id( 'hide_title' ); ?>"><?php _e('Hide the widget title', 'super-simple-related-posts'); ?></label>
</p>
<!-- Post Types -->
<p>
<label for="<?php echo $this->get_field_id( 'post_types' ); ?>"><?php _e('Post types to include (by slug):', 'super-simple-related-posts'); ?></label>
<input type="text" id="<?php echo $this->get_field_id( 'post_types' ); ?>" name="<?php echo $this->get_field_name( 'post_types' ); ?>" value="<?php echo esc_attr( $instance['post_types'] ); ?>" class="widefat" placeholder="<?php _e('e.g. post, page, faq', 'super-simple-related-posts'); ?>" />
<small><?php _e('Comma separated, ordered list of post type slugs. Available post type slugs:', 'super-simple-related-posts'); ?> <code><?php echo implode( "</code>, <code>", get_post_types() ); ?></code></small>
</p>
<!-- Taxonomy -->
<p>
<label for="<?php echo $this->get_field_id( 'taxonomy' ); ?>"><?php _e('Show posts related by:', 'super-simple-related-posts'); ?></label>
<select id="<?php echo $this->get_field_id( 'taxonomy' ); ?>" name="<?php echo $this->get_field_name( 'taxonomy' ); ?>" class="widefat">
<?php
// Get all registered taxonomies
$taxonomies = get_taxonomies('', 'objects');
// Output an <option> for each taxonomy
foreach ( $taxonomies as $taxonomy ) {
// Get taxonomy name and slug
$tax_name = $taxonomy->labels->singular_name;
$tax_slug = $taxonomy->name;
/**
* Output taxonomy:
* 1. if the $included_taxonomies[] is empty (which will display all taxonomies)
* 2. this taxonomy is set to be included in $this->included_taxonomies[]
*/
if ( empty($this->included_taxonomies) || in_array( $tax_slug, $this->included_taxonomies ) )
echo '<option value="' . $tax_slug . '" ' . selected( $instance['taxonomy'], $tax_slug ) . '>' . $tax_name . '</option>' . "\n";
}
?>
</select>
</p>
<!-- Orderby -->
<p>
<label for="<?php echo $this->get_field_id( 'orderby' ); ?>"><?php _e('Order posts by:', 'super-simple-related-posts'); ?></label>
<select id="<?php echo $this->get_field_id( 'orderby' ); ?>" name="<?php echo $this->get_field_name( 'orderby' ); ?>" class="widefat">
<?php
// Array of orderby values
$orderby_values = array(
'title' => __('Title', 'super-simple-related-posts'),
'name' => __('Post Slug', 'super-simple-related-posts'),
'date' => __('Date Created', 'super-simple-related-posts'),
'modified' => __('Date Modified', 'super-simple-related-posts'),
'menu_order' => __('Menu Order', 'super-simple-related-posts'),
'author' => __('Author', 'super-simple-related-posts'),
'ID' => __('Post ID', 'super-simple-related-posts'),
'parent' => __('Parent ID', 'super-simple-related-posts'),
'rand' => __('Random', 'super-simple-related-posts'),
'comment_count' => __('Comment Count', 'super-simple-related-posts'),
);
// Output <option> for each $orderby_value
foreach ( $orderby_values as $orderby_value => $orderby_name ) {
echo '<option value="' . $orderby_value . '" ' . selected( $instance['orderby'], $orderby_value ) . '>' . $orderby_name . '</option>' . "\n";
}
?>
</select>
</p>
<!-- Order -->
<p>
<label for="<?php echo $this->get_field_id( 'order' ); ?>"><?php _e('Order:', 'super-simple-related-posts'); ?></label>
<select id="<?php echo $this->get_field_id( 'order' ); ?>" name="<?php echo $this->get_field_name( 'order' ); ?>" class="widefat">
<?php
// Array of order values
$order_values = array(
'ASC' => __('Ascending', 'super-simple-related-posts'),
'DESC' => __('Descending', 'super-simple-related-posts'),
);
// Output <option> for each $order_value
foreach ( $order_values as $order_value => $order_name ) {
echo '<option value="' . $order_value . '" ' . selected( $instance['order'], $order_value ) . '>' . $order_name . '</option>' . "\n";
}
?>
</select>
</p>
<!-- Number of Posts -->
<p>
<label for="<?php echo $this->get_field_id( 'number_of_posts' ); ?>"><?php _e('Number of posts to show:', 'super-simple-related-posts'); ?></label>
<select id="<?php echo $this->get_field_id( 'number_of_posts' ); ?>" name="<?php echo $this->get_field_name( 'number_of_posts' ); ?>" class="widefat">
<?php
// First, output the <option> for unlimited
echo '<option value="-1" ' . selected( $instance['order'], $order_value ) . '>' . __('Unlimited', 'super-simple-related-posts') . '</option>' . "\n";
// Output <option>'s for the numbers 1-100
for ( $i = 1; $i <= 100; $i++ ) {
echo '<option value="' . $i . '" ' . selected( $instance['number_of_posts'], $i ) . '>' . $i . '</option>' . "\n";
}
?>
</select>
</p>
<!-- Featured Image -->
<p>
<input type="checkbox" value="1" <?php checked( 1 == $instance['include_featured_image'] ); ?> id="<?php echo $this->get_field_id( 'include_featured_image' ); ?>" name="<?php echo $this->get_field_name( 'include_featured_image' ); ?>">
<label for="<?php echo $this->get_field_id( 'include_featured_image' ); ?>"><?php _e('Include featured image', 'super-simple-related-posts'); ?></label>
</p>
<!-- Duplicates -->
<p>
<input type="checkbox" value="1" <?php checked( 1 == $instance['exclude_duplicates'] ); ?> id="<?php echo $this->get_field_id( 'exclude_duplicates' ); ?>" name="<?php echo $this->get_field_name( 'exclude_duplicates' ); ?>">
<label for="<?php echo $this->get_field_id( 'exclude_duplicates' ); ?>"><?php _e('Exclude duplicates', 'super-simple-related-posts'); ?></label>
</p>
<!-- No Posts Found -->
<p>
<?php _e('If there are no related posts:', 'super-simple-related-posts') ?><br />
<input type="radio" value="hide" <?php checked( 'hide' == $instance['no_posts_action'] ); ?> id="<?php echo $this->get_field_id( 'no_posts_action' ); ?>-hide" name="<?php echo $this->get_field_name( 'no_posts_action' ); ?>">
<label for="<?php echo $this->get_field_id( 'no_posts_action' ); ?>-hide"><?php _e('Hide the content/widget', 'super-simple-related-posts'); ?></label><br />
<input type="radio" value="message" <?php checked( 'message' == $instance['no_posts_action'] ); ?> id="<?php echo $this->get_field_id( 'no_posts_action' ); ?>-message" name="<?php echo $this->get_field_name( 'no_posts_action' ); ?>">
<label for="<?php echo $this->get_field_id( 'no_posts_action' ); ?>-message"><?php _e('Show the following message:', 'super-simple-related-posts'); ?></label>
<input type="text" id="<?php echo $this->get_field_id( 'no_posts_message' ); ?>" name="<?php echo $this->get_field_name( 'no_posts_message' ); ?>" value="<?php echo esc_attr( $instance['no_posts_message'] ); ?>" class="widefat" />
</p>
<!-- Post Type Headings -->
<p>
<?php _e('Headings (post types):', 'super-simple-related-posts') ?><br />
<input type="checkbox" value="1" <?php checked( 1 == $instance['post_heading_links'] ); ?> id="<?php echo $this->get_field_id( 'post_heading_links' ); ?>" name="<?php echo $this->get_field_name( 'post_heading_links' ); ?>">
<label for="<?php echo $this->get_field_id( 'post_heading_links' ); ?>"><?php _e('Link post type headings', 'super-simple-related-posts'); ?></label><br />
<input type="checkbox" value="1" <?php checked( 1 == $instance['hide_post_type_headings'] ); ?> id="<?php echo $this->get_field_id( 'hide_post_type_headings' ); ?>" name="<?php echo $this->get_field_name( 'hide_post_type_headings' ); ?>">
<label for="<?php echo $this->get_field_id( 'hide_post_type_headings' ); ?>"><?php _e('Hide post type headings', 'super-simple-related-posts'); ?></label><br />
</p>
<!-- Taxonomy Term Headings -->
<p>
<?php _e('Subheadings (taxonomy terms):', 'super-simple-related-posts') ?><br />
<input type="checkbox" value="1" <?php checked( 1 == $instance['term_heading_links'] ); ?> id="<?php echo $this->get_field_id( 'term_heading_links' ); ?>" name="<?php echo $this->get_field_name( 'term_heading_links' ); ?>">
<label for="<?php echo $this->get_field_id( 'term_heading_links' ); ?>"><?php _e('Link taxonomy term subheadings', 'super-simple-related-posts'); ?></label><br />
<input type="checkbox" value="1" <?php checked( 1 == $instance['hide_term_headings'] ); ?> id="<?php echo $this->get_field_id( 'hide_term_headings' ); ?>" name="<?php echo $this->get_field_name( 'hide_term_headings' ); ?>">
<label for="<?php echo $this->get_field_id( 'hide_term_headings' ); ?>"><?php _e('Hide taxonomy term subheadings', 'super-simple-related-posts'); ?></label>
</p>
<!-- Before Widget -->
<p>
<label for="<?php echo $this->get_field_id( 'before_HTML' ); ?>"><?php _e('HTML before widget:', 'super-simple-related-posts'); ?></label>
<textarea id="<?php echo $this->get_field_id( 'before_HTML' ); ?>" name="<?php echo $this->get_field_name( 'before_HTML' ); ?>" class="widefat" rows="6" placeholder="<?php esc_html_e('e.g. <p>Intro text goes here…</p>', 'super-simple-related-posts'); ?>"><?php echo esc_textarea( $instance['before_HTML'] ); ?></textarea>
</p>
<!-- After Widget -->
<p>
<label for="<?php echo $this->get_field_id( 'after_HTML' ); ?>"><?php _e('HTML after widget:', 'super-simple-related-posts'); ?></label>
<textarea id="<?php echo $this->get_field_id( 'after_HTML' ); ?>" name="<?php echo $this->get_field_name( 'after_HTML' ); ?>" class="widefat" rows="6" placeholder="<?php esc_html_e('e.g. <a href="#">Learn more »</a>', 'super-simple-related-posts'); ?>"><?php echo esc_textarea( $instance['after_HTML'] ); ?></textarea>
</p>
<?php
}
/**
* Sanitize and update widget form values
*
* @package Super_Simple_Related_Posts
* @since 1.0
*
* @param array $new_instance the old widget settings
* @param array $old_instance the new widget settings
*/
public function update( $new_instance, $old_instance ) {
// Sanitize title
$new_instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
// Sanitize title
$new_instance['no_posts_message'] = ( ! empty( $new_instance['no_posts_message'] ) ) ? sanitize_title( $new_instance['no_posts_message'] ) : '';
// Sanitize before_HTML & after_HTML
if ( current_user_can('unfiltered_html') ) {
$new_instance['before_HTML'] = $new_instance['before_HTML'];
$new_instance['after_HTML'] = $new_instance['after_HTML'];
} else {
$new_instance['before_HTML'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['before_HTML']) ) ); // wp_filter_post_kses() expects slashed
$new_instance['after_HTML'] = stripslashes( wp_filter_post_kses( addslashes($new_instance['after_HTML']) ) ); // wp_filter_post_kses() expects slashed
}
return $new_instance;
}
/**
* Output the widget contents
*
* @package Super_Simple_Related_Posts
* @since 1.0
*
* @param array $args widget display arguments including before_title, after_title, before_widget, and after_widget
* @param array $instance the widget settings
*/
public function widget( $args, $instance ) {
// Exits if we're not looking at a single post/page
if ( !is_singular() || empty( $instance['post_types'] ) )
return;
// Get widget $args as variables
extract( $args );
// Initialize main output string
$output = '';
// Get the widget title, taxonomy, and post types to be included
$title = ( $instance['title'] ? $instance['title'] : __('Related Posts', 'super-simple-related-posts') );
$taxonomy = $instance['taxonomy'];
$post_types = explode( ',', str_replace( ' ', '', $instance['post_types'] ) );
// Set up array to track included posts to exclude them from being included twice.
$included_posts = array( get_the_ID() );
// Get the taxonomy terms of the current post/page for the specified taxonomy
$post_terms = wp_get_post_terms( get_the_ID(), $taxonomy );
// Loop through each post type and generate output
foreach ( $post_types as $post_type ) {
// Initialize term output
$term_output = '';
// Loop through the taxonomy terms of the current post
foreach ( $post_terms as $term_object ) {
// Get the ID of the term object
$term_id = $term_object->term_id;
// Set the arguments for the following get_posts() call
$args = array(
'posts_per_page' => $instance['number_of_posts'],
'orderby' => $instance['orderby'],
'order' => $instance['order'],
'post_type' => $post_type,
'exclude' => $included_posts,
'tax_query' => array(
array(
'taxonomy' => $taxonomy,
'field' => 'id',
'terms' => $term_id,
)
)
);
// Get all posts of the current post type that have the current taxonomy term
$posts = get_posts( $args );
// Initialize post output
$post_link = '';
$post_output = '';
// Output posts for this post type and taxonomy
foreach ( $posts as $post ) {
if ( ! empty( $instance['exclude_duplicates'] ) ) {
$included_posts[] = $post->ID;
}
// Apply the_title and ssrp_post_title filters (within <a> tag)
$post_link = apply_filters( 'the_title', $post->post_title, $post->ID);
$post_link = apply_filters( 'ssrp_post_title', $post_link, $post->ID);
// Add actual link
$post_link = '<a href="' . get_permalink($post->ID) . '">' . $post_link . '</a>';
// Add featured image if needed
if ( isset( $instance['include_featured_image'] ) && $instance['include_featured_image'] )
$post_link = '<a href="' . get_permalink($post->ID) . '">' . get_the_post_thumbnail( $post->ID ) . '</a>' . $post_link;
// Apply ssrp_post_link (outside of <a> tag)
$post_output .= '<li>' . apply_filters( 'ssrp_post_link', $post_link, $post->ID ) . '</li>';
}
// Only output the term heading if some related posts exist within it
if ( !empty( $post_output ) || 'message' == $instance['no_posts_action'] ) {
// Only output the term heading if the widget box to hide it is unchecked
if ( !isset( $instance['hide_term_headings'] ) || 1 != $instance['hide_term_headings'] ) {
$term_output .= '<h5>';
// Output post type headings as links if specified
if ( isset( $instance['term_heading_links'] ) && 1 == $instance['term_heading_links'] )
$term_output .= '<a href="' . get_term_link( get_term_by('id', $term_id, $taxonomy) ) . '">';
// Output taxonomy term heading text
$term_output .= apply_filters( 'ssrp_taxonomy_term_heading', $term_object->name, $term_object );
// Close taxonomy term heading link if specified
if ( isset( $instance['term_heading_links'] ) && 1 == $instance['term_heading_links'] )
$term_output .= '</a>';
$term_output .= '</h5>';
}
// If there are no related posts
if ( empty( $post_output ) )
$post_output = '<div class="no-posts-message">' . $instance['no_posts_message'] . '</div>';
// Output the posts list and apply ssrp_posts_list filter
$term_output .= '<ul>' . apply_filters( 'ssrp_posts_list', $post_output, get_post_type_object($post_type), $term_object ) . '</ul>';
}
} /* End terms loop */
// Only output the post type heading if some related posts exist within it
if ( !empty($term_output) ) {
// Open the container div
$output .= '<div class="post-type-' . $post_type . '">';
// Only output the post type heading if the widget box to hide it is unchecked
if ( !isset( $instance['hide_post_type_headings'] ) || 1 != $instance['hide_post_type_headings'] ) {
$output .= '<h4>';
// Output post type headings as links if specified, requires 2 different treatments for regular and custom posts
if ( isset( $instance['post_heading_links'] ) && 1 == $instance['post_heading_links'] ) {
// 1. Regular posts - get_post_type_archive_link() doesn't work for regular posts, so get the URL manually
if ( 'post' == $post_type ) {
// If homepage is NOT set to be posts/blog page
if ( 'page' == get_option('show_on_front') )
$archive_link = get_permalink( get_option('page_for_posts' ) );
// If homepage IS set to be posts/blog page
else
$archive_link = get_bloginfo('url');
}
// 2. Custom post types - get_post_type_archive_link() works just fine
else
$archive_link = get_post_type_archive_link( $post_type );
// Output actual link
$output .= '<a href="' . $archive_link . '">';
}
// Output post type heading text and apply ssrp_post_type_heading filter
$output .= apply_filters( 'ssrp_post_type_heading', get_post_type_object($post_type)->labels->name, get_post_type_object($post_type) );
// Close post type heading link if need be
if ( isset( $instance['post_heading_links'] ) && 1 == $instance['post_heading_links'] )
$output .= '</a>';
$output .= '</h4>';
}
// Close the post type container div
$output .= $term_output . '</div>';
}
} /* End post type loop */
// If there are related posts or widget is set to display $no_posts_message
if ( !empty( $output ) || 'message' == $instance['no_posts_action'] ) {
// If there are no related posts, output the $no_posts_message
if ( empty( $output ) )
$output = '<div class="no-posts-message">' . $instance['no_posts_message'] . '</div>';
// Apply widget_title and widget_text filters
$widget_title = $before_title . apply_filters( 'widget_title', $title, $instance, $this->id_base ) . $after_title;
$widget_text = apply_filters( 'widget_text', $output, $instance, $this->id_base );
// Get before_HTML and after_HTML
$before_HTML = '<div class="ssrp-before">' . $instance['before_HTML'] . '</div>';
$after_HTML = '<div class="ssrp-after">' . $instance['after_HTML'] . '</div>';
// Don't show widget title if "hide title" setting is checked
if ( !empty( $instance['hide_title'] ) )
$widget_title = '';
echo $before_widget . $widget_title .'<div class="textwidget">' . $before_HTML . $widget_text . $after_HTML . '</div>' . $after_widget;
}
}
/**
* Output content for shortcode
*
* @package Super_Simple_Related_Posts
* @since 1.2
*
* @param array $atts shortcode atts to be used in the $instance parameter
*/
public function ssrp_shortcode( $atts ) {
$instance = wp_parse_args( $atts, $this->defaults );
the_widget( 'SSRP_Widget', $instance );
}
}