Simple Sitemap – Automatically Generate a Responsive Sitemap - Version 1.82

Version Description

Download this release

Release Info

Developer dgwyer
Plugin Icon Simple Sitemap – Automatically Generate a Responsive Sitemap
Version 1.82
Comparing to
See all releases

Code changes from version 1.81 to 1.82

Files changed (2) hide show
  1. readme.txt +6 -1
  2. simple-sitemap.php +184 -13
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: dgwyer
3
  Tags: sitemap, html, global, sort, shortcode, pages, posts
4
  Requires at least: 2.7
5
  Tested up to: 4.4
6
- Stable tag: 1.81
7
 
8
  Powerful but simple to use HTML sitemap. Display site content in one or more lists separated by post type, customized via flexible filters.
9
 
@@ -58,6 +58,11 @@ See our <a href="http://www.wpgoplugins.com" target="_blank">WordPress plugin si
58
 
59
  == Changelog ==
60
 
 
 
 
 
 
61
  *1.81 update*
62
 
63
  * Screenshots updated.
3
  Tags: sitemap, html, global, sort, shortcode, pages, posts
4
  Requires at least: 2.7
5
  Tested up to: 4.4
6
+ Stable tag: 1.82
7
 
8
  Powerful but simple to use HTML sitemap. Display site content in one or more lists separated by post type, customized via flexible filters.
9
 
58
 
59
  == Changelog ==
60
 
61
+ *1.82 update*
62
+
63
+ * Better security.
64
+ * Fix: Some pretty permalinks weren't being displayed properly for posts.
65
+
66
  *1.81 update*
67
 
68
  * Screenshots updated.
simple-sitemap.php CHANGED
@@ -2,8 +2,8 @@
2
  /*
3
  Plugin Name: Simple Sitemap
4
  Plugin URI: http://wordpress.org/plugins/simple-sitemap/
5
- Description: HTML sitemap to display content as a single linked list of posts and pages, or as groups sorted by taxonomy (via a drop-down box).
6
- Version: 1.81
7
  Author: David Gwyer
8
  Author URI: http://www.wpgothemes.com
9
  Text Domain: simple-sitemap
@@ -29,6 +29,7 @@ Text Domain: simple-sitemap
29
  /* wpss_ prefix is derived from [W]ord[P]ress [s]imple [s]itemap. */
30
 
31
  add_shortcode( 'simple-sitemap', 'wpss_render_sitemap' );
 
32
  add_action( 'admin_init', 'wpss_init' );
33
  add_action( 'admin_menu', 'wpss_add_options_page' );
34
  add_filter( 'plugin_action_links', 'wpss_plugin_action_links', 10, 2 );
