Events Calendar Pro 3.10 will ship with a refactored Week view. This refactor was done so that Week view would be easier to understand under the hood, easier to customize, and more extensible. We’ve also added a couple new features.
Why We Did This
You may be wondering why we did this. Here is a list of the goals we wanted to accomplish with this refactor:
- Make the code in the week view template class easy to follow. The naming conventions and logic in there were very complex and convoluted.
- Take all logic out of the templates so that they are clean and easy to read for people who just want to make changes to their design.
- Make sure all the template tags are sensibly named, so you can ideally tell what they do just by reading the names. Make sure they are consistently named (they all start with “tribe_events_week_” now)
- Bring the week view template structure and general concept in line with how month view is done, I.E. create and make available an array of days to loop through, and a set of template tags that can be used to create a “week view loop” that nests to loop through each day in the week, and each day loops through each event in the day. This was sort of half implemented previously but didn’t really match up with the month view style exactly.
- Add two new features that have been requested by the community (ideally adding new features will be much easier with the new cleaned up code structure): the ability to hide weekends on week view via a new setting, and the ability to specify a specific hour range that shows on week view via a new filterable array of hours.
What You Should Know
Here are the major takeaways that you should be aware of
- CSS and markup changes have been very minimal, you will likely have no problems if your customizations are done through CSS only
- Customizations that have Week view template overrides will likely no longer function correctly. We have taken care to ensure that there will be no fatal errors on your site, but you may not see any events on your Week view after you update, if you do not update your templates to use the new code.
- If you have existing customizations, you will likely see a lot of deprecated notices if you have WP_DEBUG enabled.
- The script that creates the custom scrollbar on the Week view layout has been changed to nanoscroller
Here’s an overview of what’s changed in each Week view template part:
|Template Part||What’s Changed|
Here’s a list of what’s been deprecated:
|tribe_events_week_is_current_today()||no replacement||You can achieve the same conditional check with this code:
|tribe_events_week_set_loop_type()||no replacement||“loop type” concept has been removed, there is no longer a need for this template tag|
|tribe_events_week_the_day_map()||tribe_events_week_the_day()||tribe_events_week_the_day() will increment the counter for the current day in the week view loop, similar to what the_post() does for a WordPress query|
|tribe_events_week_reset_the_day_map()||Tribe_Events_Pro_Week_Template::rewind_days();||this function is no longer necessary in your templates|
|tribe_events_week_get_the_day_display()||tribe_events_week_day_header()||tribe_events_week_day_header() will output all the text needed in your day header cells|
|tribe_events_week_get_all_day_map()||no replacement||this function is no longer necessary in your templates|
|tribe_events_week_get_hourly()||no replacement||this function is no longer necessary in your templates|
|tribe_events_week_setup_event()||no replacement||this function is no longer necessary in your templates|
|tribe_events_week_get_event_id()||no replacment||you can get the current event id from the global $post|
|tribe_events_week_is_all_day_placeholder()||no replacement||this function is no longer necessary in your templates|
|tribe_events_week_get_event()||no replacement||you can get the current event from the global $post|
|tribe_events_current_week_day_has_events()||tribe_events_week_get_current_day()||tribe_events_week_get_current_day() returns an array with information about the current day. you can simply check the ‘has_events’ element of that array|
|tribe_previous_week_link()||tribe_events_week_previous_link()||renamed for consistency|
|tribe_events_week_next_link()||tribe_events_week_next_link()||renamed for consistency|
New Template Tags
Here’s a list of the new template tags we’ve added:
|Function||What it does|
As was mentioned under “Why we did this”, we have added two new features to the Week view. Those are:
- An option to hide weekends. This comes in the form of a new checkbox on the Events > Settings > Display tab called “Hide weekends on Week View”.
- The ability to customize what hours are displayed on the Week View grid. This can be done via a filter called ‘tribe_events_week_get_hours’. If you hook into that filter, you will receive an array of the 24 hours of the day. You can remove hours you don’t want to display and return the array. The array should be such that the keys are the hour, from 0 to 23, and the values are the hours in the format you would like to display them. For example:
In addition to making the new week view easier to customize, we made a few small enhancements and corrected some bugs from the old week view. Here is a list of those changes:
- Tweak – Updated tooltip positioning logic for week view to account for more edge cases
- Tweak – Updated week view to better handle very short events and long titles (thanks to csikimacko for the heads up!)
- Bug – Fixed issues with all day multiday events in Week View when Week Starts On was changed (thanks to Mark Root-Wiley for reporting this!)
- Bug – Fixed a bug where resizing browser window caused Week View header to expand its height
- Bug – Fixed a bug with the tooltip improperly HTML escaping characters twice (thanks to evertramos on the dot-org forums for the report!)