upcoming-events.php 774 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. /**
  3. * Most of the heavy lifting done in iCalendarReader class
  4. */
  5. class Upcoming_Events_Shortcode {
  6. public static function init() {
  7. add_shortcode( 'upcomingevents', array( __CLASS__, 'shortcode' ) );
  8. }
  9. public static function shortcode( $atts = array() ) {
  10. jetpack_require_lib( 'icalendar-reader' );
  11. $atts = shortcode_atts( array( 'url' => '', 'number' => 0 ), $atts, 'upcomingevents' );
  12. $args = array(
  13. 'context' => 'shortcode',
  14. 'number' => absint( $atts['number'] ),
  15. );
  16. $events = icalendar_render_events( $atts['url'], $args );
  17. if ( ! $events ) {
  18. $events = sprintf( '<p>%s</p>', __( 'No upcoming events', 'jetpack' ) );
  19. }
  20. return $events;
  21. }
  22. }
  23. add_action( 'plugins_loaded', array( 'Upcoming_Events_Shortcode', 'init' ), 101 );