tec_is_view( string $view_slug = 'default', Tribe__Context $context = null )

Check whether we’re on a particular view.


Parameters

$view_slug

(string) (Optional) (optional) The view slug we are looking for. Defaults to checking if we are on the default view.

Default value: 'default'

$context

(Tribe__Context) (Optional) (optional) The view context. Generated via tribe_context() if not supplied.

Default value: null


Top ↑

Return

(boolean) Whether we're on the requested view.


Top ↑

Source

File: src/functions/template-tags/loop.php

function tec_is_view( string $view_slug = 'default', $context = null ): bool {
	$is_view   = false;
	$view_slug = strtolower( $view_slug );

	// In case we somehow get passed a non-string.
	if ( ! is_string( $view_slug ) ) {
		$view_slug = 'default';
	}

	if ( ! $context instanceof Tribe__Context ) {
		$context = tribe_context();
	}

	if ( $context->is( 'tec_post_type' ) ) {
		$current_view = $context->get( 'view', 'default' );

		$is_view = ( $view_slug === $current_view );

		// If we get 'default' but are testing for 'month',
		// make sure we return true when the default view is 'month'.
		if ( 'default' !== $view_slug && 'default' === $current_view ) {
			$is_view = ( $view_slug === tribe_get_option( 'viewOption' ) );
		}
	}

	/**
	 * Allows generic filtering of the tec_is_view boolean value.
	 *
	 * @since 6.0.7
	 *
	 * @param boolean $is_view Whether you're on the View or not
	 * @param Tribe__Context The global context object.
	 */
	$is_view = apply_filters( 'tec_is_view', $is_view, $view_slug, $context );

	/**
	 * Allows view-specific filtering of the tec_is_view boolean value.
	 *
	 * @since 6.0.7
	 *
	 * @param boolean $is_view Whether you're on the View or not
	 * @param Tribe__Context The global context object.
	 */
	return (bool) apply_filters( "tec_is_{$view_slug}_view", $is_view, $context );
}

Top ↑

Changelog

Changelog
Version Description
6.0.7 Introduced.