PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 7.1.5
Jetpack – WP Security, Backup, Speed, & Growth v7.1.5
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / shortcodes / archives.php

archives.php in Jetpack – WP Security, Backup, Speed, & Growth 7.1.5, at modules/shortcodes/archives.php

76 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * Archives shortcode
5 * @author bubel & nickmomrik
6 * [archives limit=10]
7 */
8
9 add_shortcode( 'archives', 'archives_shortcode' );
10
11 function archives_shortcode( $atts ) {
12 if ( is_feed() ) {
13 return '[archives]';
14 }
15
16 global $allowedposttags;
17
18 $default_atts = array(
19 'type' => 'postbypost',
20 'limit' => '',
21 'format' => 'html',
22 'showcount' => false,
23 'before' => '',
24 'after' => '',
25 'order' => 'desc',
26 );
27
28 $attr = shortcode_atts( $default_atts, $atts, 'archives' );
29
30 if ( ! in_array( $attr['type'], array( 'yearly', 'monthly', 'daily', 'weekly', 'postbypost' ) ) ) {
31 $attr['type'] = 'postbypost';
32 }
33
34 if ( ! in_array( $attr['format'], array( 'html', 'option', 'custom' ) ) ) {
35 $attr['format'] = 'html';
36 }
37
38 $limit = intval( $attr['limit'] );
39 // A Limit of 0 makes no sense so revert back to the default.
40 if ( empty( $limit ) ) {
41 $limit = '';
42 }
43
44 $showcount = ( false !== $attr['showcount'] && 'false' !== $attr['showcount'] ) ? true : false;
45 $before = wp_kses( $attr['before'], $allowedposttags );
46 $after = wp_kses( $attr['after'], $allowedposttags );
47
48 // Get the archives
49 $archives = wp_get_archives(
50 array(
51 'type' => $attr['type'],
52 'limit' => $limit,
53 'format' => $attr['format'],
54 'echo' => false,
55 'show_post_count' => $showcount,
56 'before' => $before,
57 'after' => $after,
58 )
59 );
60
61 if ( 'asc' === $attr['order'] ) {
62 $archives = implode( "\n", array_reverse( explode( "\n", $archives ) ) );
63 }
64
65 // Check to see if there are any archives
66 if ( empty( $archives ) ) {
67 $archives = '<p>' . __( 'Your blog does not currently have any published posts.', 'jetpack' ) . '</p>';
68 } elseif ( 'option' === $attr['format'] ) {
69 $archives = '<select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;"><option value="' . get_permalink() . '">--</option>' . $archives . '</select>';
70 } elseif ( 'html' === $attr['format'] ) {
71 $archives = '<ul>' . $archives . '</ul>';
72 }
73
74 return $archives;
75 }
76