@@ -118,7 +119,7 @@ function wpss_render_sitemap($args) {
118
 
119
  /* Get slider attributes from the shortcode. */
120
  extract( shortcode_atts( array(
121
- 'types' => 'post, page',
122
  'show_excerpt' => 'false',
123
  'title_tag' => '',
124
  'excerpt_tag' => 'div',
@@ -131,6 +132,12 @@ function wpss_render_sitemap($args) {
131
  'exclude' => ''
132
  ), $args ) );
133
 
 
 
 
 
 
 
134
  $post_types = $types; // allows the use of the shorter 'types' rather than 'post_types' in the shortcode
135
 
136
  // Start output caching (so that existing content in the [simple-sitemap] post doesn't get shoved to the bottom of the post
@@ -173,7 +180,7 @@ function wpss_render_sitemap($args) {
173
  if( $show_label == 'true' ) {
174
  $post_type_obj = get_post_type_object( $post_type );
175
  $post_type_name = $post_type_obj->labels->name;
176
- echo '<' . $post_type_tag . '>' . $post_type_name . '</' . $post_type_tag . '>';
177
  }
178
 
179
  $query_args = array(
@@ -194,7 +201,7 @@ function wpss_render_sitemap($args) {
194
  'page_depth' => $page_depth,
195
  'exclude' => $exclude
196
  );
197
- echo '<ul class="' . $ul_class . '">';
198
  wpss_list_pages($arr, $query_args);
199
  echo '</ul>';
200
  continue;
@@ -205,7 +212,7 @@ function wpss_render_sitemap($args) {
205
 
206
  if ( $sitemap_query->have_posts() ) :
207
 
208
- echo '<ul class="' . $ul_class . '">';
209
 
210
  // start of the loop
211
  while ( $sitemap_query->have_posts() ) : $sitemap_query->the_post();
@@ -215,21 +222,21 @@ function wpss_render_sitemap($args) {
215
 
216
  if( !empty( $title_text ) ) {
217
  if ( $links == 'true' ) {
218
- $title = $title_open . '<a href="' . get_post_permalink() . '">' . $title_text . '</a>' . $title_close;
219
  } else {
220
- $title = $title_open . $title_text . $title_close;
221
  }
222
  }
223
  else {
224
  if ( $links == 'true' ) {
225
- $title = $title_open . '<a href="' . get_post_permalink() . '">' . '(no title)' . '</a>' . $title_close;
226
  } else {
227
  $title = $title_open . '(no title)' . $title_close;
228
  }
229
  }
230
 
231
  // excerpt
232
- $excerpt = $show_excerpt == 'true' ? '<' . $excerpt_tag . '>' . get_the_excerpt() . '</' . $excerpt_tag . '>' : '';
233
 
234
  // render list item
235
  echo '<li>';
@@ -256,10 +263,174 @@ function wpss_render_sitemap($args) {
256
  // CONTENT END
257
  // ***********
258
 
259
- $sitemap = ob_get_contents();;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
260
  ob_end_clean();
261
 
262
- return $sitemap;
263
  }
264
 
265
  function wpss_list_pages( $arr, $query_args ) {
@@ -326,7 +497,7 @@ function wpss_list_pages( $arr, $query_args ) {
326
  function wpss_plugin_action_links( $links, $file ) {
327
 
328
  if ( $file == plugin_basename( __FILE__ ) ) {
329
- $posk_links = '<a href="' . get_admin_url() . 'options-general.php?page=simple-sitemap/simple-sitemap.php">' . __( 'Settings', 'simple-sitemap' ) . '</a>';
330
  // make the 'Settings' link appear first
331
  array_unshift( $links, $posk_links );
332
  }
2
  /*
3
  Plugin Name: Simple Sitemap
4
  Plugin URI: http://wordpress.org/plugins/simple-sitemap/
5
+ Description: HTML sitemap to display content as a single linked list of posts, pages, or custom post types. You can even display posts in groups sorted by taxonomy!
6
+ Version: 1.82
7
  Author: David Gwyer
8
  Author URI: http://www.wpgothemes.com
9
  Text Domain: simple-sitemap
29
  /* wpss_ prefix is derived from [W]ord[P]ress [s]imple [s]itemap. */
30
 
31
  add_shortcode( 'simple-sitemap', 'wpss_render_sitemap' );
32
+ add_shortcode( 'simple-sitemap-group', 'wpss_render_sitemap_group' );
33
  add_action( 'admin_init', 'wpss_init' );
34
  add_action( 'admin_menu', 'wpss_add_options_page' );
35
  add_filter( 'plugin_action_links', 'wpss_plugin_action_links', 10, 2 );
119
 
120
  /* Get slider attributes from the shortcode. */
121
  extract( shortcode_atts( array(
122
+ 'types' => 'page',
123
  'show_excerpt' => 'false',
124
  'title_tag' => '',
125
  'excerpt_tag' => 'div',
132
  'exclude' => ''
133
  ), $args ) );
134
 
135
+ // escape tag names
136
+ $title_tag = tag_escape( $title_tag );
137
+ $excerpt_tag = tag_escape( $excerpt_tag );
138
+ $post_type_tag = tag_escape( $post_type_tag );
139
+
140
+ $page_depth = intval( $page_depth );
141
  $post_types = $types; // allows the use of the shorter 'types' rather than 'post_types' in the shortcode
142
 
143
  // Start output caching (so that existing content in the [simple-sitemap] post doesn't get shoved to the bottom of the post
180
  if( $show_label == 'true' ) {
181
  $post_type_obj = get_post_type_object( $post_type );
182
  $post_type_name = $post_type_obj->labels->name;
183
+ echo '<' . $post_type_tag . '>' . esc_html($post_type_name) . '</' . $post_type_tag . '>';
184
  }
185
 
186
  $query_args = array(
201
  'page_depth' => $page_depth,
202
  'exclude' => $exclude
203
  );
204
+ echo '<ul class="' . esc_attr($ul_class) . '">';
205
  wpss_list_pages($arr, $query_args);
206
  echo '</ul>';
207
  continue;
212
 
213
  if ( $sitemap_query->have_posts() ) :
214
 
215
+ echo '<ul class="' . esc_attr($ul_class) . '">';
216
 
217
  // start of the loop
218
  while ( $sitemap_query->have_posts() ) : $sitemap_query->the_post();
222
 
223
  if( !empty( $title_text ) ) {
224
  if ( $links == 'true' ) {
225
+ $title = $title_open . '<a href="' . esc_url(get_permalink()) . '">' . esc_html($title_text) . '</a>' . $title_close;
226
  } else {
227
+ $title = $title_open . esc_html($title_text) . $title_close;
228
  }
229
  }
230
  else {
231
  if ( $links == 'true' ) {
232
+ $title = $title_open . '<a href="' . esc_url(get_permalink()) . '">' . '(no title)' . '</a>' . $title_close;
233
  } else {
234
  $title = $title_open . '(no title)' . $title_close;
235
  }
236
  }
237
 
238
  // excerpt
239
+ $excerpt = $show_excerpt == 'true' ? '<' . $excerpt_tag . '>' . esc_html(get_the_excerpt()) . '</' . $excerpt_tag . '>' : '';
240
 
241
  // render list item
242
  echo '<li>';
263
  // CONTENT END
264
  // ***********
265
 
266
+ $sitemap = ob_get_contents();
267
+ ob_end_clean();
268
+
269
+ return wp_kses_post($sitemap);
270
+ }
271
+
272
+ /* Shortcode function. */
273
+ function wpss_render_sitemap_group($args) {
274
+
275
+ /* Get slider attributes from the shortcode. */
276
+ extract( shortcode_atts( array(
277
+ 'tax' => 'category', // single taxonomy
278
+ 'term_order' => 'asc',
279
+ 'term_orderby' => 'name',
280
+ 'show_excerpt' => 'false',
281
+ 'title_tag' => '',
282
+ 'excerpt_tag' => 'div',
283
+ 'post_type_tag' => 'h2',
284
+ 'show_label' => 'true',
285
+ 'links' => 'true',
286
+ 'page_depth' => 0,
287
+ 'order' => 'asc',
288
+ 'orderby' => 'title',
289
+ 'exclude' => ''
290
+ ), $args ) );
291
+
292
+ // escape tag names
293
+ $title_tag = tag_escape( $title_tag );
294
+ $excerpt_tag = tag_escape( $excerpt_tag );
295
+ $post_type_tag = tag_escape( $post_type_tag );
296
+
297
+ $page_depth = intval( $page_depth );
298
+ $post_type = 'post';
299
+
300
+ // Start output caching (so that existing content in the [simple-sitemap] post doesn't get shoved to the bottom of the post
301
+ ob_start();
302
+
303
+ // *************
304
+ // CONTENT START
305
+ // *************
306
+
307
+ $exclude = array_map( 'trim', explode( ',', $exclude) ); // must be array to work in the post query
308
+ $registered_post_types = get_post_types();
309
+
310
+ //echo "<pre>";
311
+ //print_r($registered_post_types);
312
+ //print_r($post_types);
313
+ //print_r($exclude);
314
+ //echo "</pre>";
315
+
316
+ $taxonomy_arr = get_object_taxonomies( $post_type );
317
+
318
+ // sort via specified taxonomy
319
+ if ( !empty($tax) && in_array( $tax, $taxonomy_arr ) ) {
320
+
321
+ // conditionally show label for each post type
322
+ if( $show_label == 'true' ) {
323
+ $post_type_obj = get_post_type_object( $post_type );
324
+ $post_type_name = $post_type_obj->labels->name;
325
+ echo '<' . $post_type_tag . '>' . esc_html($post_type_name) . '</' . $post_type_tag . '>';
326
+ }
327
+
328
+ $term_attr = array(
329
+ 'orderby' => $term_orderby,
330
+ 'order' => $term_order
331
+ );
332
+ $terms = get_terms( $tax, $term_attr );
333
+
334
+ foreach($terms as $term) {
335
+
336
+ // generate <ul> element class
337
+ $ul_class = 'simple-sitemap-' . $post_type;
338
+
339
+ // bail if post type isn't valid
340
+ if( !array_key_exists( $post_type, $registered_post_types ) ) {
341
+ break;
342
+ }
343
+
344
+ // set opening and closing title tag
345
+ if( !empty($title_tag) ) {
346
+ $title_open = '<' . $title_tag . '>';
347
+ $title_close = '</' . $title_tag . '>';
348
+ }
349
+ else {
350
+ $title_open = $title_close = '';
351
+ }
352
+
353
+ $query_args = array(
354
+ 'posts_per_page' => -1,
355
+ 'post_type' => $post_type,
356
+ 'order' => $order,
357
+ 'orderby' => $orderby,
358
+ 'post__not_in' => $exclude,
359
+ 'tax_query' => array(
360
+ array(
361
+ 'taxonomy' => $tax,
362
+ 'field' => 'slug',
363
+ 'terms' => $term
364
+ )
365
+ )
366
+ );
367
+
368
+ echo '<h4>' . $term->name . '</h4>';
369
+
370
+ //post query
371
+ $sitemap_query = new WP_Query( $query_args );
372
+
373
+ if ( $sitemap_query->have_posts() ) :
374
+
375
+ echo '<ul class="' . esc_attr($ul_class) . '">';
376
+
377
+ // start of the loop
378
+ while ( $sitemap_query->have_posts() ) : $sitemap_query->the_post();
379
+
380
+ // title
381
+ $title_text = get_the_title();
382
+
383
+ if( !empty( $title_text ) ) {
384
+ if ( $links == 'true' ) {
385
+ $title = $title_open . '<a href="' . esc_url(get_permalink()) . '">' . esc_html($title_text) . '</a>' . $title_close;
386
+ } else {
387
+ $title = $title_open . esc_html($title_text) . $title_close;
388
+ }
389
+ }
390
+ else {
391
+ if ( $links == 'true' ) {
392
+ $title = $title_open . '<a href="' . esc_url(get_permalink()) . '">' . '(no title)' . '</a>' . $title_close;
393
+ } else {
394
+ $title = $title_open . '(no title)' . $title_close;
395
+ }
396
+ }
397
+
398
+ // excerpt
399
+ $excerpt = $show_excerpt == 'true' ? '<' . $excerpt_tag . '>' . esc_html(get_the_excerpt()) . '</' . $excerpt_tag . '>' : '';
400
+
401
+ // render list item
402
+ echo '<li>';
403
+ echo $title;
404
+ echo $excerpt;
405
+ echo '</li>';
406
+
407
+ endwhile; // end of post loop -->
408
+
409
+ echo '</ul>';
410
+
411
+ // put pagination functions here
412
+ wp_reset_postdata();
413
+
414
+ else:
415
+
416
+ echo '<p>' . __( 'Sorry, no posts matched your criteria.', 'wpgo-simple-sitemap-pro' ) . '</p>';
417
+
418
+ endif;
419
+ }
420
+ }
421
+ else {
422
+ echo "No posts found.";
423
+ }
424
+
425
+
426
+ // ***********
427
+ // CONTENT END
428
+ // ***********
429
+
430
+ $sitemap = ob_get_contents();
431
  ob_end_clean();
432
 
433
+ return wp_kses_post($sitemap);
434
  }
435
 
436
  function wpss_list_pages( $arr, $query_args ) {
497
  function wpss_plugin_action_links( $links, $file ) {
498
 
499
  if ( $file == plugin_basename( __FILE__ ) ) {
500
+ $posk_links = '<a href="' . esc_url(get_admin_url() . 'options-general.php?page=simple-sitemap/simple-sitemap.php' ) . '">' . __( 'Settings', 'simple-sitemap' ) . '</a>';
501
  // make the 'Settings' link appear first
502
  array_unshift( $links, $posk_links );
503
  }