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