css
1 month ago
images
1 year ago
img
2 months ago
js
7 months ago
archiveorg-book.php
7 months ago
archiveorg.php
1 month ago
archives.php
1 week ago
bandcamp.php
7 months ago
brightcove.php
6 months ago
cartodb.php
7 months ago
class.filter-embedded-html-objects.php
7 months ago
codepen.php
7 months ago
crowdsignal.php
6 months ago
dailymotion.php
7 months ago
descript.php
7 months ago
facebook.php
7 months ago
flatio.php
7 months ago
flickr.php
7 months ago
getty.php
7 months ago
gist.php
7 months ago
googleapps.php
7 months ago
googlemaps.php
1 month ago
googleplus.php
7 months ago
gravatar.php
7 months ago
houzz.php
7 months ago
inline-pdfs.php
7 months ago
instagram.php
7 months ago
kickstarter.php
7 months ago
mailchimp.php
1 month ago
medium.php
7 months ago
mixcloud.php
7 months ago
others.php
7 months ago
pinterest.php
7 months ago
presentations.php
7 months ago
quiz.php
7 months ago
recipe.php
2 weeks ago
scribd.php
7 months ago
shortcode-utils.php
7 months ago
sitemap.php
7 months ago
slideshare.php
7 months ago
slideshow.php
2 weeks ago
smartframe.php
7 months ago
soundcloud.php
1 month ago
spotify.php
7 months ago
ted.php
7 months ago
tweet.php
7 months ago
twitchtv.php
2 weeks ago
twitter-timeline.php
7 months ago
twitter.php
7 months ago
unavailable.php
7 months ago
untappd-menu.php
7 months ago
upcoming-events.php
7 months ago
ustream.php
7 months ago
videopress.php
7 months ago
vimeo.php
1 month ago
vine.php
7 months ago
vr.php
1 month ago
wufoo.php
7 months ago
youtube.php
4 months ago
upcoming-events.php
71 lines
| 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 |