month_day_classes( TribeEventsViewsV2array $day, string $day_date, DateTime $request_date, string $today_date )

A list of CSS classes that will be added to the day “cell” in month view.

Used in the Month View days loop.


Parameters

$day

(<span class="TribeEventsViewsV2array">TribeEventsViewsV2array) (Required) The current day data.

$day_date

(string) (Required) The current day date in Y-m-d format.

$request_date

(DateTime) (Required) The request date for the view.

$today_date

(string) (Required) Today's date in Y-m-d format.


Top ↑

Return

(TribeEventsViewsV2array<string,bool>) $day_classes The classes to add to the day "cell".


Top ↑

Source

File: src/Tribe/Views/V2/functions/classes.php

function month_day_classes( array $day, string $day_date, \DateTime $request_date, string $today_date ) {
	// If for some reason we don't have a request date, use today's date.
	$comparison_date = ! empty( $request_date ) ? $request_date->format( 'Y-m-d' ) : $today_date;

	/**
	 * Allows filtering the date used for comparison when generating the Month View day cell classes.
	 *
	 * @since 6.0.2
	 *
	 * @param string       $comparison_date The date used for comparisons.
	 * @param DateTime     $request_date    The request date for the view.
	 * @param string       $day_date        The current day date, in the `Y-m-d` format.
	 * @param array<mixed> $day             The current day data.
	 */
	$comparison_date =  apply_filters( 'tec_events_month_day_classes_comparison_date', $comparison_date, $request_date, $day_date, $day  );

	// Convert it to a date object.
	$comparison_date = Dates::immutable( $comparison_date );

	// Classes in array are applied if the value is truthy, not applied if the value is falsy.
	$day_classes = [
		'tribe-events-calendar-month__day'              => true,
		// Add a class for the current day.
		'tribe-events-calendar-month__day--current'     => $comparison_date->format( 'Y-m-d' ) === $day_date,
		// Add a class for the past days (includes days in the requested month).
		'tribe-events-calendar-month__day--past'        => $comparison_date->format( 'Y-m-d' ) > $day_date,
		// Not the requested month.
		'tribe-events-calendar-month__day--other-month' => $day[ 'month_number' ] !== $comparison_date->format( 'm' ),
		// Past month.
		'tribe-events-calendar-month__day--past-month'  => $day[ 'month_number' ] < $comparison_date->format( 'm' ),
		// Future month.
		'tribe-events-calendar-month__day--next-month'  => $day[ 'month_number' ] > $comparison_date->format( 'm' ),
	];

	/**
	 * Allows filtering the final list of classes for each Month View day cell.
	 *
	 * @since 6.0.2
	 *
	 * @param array<string,bool> $day_classes     The classes to add to the day "cell".
	 * @param string             $comparison_date The date that was used for comparisons.
	 * @param array<mixed>       $day             The current day data.
	 *
	 * @return array<string> $day_classes The final list of classes to add to the day "cell".
	 */
	return (array) apply_filters( 'tec_events_month_day_classes', $day_classes, $comparison_date, $day );
}

Top ↑

Changelog

Changelog
Version Description
6.2.9 Updated logic to always default to comparing days with today's date.
6.0.2 Introduced.