Display Posts Shortcode - Version 2.7.0

Version Description

Download this release

Release Info

Developer billerickson
Plugin Icon 128x128 Display Posts Shortcode
Version 2.7.0
Comparing to
See all releases

Code changes from version 2.6.2 to 2.7.0

Files changed (2) hide show
  1. display-posts-shortcode.php +115 -122
  2. readme.txt +8 -1
display-posts-shortcode.php CHANGED
@@ -3,7 +3,7 @@
3
  * Plugin Name: Display Posts Shortcode
4
  * Plugin URI: http://www.billerickson.net/shortcode-to-display-posts/
5
  * Description: Display a listing of posts using the [display-posts] shortcode
6
- * Version: 2.6.2
7
  * Author: Bill Erickson
8
  * Author URI: http://www.billerickson.net
9
  *
@@ -15,7 +15,7 @@
15
  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
  *
17
  * @package Display Posts
18
- * @version 2.5
19
  * @author Bill Erickson <bill@billerickson.net>
20
  * @copyright Copyright (c) 2011, Bill Erickson
21
  * @link http://www.billerickson.net/shortcode-to-display-posts/
@@ -25,22 +25,7 @@
25
 
26
  /**
27
  * To Customize, use the following filters:
28
- *
29
- * `shortcode_atts_display-posts`
30
- * For customizing the default shortode arguments
31
- *
32
- * `display_posts_shortcode_args`
33
- * For customizing the $args passed to WP_Query
34
- *
35
- * `display_posts_shortcode_output`
36
- * For customizing the output of individual posts.
37
- * Example: https://gist.github.com/1175575#file_display_posts_shortcode_output.php
38
- *
39
- * `display_posts_shortcode_wrapper_open`
40
- * display_posts_shortcode_wrapper_close`
41
- * For customizing the outer markup of the whole listing. By default it is a <ul> but
42
- * can be changed to <ol> or <div> using the 'wrapper' attribute, or by using this filter.
43
- * Example: https://gist.github.com/1270278
44
  */
45
 
46
  // Create the shortcode
