This plugin currently supplies a widget, and theme function.
<?php uwmadison_events('https://today.wisc.edu/events/tag/arts', array('limit' => 3)) ?>
<?php uwmadison_events('https://today.wisc.edu/events/tag/arts', array('limit' => 3, 'title' => 'Arts Events', 'grouped' => TRUE)) ?>
Here are my 4 newest events within post content:
[uwmadison_events url=https://today.wisc.edu/events/tag/film limit=4]
Look at 10 of the film events with a feed title of Film Events, showing descriptions:
[uwmadison_events url=https://today.wisc.edu/events/tag/film limit=10 grouped=1 title="Film Events" show_description=1]
uwmadison_events_get_remote($url, $opts)
<pre>
<?php print_r(uwmadison_events_get_remote('https://today.wisc.edu/events/tag/arts', array('limit' => 20))) ?>
</pre>
uwmadison_events_get_event_data($event_id)
<pre>
<?php print_r(uwmadison_events_get_event_data('123')) ?>
</pre>
Note: The today.wisc.edu JSON feed does not return a total count, so you will need to account for this in your logic, e.g. check if the number of events returned is less than per_page or zero.
Pagination with the theme function:
<?php uwmadison_events('https://today.wisc.edu/events/tag/arts', array('per_page' => 5, 'page' => 3)) ?>
<?php uwmadison_events('https://today.wisc.edu/events/tag/arts', array('per_page' => 5, 'page' => 3, 'title' => 'Arts Events', 'grouped' => TRUE)) ?>
Pagination with the lower level function:
5, 'page => 3'))) ?>
There are three date/time strings rendered by default. The default string is rendered for each event in the standard, non-grouped, view. A group item time is rendered for each event in the grouped view. The group header string is used for the date header for the group when rendering the list in group view.
These are all strings that use PHP date() formats which can be overriden with the uwmadison_events_date_formats filter. The filtered object is an associative array with three default keys, 'default', 'group_item', and 'group_header.' You may override these, as well as add your own format keys. Each array item returns a string, and will be made avialable in the event object. If you are going to be overriding the event html manually (covered later), it is still better to modify or add times to this array, which will be made available to you when you filter the event html. This is because this filter will take into account Wordpress's convention of always setting its timezone to UTC during runtime.
Example:
/**
* Filter the UW-Madison Events date formats
*/
function my_uw_events_date_formats($date_formats, $unix_time) {
// Change the default time beside each event
$date_formats['default'] = date('m/d/y', $unix_time) . ' (day of week: ' . date('l', $unix_time) . ')';
// Add a custom time format, made available in the $event
// object passed to other filters
$date_formats['my_time'] = 'My Time ' . date('Y-m-d', $unix_time);
// Custom header format for each group of events
// in the grouped event view
$date_formats['group_header'] = 'On - '. date('D', $unix_time);
return $date_formats;
}
add_filter('uwmadison_events_date_formats', 'my_uw_events_date_formats', 10, 1);
The uwmadison_events_html filter allows you to customize the content of each event's li in the ul of events, in both the standard and grouped views.
Example:
/**
* Customise the events html for the <li> or each event
*/
function my_uwmadison_events_html($html, $event, $opts) {
$my_event_html = 'Just the title ' . $event->title;
return $my_event_html;
}
// When registering this filter, we must tell it we're receiving 3 arguments
// if we want access to the $event object and options
add_filter('uwmadison_events_event_html', 'my_uwmadison_events_html', 10, 3);
The uwmadison_events_group_by filter allows you to group events by somethign other than the default, which is based on day_month_year.
Example:
/**
* Group event by just the month
*/
function my_uw_events_group_by($group_by) {
return "F"; // pass a PHP date() format string
}
add_filter('uwmadison_events_group_by', 'my_uw_events_group_by');
Breaking changes This version deprecates strftime() calls (deprecated in PHP 8.1; to be removed in PHP 9) with date().
Implementations that use the uwmadison_events_group_by or uwmadison_events_date_formats filters should update those filters to also use date() formats.
For the uwmadison_events_group_by filter, return a PHP datetime format instead of a strftime() format string.
For the uwmadison_events_date_formats filter, it now passes an arugment for $unix_time
which is the Unix time integer representation of an events start date and time. When overriding or adding to the formats array, use date()
with the passed $unix_time
value to generate your desired date format string.
- Replaces short-lived physical_location field from 1.3.0 with has_hybrid_format field which is a new boolean that indicates if an even has both a phycial and virtual location. If an event has only a physical location, the location field will show the location (note that a user can enter the word Online or Virtual in the freeform location field at today.wisc.edu - rare, but possible). If an event has only an online format, the location field will read Online (as prior to 1.3.0). If an event is hybrid, the location will show the physical location. The virtual_url field will have the online stream or website for details. NOTE: The default Wordpress tag for showing an event listing does not show any location info. The new has_hybrid_format only applies if you add custom templates in yur child theme.
- Pulls in two new fields from the today.wisc.edu API: virtual_url and physical_location. virtual_url is the URL users enter if their event has an Online option. The legacy location will now also indicate if an event has both a physical location and an online option. The location for a hybrid event will read, e.g. 200 Bascom Hall (also available online). The new fields allow you to show both a physical location and a virtual option, each with a link to either the campus map or the URL for the online event. NOTE: The default Wordpress tag for showing an event listing does not show any location info. These new fields only apply if you add custom templates in yur child theme.
- Tested up to Wordpress 5.7
- Changes the API base URL from http to https
- Replaces deprecated create_function with anonymous function (@kedarjoyner)
- Includes start and end params for function that builds a URL query (@kedarjoyner)
- Adds sponsor and tags as additional items to pull from the API (@kedarjoyner)
- Ensures limit option gets set - otherwise causes php warning that variable is unset. (@kedarjoyner)
- Adds code to test if the plugin's functions and classes already exist, to help avoid errors in instances where the plugin code might be packaged into a theme or another plugin outside of Wordpress's plugin manager. This release otherwise adds no new or changed featues.
- This is released as a minor update because the widet now properly uses the before_widget and after_widget parameters. In the process, the hard-coded widget_meta CSS class has been dropped. Any styling based on this hook will break unless you use Wordpress's dynamic_sidebar_params filter to add that class yourself.
- Cleans up a few minor PHP notices
- Adds filter for changing the default date string to group events by
- Adds url data attribute from today.wisc.edu
- Adds handling for wp_remote_get errors; returns FALSE (@sterlinganderson)
- Add uw_map_url field to processd output data. If location references a campus building, a map.wisc.edu URL will be returned, e.g. https://www.map.wisc.edu/?initObj=0485
- Now accepts per_page and page parameters corresponding to the today.wisc.edu API so that pagination can be designed into your integration of the plugin. E.g. uwmadison_events_get_remote('https://www.today.wisc.edu/events/feed/10', array('per_page' => 10, 'page' => 2)) will return events 11-20 from the feed. (Note: The feed does not return a total count, so you will need to account for this in your logic, e.g. check if the number of events returned is less than per_page or zero).
This version also allows the widget to set the header tag, which default to h2.
- Add location field to processd output data
- Default date formats check for Windows to swap out windows compatible strftime strings.
- Removes type from output since it is not passed in today.wisc.edu JSON
- Adds contact_phone, contact_email, cost and all_day_event to data output