kollapsminoriteten/wp-content/plugins/jetpack/modules/shortcodes/upcoming-events.php

71 lines
1.7 KiB
PHP
Raw Normal View History

2019-11-15 23:26:29 +01:00
<?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName
/**
* Display a list of upcoming events from a calendar.
*
2021-04-27 08:32:47 +02:00
* @package automattic/jetpack
2019-11-15 23:26:29 +01:00
*/
2025-12-12 13:13:07 +01:00
if ( ! defined( 'ABSPATH' ) ) {
exit( 0 );
}
2019-11-15 23:26:29 +01:00
/**
* Register a upcomingevents shortcode.
* Most of the heavy lifting done in iCalendarReader class,
* where the icalendar_render_events() function controls the display.
*/
class Upcoming_Events_Shortcode {
/**
* Register things.
*/
public static function init() {
add_shortcode( 'upcomingevents', array( __CLASS__, 'shortcode' ) );
}
/**
* Register the shortcode.
*
* @param array $atts Shortcode attributes.
*/
public static function shortcode( $atts = array() ) {
2022-12-15 17:41:53 +01:00
require_once JETPACK__PLUGIN_DIR . '/_inc/lib/icalendar-reader.php';
2023-01-25 20:43:46 +01:00
$atts = shortcode_atts(
2019-11-15 23:26:29 +01:00
array(
'url' => '',
'number' => 0,
),
$atts,
'upcomingevents'
);
2023-01-25 20:43:46 +01:00
$args = array(
2019-11-15 23:26:29 +01:00
'context' => 'shortcode',
'number' => absint( $atts['number'] ),
);
2023-01-25 20:43:46 +01:00
if ( empty( $atts['url'] ) ) {
// If the current user can access the Appearance->Widgets page.
if ( current_user_can( 'edit_theme_options' ) ) {
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' ) );
}
return self::no_upcoming_event_text();
}
2019-11-15 23:26:29 +01:00
$events = icalendar_render_events( $atts['url'], $args );
if ( ! $events ) {
2023-01-25 20:43:46 +01:00
$events = self::no_upcoming_event_text();
2019-11-15 23:26:29 +01:00
}
return $events;
}
2023-01-25 20:43:46 +01:00
/**
* Returns No Upcoming Event text.
*/
private static function no_upcoming_event_text() {
return sprintf( '<p>%s</p>', __( 'No upcoming events', 'jetpack' ) );
}
2019-11-15 23:26:29 +01:00
}
2025-02-28 08:42:11 +01:00
add_action( 'after_setup_theme', array( 'Upcoming_Events_Shortcode', 'init' ), 2 );