PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2
Jetpack – WP Security, Backup, Speed, & Growth v16.2
16.2 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 All 502 releases
jetpack / modules / shortcodes / upcoming-events.php

upcoming-events.php in Jetpack – WP Security, Backup, Speed, & Growth 16.2, at modules/shortcodes/upcoming-events.php

71 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
2
3 /**
4 * Display a list of upcoming events from a calendar.
5 *
6 * @package automattic/jetpack
7 */
8
9 if ( ! defined( 'ABSPATH' ) ) {
10 exit( 0 );
11 }
12
13 /**
14 * Register a upcomingevents shortcode.
15 * Most of the heavy lifting done in iCalendarReader class,
16 * where the icalendar_render_events() function controls the display.
17 */
18 class Upcoming_Events_Shortcode {
19
20 /**
21 * Register things.
22 */
23 public static function init() {
24 add_shortcode( 'upcomingevents', array( __CLASS__, 'shortcode' ) );
25 }
26
27 /**
28 * Register the shortcode.
29 *
30 * @param array $atts Shortcode attributes.
31 */
32 public static function shortcode( $atts = array() ) {
33 require_once JETPACK__PLUGIN_DIR . '/_inc/lib/icalendar-reader.php';
34 $atts = shortcode_atts(
35 array(
36 'url' => '',
37 'number' => 0,
38 ),
39 $atts,
40 'upcomingevents'
41 );
42 $args = array(
43 'context' => 'shortcode',
44 'number' => absint( $atts['number'] ),
45 );
46
47 if ( empty( $atts['url'] ) ) {
48 // If the current user can access the Appearance->Widgets page.
49 if ( current_user_can( 'edit_theme_options' ) ) {
50 return sprintf( '<p>%s</p>', __( 'You must specify a URL to an iCalendar feed in the shortcode. This notice is only displayed to administrators.', 'jetpack' ) );
51 }
52 return self::no_upcoming_event_text();
53 }
54 $events = icalendar_render_events( $atts['url'], $args );
55
56 if ( ! $events ) {
57 $events = self::no_upcoming_event_text();
58 }
59
60 return $events;
61 }
62
63 /**
64 * Returns No Upcoming Event text.
65 */
66 private static function no_upcoming_event_text() {
67 return sprintf( '<p>%s</p>', __( 'No upcoming events', 'jetpack' ) );
68 }
69 }
70 add_action( 'after_setup_theme', array( 'Upcoming_Events_Shortcode', 'init' ), 2 );
71