\WP_Stager_Integration\Calendar::component_week(int $year, int $week, array $all_events = null, array $args = array()): void

Description

Render a full week view of events.

Ensures that all 7 days of the week exist in the hierarchy, even if they contain no events. When clipping is enabled, only days within $args['start'] and $args['end'] are included.

Parameters:

ParameterTypeDescription
$year int The year (e.g. 2025).
$week int The ISO week number (1–53).
$all_events array Nested hierarchy of events (year → month → day).
$args array (Optional) Additional arguments to pass to the component template.

Returns:

void

Information

Fileclass-calendar.php line 1861

Full Code

/**
 * Render a full week view of events.
 *
 * Ensures that all 7 days of the week exist in the hierarchy,
 * even if they contain no events. When clipping is enabled,
 * only days within <code>$args['start']</code> and <code>$args['end']</code> are included.
 *
 * @param int   $year           The year (e.g. 2025).
 * @param int   $week           The ISO week number (1–53).
 * @param array $all_events     Nested hierarchy of events (year → month → day).
 * @param array $args           (Optional) Additional arguments to pass to the component template.
 *
 * @return void
 */
public static function component_week( $year, $week, $all_events = null, $args = array() ) {

    // Type casting
    $year       = (int) $year;
    $week       = (int) $week;
    $all_events = (array) $all_events;
    $args       = (array) $args;

    // Get week range
    $week_start = (int) self::calculate_timestamp_week_start( $year, $week );
    $week_end   = (int) self::calculate_timestamp_week_end( $year, $week );

    // Clip range (if enabled)
    $clip  = (bool) ($args[ 'clip' ] ?? false);
    $start = (int) ($args[ 'start' ] ?? 0);
    $end   = (int) ($args[ 'end' ] ?? 0);

    // Init week days
    $days = array();

    for (
            $timestamp = $week_start;
            $timestamp <= $week_end;
            $timestamp = self::calculate_offset_timestamp( $timestamp, 'P1D' )
    ) {
        $y = wp_date( 'Y', $timestamp );
        $m = self::get_month_number( $timestamp );
        $d = self::get_day_number( $timestamp );

        // If clipped and outside range → insert empty placeholder
        if ( $clip && $start && $end && ($timestamp < $start || $timestamp > $end) ) {
            $days[ $y ][ $m ][ $d ] = array(); // empty but present
            continue;
        }

        // Normal: fetch events
        $days[ $y ][ $m ][ $d ] = (array) ($all_events[ $y ][ $m ][ $d ] ?? array());
    }

    self::render_calendar_component( 'week', array(
        'year'           => $year,
        'week_number'    => $week,
        'events'         => $days,
        'component_args' => $args,
    ) );
}

šŸ’” If you ever get stuck or have a question, please check our FAQs, our Free Integration Service, our paid Full Integration Service, or reach out to us!

Get WP Stager Integration

šŸŽ Limited offer: Use code WELCOME26 to get your first month for free!