@@ -52,100 +37,102 @@ function be_display_posts_shortcode( $atts ) {
52
 
53
  // Pull in shortcode attributes and set defaults
54
  $atts = shortcode_atts( array(
55
- 'title' => '',
56
- 'author' => '',
57
- 'category' => '',
58
- 'category_display' => '',
59
- 'category_label' => 'Posted in: ',
60
- 'content_class' => 'content',
61
- 'date_format' => '(n/j/Y)',
62
- 'date' => '',
63
- 'date_column' => 'post_date',
64
- 'date_compare' => '=',
65
- 'date_query_before' => '',
66
- 'date_query_after' => '',
67
- 'date_query_column' => '',
68
- 'date_query_compare' => '',
69
- 'display_posts_off' => false,
70
- 'excerpt_length' => false,
71
- 'excerpt_more' => false,
72
- 'excerpt_more_link' => false,
73
- 'exclude_current' => false,
74
- 'id' => false,
75
- 'ignore_sticky_posts' => false,
76
- 'image_size' => false,
77
- 'include_title' => true,
78
- 'include_author' => false,
79
- 'include_content' => false,
80
- 'include_date' => false,
81
- 'include_excerpt' => false,
82
- 'meta_key' => '',
83
- 'meta_value' => '',
84
- 'no_posts_message' => '',
85
- 'offset' => 0,
86
- 'order' => 'DESC',
87
- 'orderby' => 'date',
88
- 'post_parent' => false,
89
- 'post_status' => 'publish',
90
- 'post_type' => 'post',
91
- 'posts_per_page' => '10',
92
- 'tag' => '',
93
- 'tax_operator' => 'IN',
94
- 'tax_term' => false,
95
- 'taxonomy' => false,
96
- 'time' => '',
97
- 'wrapper' => 'ul',
98
- 'wrapper_class' => 'display-posts-listing',
99
- 'wrapper_id' => false,
 
100
  ), $atts, 'display-posts' );
101
 
102
  // End early if shortcode should be turned off
103
  if( $atts['display_posts_off'] )
104
  return;
105
 
106
- $shortcode_title = sanitize_text_field( $atts['title'] );
107
- $author = sanitize_text_field( $atts['author'] );
108
- $category = sanitize_text_field( $atts['category'] );
109
- $category_display = 'true' == $atts['category_display'] ? 'category' : sanitize_text_field( $atts['category_display'] );
110
- $category_label = sanitize_text_field( $atts['category_label'] );
111
- $content_class = array_map( 'sanitize_html_class', ( explode( ' ', $atts['content_class'] ) ) );
112
- $date_format = sanitize_text_field( $atts['date_format'] );
113
- $date = sanitize_text_field( $atts['date'] );
114
- $date_column = sanitize_text_field( $atts['date_column'] );
115
- $date_compare = sanitize_text_field( $atts['date_compare'] );
116
- $date_query_before = sanitize_text_field( $atts['date_query_before'] );
117
- $date_query_after = sanitize_text_field( $atts['date_query_after'] );
118
- $date_query_column = sanitize_text_field( $atts['date_query_column'] );
119
- $date_query_compare = sanitize_text_field( $atts['date_query_compare'] );
120
- $excerpt_length = intval( $atts['excerpt_length'] );
121
- $excerpt_more = sanitize_text_field( $atts['excerpt_more'] );
122
- $excerpt_more_link = filter_var( $atts['excerpt_more_link'], FILTER_VALIDATE_BOOLEAN );
123
- $exclude_current = filter_var( $atts['exclude_current'], FILTER_VALIDATE_BOOLEAN );
124
- $id = $atts['id']; // Sanitized later as an array of integers
125
- $ignore_sticky_posts = filter_var( $atts['ignore_sticky_posts'], FILTER_VALIDATE_BOOLEAN );
126
- $image_size = sanitize_key( $atts['image_size'] );
127
- $include_title = filter_var( $atts['include_title'], FILTER_VALIDATE_BOOLEAN );
128
- $include_author = filter_var( $atts['include_author'], FILTER_VALIDATE_BOOLEAN );
129
- $include_content = filter_var( $atts['include_content'], FILTER_VALIDATE_BOOLEAN );
130
- $include_date = filter_var( $atts['include_date'], FILTER_VALIDATE_BOOLEAN );
131
- $include_excerpt = filter_var( $atts['include_excerpt'], FILTER_VALIDATE_BOOLEAN );
132
- $meta_key = sanitize_text_field( $atts['meta_key'] );
133
- $meta_value = sanitize_text_field( $atts['meta_value'] );
134
- $no_posts_message = sanitize_text_field( $atts['no_posts_message'] );
135
- $offset = intval( $atts['offset'] );
136
- $order = sanitize_key( $atts['order'] );
137
- $orderby = sanitize_key( $atts['orderby'] );
138
- $post_parent = $atts['post_parent']; // Validated later, after check for 'current'
139
- $post_status = $atts['post_status']; // Validated later as one of a few values
140
- $post_type = sanitize_text_field( $atts['post_type'] );
141
- $posts_per_page = intval( $atts['posts_per_page'] );
142
- $tag = sanitize_text_field( $atts['tag'] );
143
- $tax_operator = $atts['tax_operator']; // Validated later as one of a few values
144
- $tax_term = sanitize_text_field( $atts['tax_term'] );
145
- $taxonomy = sanitize_key( $atts['taxonomy'] );
146
- $time = sanitize_text_field( $atts['time'] );
147
- $wrapper = sanitize_text_field( $atts['wrapper'] );
148
- $wrapper_class = array_map( 'sanitize_html_class', ( explode( ' ', $atts['wrapper_class'] ) ) );
 
149
 
150
  if( !empty( $wrapper_class ) )
151
  $wrapper_class = ' class="' . implode( ' ', $wrapper_class ) . '"';
@@ -308,14 +295,15 @@ function be_display_posts_shortcode( $atts ) {
308
  // Validate operator
309
  if( !in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) )
310
  $tax_operator = 'IN';
311
-
312
  $tax_args = array(
313
  'tax_query' => array(
314
  array(
315
- 'taxonomy' => $taxonomy,
316
- 'field' => 'slug',
317
- 'terms' => $tax_term,
318
- 'operator' => $tax_operator
 
319
  )
320
  )
321
  );
@@ -334,12 +322,14 @@ function be_display_posts_shortcode( $atts ) {
334
  $terms = explode( ', ', sanitize_text_field( $original_atts['tax_' . $count . '_term'] ) );
335
  $tax_operator = isset( $original_atts['tax_' . $count . '_operator'] ) ? $original_atts['tax_' . $count . '_operator'] : 'IN';
336
  $tax_operator = in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) ? $tax_operator : 'IN';
 
337
 
338
  $tax_args['tax_query'][] = array(
339
- 'taxonomy' => $taxonomy,
340
- 'field' => 'slug',
341
- 'terms' => $terms,
342
- 'operator' => $tax_operator
 
343
  );
344
 
345
  $count++;
@@ -418,7 +408,7 @@ function be_display_posts_shortcode( $atts ) {
418
  *
419
  * @param string $author_output HTML markup to display author information.
420
  */
421
- $author = apply_filters( 'display_posts_shortcode_author', ' <span class="author">by ' . get_the_author() . '</span>' );
422
 
423
  if ( $include_excerpt ) {
424
 
@@ -428,8 +418,15 @@ function be_display_posts_shortcode( $atts ) {
428
  $length = $excerpt_length ? $excerpt_length : apply_filters( 'excerpt_length', 55 );
429
  $more = $excerpt_more ? $excerpt_more : apply_filters( 'excerpt_more', '' );
430
  $more = $excerpt_more_link ? ' <a href="' . get_permalink() . '">' . $more . '</a>' : ' ' . $more;
 
 
 
 
 
 
 
 
431
 
432
- $excerpt = has_excerpt() ? $post->post_excerpt . $more : wp_trim_words( $post->post_content, $length, $more );
433
 
434
  // Use default, can customize with WP filters
435
  } else {
@@ -486,10 +483,6 @@ function be_display_posts_shortcode( $atts ) {
486
  $class = array_map( 'sanitize_html_class', apply_filters( 'display_posts_shortcode_post_class', $class, $post, $listing, $original_atts ) );
487
  $output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $author . $category_display_text . $excerpt . $content . '</' . $inner_wrapper . '>';
488
 
489
- // If post is set to private, only show to logged in users
490
- if( 'private' == get_post_status( get_the_ID() ) && !current_user_can( 'read_private_posts' ) )
491
- $output = '';
492
-
493
  /**
494
  * Filter the HTML markup for output via the shortcode.
495
  *
@@ -670,4 +663,4 @@ function be_display_posts_off( $out, $pairs, $atts ) {
670
  */
671
  $out['display_posts_off'] = apply_filters( 'display_posts_shortcode_inception_override', true );
672
  return $out;
673
- }
3
  * Plugin Name: Display Posts Shortcode
4
  * Plugin URI: http://www.billerickson.net/shortcode-to-display-posts/
5
  * Description: Display a listing of posts using the [display-posts] shortcode
6
+ * Version: 2.7.0
7
  * Author: Bill Erickson
8
  * Author URI: http://www.billerickson.net
9
  *
15
  * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
  *
17
  * @package Display Posts
18
+ * @version 2.7.0
19
  * @author Bill Erickson <bill@billerickson.net>
20
  * @copyright Copyright (c) 2011, Bill Erickson
21
  * @link http://www.billerickson.net/shortcode-to-display-posts/
25
 
26
  /**
27
  * To Customize, use the following filters:
28
+ * @link https://github.com/billerickson/display-posts-shortcode/wiki#customization-with-filters
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  */
30
 
31
  // Create the shortcode
37
 
38
  // Pull in shortcode attributes and set defaults
39
  $atts = shortcode_atts( array(
40
+ 'author' => '',
41
+ 'category' => '',
42
+ 'category_display' => '',
43
+ 'category_label' => 'Posted in: ',
44
+ 'content_class' => 'content',
45
+ 'date_format' => '(n/j/Y)',
46
+ 'date' => '',
47
+ 'date_column' => 'post_date',
48
+ 'date_compare' => '=',
49
+ 'date_query_before' => '',
50
+ 'date_query_after' => '',
51
+ 'date_query_column' => '',
52
+ 'date_query_compare' => '',
53
+ 'display_posts_off' => false,
54
+ 'excerpt_length' => false,
55
+ 'excerpt_more' => false,
56
+ 'excerpt_more_link' => false,
57
+ 'exclude_current' => false,
58
+ 'id' => false,
59
+ 'ignore_sticky_posts' => false,
60
+ 'image_size' => false,
61
+ 'include_author' => false,
62
+ 'include_content' => false,
63
+ 'include_date' => false,
64
+ 'include_excerpt' => false,
65
+ 'include_title' => true,
66
+ 'meta_key' => '',
67
+ 'meta_value' => '',
68
+ 'no_posts_message' => '',
69
+ 'offset' => 0,
70
+ 'order' => 'DESC',
71
+ 'orderby' => 'date',
72
+ 'post_parent' => false,
73
+ 'post_status' => 'publish',
74
+ 'post_type' => 'post',
75
+ 'posts_per_page' => '10',
76
+ 'tag' => '',
77
+ 'tax_operator' => 'IN',
78
+ 'tax_include_children' => true,
79
+ 'tax_term' => false,
80
+ 'taxonomy' => false,
81
+ 'time' => '',
82
+ 'title' => '',
83
+ 'wrapper' => 'ul',
84
+ 'wrapper_class' => 'display-posts-listing',
85
+ 'wrapper_id' => false,
86
  ), $atts, 'display-posts' );
87
 
88
  // End early if shortcode should be turned off
89
  if( $atts['display_posts_off'] )
90
  return;
91
 
92
+ $author = sanitize_text_field( $atts['author'] );
93
+ $category = sanitize_text_field( $atts['category'] );
94
+ $category_display = 'true' == $atts['category_display'] ? 'category' : sanitize_text_field( $atts['category_display'] );
95
+ $category_label = sanitize_text_field( $atts['category_label'] );
96
+ $content_class = array_map( 'sanitize_html_class', ( explode( ' ', $atts['content_class'] ) ) );
97
+ $date_format = sanitize_text_field( $atts['date_format'] );
98
+ $date = sanitize_text_field( $atts['date'] );
99
+ $date_column = sanitize_text_field( $atts['date_column'] );
100
+ $date_compare = sanitize_text_field( $atts['date_compare'] );
101
+ $date_query_before = sanitize_text_field( $atts['date_query_before'] );
102
+ $date_query_after = sanitize_text_field( $atts['date_query_after'] );
103
+ $date_query_column = sanitize_text_field( $atts['date_query_column'] );
104
+ $date_query_compare = sanitize_text_field( $atts['date_query_compare'] );
105
+ $excerpt_length = intval( $atts['excerpt_length'] );
106
+ $excerpt_more = sanitize_text_field( $atts['excerpt_more'] );
107
+ $excerpt_more_link = filter_var( $atts['excerpt_more_link'], FILTER_VALIDATE_BOOLEAN );
108
+ $exclude_current = filter_var( $atts['exclude_current'], FILTER_VALIDATE_BOOLEAN );
109
+ $id = $atts['id']; // Sanitized later as an array of integers
110
+ $ignore_sticky_posts = filter_var( $atts['ignore_sticky_posts'], FILTER_VALIDATE_BOOLEAN );
111
+ $image_size = sanitize_key( $atts['image_size'] );
112
+ $include_title = filter_var( $atts['include_title'], FILTER_VALIDATE_BOOLEAN );
113
+ $include_author = filter_var( $atts['include_author'], FILTER_VALIDATE_BOOLEAN );
114
+ $include_content = filter_var( $atts['include_content'], FILTER_VALIDATE_BOOLEAN );
115
+ $include_date = filter_var( $atts['include_date'], FILTER_VALIDATE_BOOLEAN );
116
+ $include_excerpt = filter_var( $atts['include_excerpt'], FILTER_VALIDATE_BOOLEAN );
117
+ $meta_key = sanitize_text_field( $atts['meta_key'] );
118
+ $meta_value = sanitize_text_field( $atts['meta_value'] );
119
+ $no_posts_message = sanitize_text_field( $atts['no_posts_message'] );
120
+ $offset = intval( $atts['offset'] );
121
+ $order = sanitize_key( $atts['order'] );
122
+ $orderby = sanitize_key( $atts['orderby'] );
123
+ $post_parent = $atts['post_parent']; // Validated later, after check for 'current'
124
+ $post_status = $atts['post_status']; // Validated later as one of a few values
125
+ $post_type = sanitize_text_field( $atts['post_type'] );
126
+ $posts_per_page = intval( $atts['posts_per_page'] );
127
+ $tag = sanitize_text_field( $atts['tag'] );
128
+ $tax_operator = $atts['tax_operator']; // Validated later as one of a few values
129
+ $tax_include_children = filter_var( $atts['tax_include_children'], FILTER_VALIDATE_BOOLEAN );
130
+ $tax_term = sanitize_text_field( $atts['tax_term'] );
131
+ $taxonomy = sanitize_key( $atts['taxonomy'] );
132
+ $time = sanitize_text_field( $atts['time'] );
133
+ $shortcode_title = sanitize_text_field( $atts['title'] );
134
+ $wrapper = sanitize_text_field( $atts['wrapper'] );
135
+ $wrapper_class = array_map( 'sanitize_html_class', ( explode( ' ', $atts['wrapper_class'] ) ) );
136
 
137
  if( !empty( $wrapper_class ) )
138
  $wrapper_class = ' class="' . implode( ' ', $wrapper_class ) . '"';
295
  // Validate operator
296
  if( !in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) )
297
  $tax_operator = 'IN';
298
+
299
  $tax_args = array(
300
  'tax_query' => array(
301
  array(
302
+ 'taxonomy' => $taxonomy,
303
+ 'field' => 'slug',
304
+ 'terms' => $tax_term,
305
+ 'operator' => $tax_operator,
306
+ 'include_children' => $tax_include_children,
307
  )
308
  )
309
  );
322
  $terms = explode( ', ', sanitize_text_field( $original_atts['tax_' . $count . '_term'] ) );
323
  $tax_operator = isset( $original_atts['tax_' . $count . '_operator'] ) ? $original_atts['tax_' . $count . '_operator'] : 'IN';
324
  $tax_operator = in_array( $tax_operator, array( 'IN', 'NOT IN', 'AND' ) ) ? $tax_operator : 'IN';
325
+ $tax_include_children = isset( $original_atts['tax_' . $count . '_include_children'] ) ? filter_var( $atts['tax_' . $count . '_include_children'], FILTER_VALIDATE_BOOLEAN ) : true;
326
 
327
  $tax_args['tax_query'][] = array(
328
+ 'taxonomy' => $taxonomy,
329
+ 'field' => 'slug',
330
+ 'terms' => $terms,
331
+ 'operator' => $tax_operator,
332
+ 'include_children' => $tax_include_children,
333
  );
334
 
335
  $count++;
408
  *
409
  * @param string $author_output HTML markup to display author information.
410
  */
411
+ $author = apply_filters( 'display_posts_shortcode_author', ' <span class="author">by ' . get_the_author() . '</span>', $original_atts );
412
 
413
  if ( $include_excerpt ) {
414
 
418
  $length = $excerpt_length ? $excerpt_length : apply_filters( 'excerpt_length', 55 );
419
  $more = $excerpt_more ? $excerpt_more : apply_filters( 'excerpt_more', '' );
420
  $more = $excerpt_more_link ? ' <a href="' . get_permalink() . '">' . $more . '</a>' : ' ' . $more;
421
+
422
+ if( has_excerpt() && apply_filters( 'display_posts_shortcode_full_manual_excerpt', false ) ) {
423
+ $excerpt = $post->post_excerpt . $more;
424
+ } elseif( has_excerpt() ) {
425
+ $excerpt = wp_trim_words( strip_shortcodes( $post->post_excerpt ), $length, $more );
426
+ } else {
427
+ $excerpt = wp_trim_words( strip_shortcodes( $post->post_content ), $length, $more );
428
+ }
429
 
 
430
 
431
  // Use default, can customize with WP filters
432
  } else {
483
  $class = array_map( 'sanitize_html_class', apply_filters( 'display_posts_shortcode_post_class', $class, $post, $listing, $original_atts ) );
484
  $output = '<' . $inner_wrapper . ' class="' . implode( ' ', $class ) . '">' . $image . $title . $date . $author . $category_display_text . $excerpt . $content . '</' . $inner_wrapper . '>';
485
 
 
 
 
 
486
  /**
487
  * Filter the HTML markup for output via the shortcode.
488
  *
663
  */
664
  $out['display_posts_off'] = apply_filters( 'display_posts_shortcode_inception_override', true );
665
  return $out;
666
+ }
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: shortcode, pages, posts, page, query, display, list
5
  Requires at least: 3.0
6
  Tested up to: 4.5.2
7
- Stable tag: 2.6.2
8
 
9
  Display a listing of posts using the [display-posts] shortcode
10
 
@@ -30,6 +30,13 @@ Add the shortcode in a post or page, and use the arguments to query based on tag
30
 
31
  == Changelog ==
32
 
 
 
 
 
 
 
 
33
  **Version 2.6.2**
34
  * More improvements to excerpts, see #110
35
  * Added content_class parameter
4
  Tags: shortcode, pages, posts, page, query, display, list
5
  Requires at least: 3.0
6
  Tested up to: 4.5.2
7
+ Stable tag: 2.7.0
8
 
9
  Display a listing of posts using the [display-posts] shortcode
10
 
30
 
31
  == Changelog ==
32
 
33
+ **Version 2.7.0**
34
+ * Added support for [Co-Authors Plus Addon](https://github.com/billerickson/dps-coauthor-addon).
35
+ * Added parameter to exclude children terms in tax queries, [more information](https://github.com/billerickson/display-posts-shortcode/issues/120)
36
+ * Added a filter to display the full version of manual excerpt, regardless of excerpt_length. [more information](https://github.com/billerickson/display-posts-shortcode/issues/123)
37
+ * Removed shortcodes from custom excerpts, [more information](https://github.com/billerickson/display-posts-shortcode/issues/113)
38
+ * Fixed private post visibility, [more information](https://github.com/billerickson/display-posts-shortcode/issues/115)
39
+
40
  **Version 2.6.2**
41
  * More improvements to excerpts, see #110
42
  * Added content_class parameter