tribe_get_post_class( string|string[] $class, int|WP_Post $post )

Wrapper for post_class function that allows us to in-memory cache


Parameters #

$class

(string|string[]) (Required) Space-separated string or array of class names to add to the class list.

$post

(int|WP_Post) (Optional) Post ID or post object.


Top ↑

Return #

(string[]) Array of class names.


Top ↑

Source #

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

function tribe_get_post_class( $class, $post ) {
	static $post_classes = [];

	if ( is_numeric( $post ) ) {
		$post_id = $post;
	} else {
		$post_id = $post->ID;
	}

	if ( ! isset( $post_classes[ $post_id ] ) ) {
		$post_classes[ $post_id ] = get_post_class( [], $post );
	}

	if ( ! is_array( $class ) ) {
		$class = explode( ' ', $class );
	}

	return array_merge( $class, $post_classes[ $post_id ] );
}

Top ↑

Changelog #

Changelog
Version Description
4.11.0 Introduced.