Rewrite::filter_events_rewrite_rules_custom( TribeEventsProViewsV2array $rewrite_rules )

Filters The Events Calendar custom rewrite rules to fix the order and relative position of some and play nice with Views v2 canonical URL needs.

The operations performed by this method are pretty expensive (filtering and sorting preserving keys) and is meant to be used once when rewrite rules are generated. It’s NOT the kind of method that should run on each request.


Parameters

$rewrite_rules

(<span class="TribeEventsProViewsV2array">TribeEventsProViewsV2array) (Required) An array of The Events Calendar custom rewrite rules, in the same format used by WordPress: a map of each rule regular expression to the corresponding query string.


Top ↑

Return

(TribeEventsProViewsV2array<string,string>) The input map of The Events Calendar rewrite rules, updated to satisfy the needs of Views v2 canonical URL building.


Top ↑

Source

File: src/Tribe/Views/V2/Rewrite.php

	public function filter_events_rewrite_rules_custom( array $rewrite_rules ) {
		$rules_by_type = [ 'map' => [], 'week' => [], 'other' => [] ];

		// Divide the rules by type. Using the view slug is fine as it's in the query var, thus not translated.
		foreach ( $rewrite_rules as $regex => $query_string ) {
			if ( false !== strpos( $query_string, 'eventDisplay=map' ) ) {
				$rules_by_type['map'][ $regex ] = $query_string;
				continue;
			}

			if ( false !== strpos( $query_string, 'eventDisplay=week' ) ) {
				if ( false !== strpos( $regex, '/(\d{2})/?$' ) ) {
					// Discard week number rules: we do not support them in Views v2.
					continue;
				}
				$rules_by_type['week'][ $regex ] = $query_string;
				continue;
			}

			$rules_by_type['other'][ $regex ] = $query_string;
		}

		// Sort the rules to be map, week and others.
		$rewrite_rules = $rules_by_type['map'] + $rules_by_type['week'] + $rules_by_type['other'];

		return $rewrite_rules;
	}

Top ↑

Changelog

Changelog
Version Description
5.0.3 Introduced.