View::clean_data( TribeEventsViewsV2Utilsarray $view_data )

Cleans the View data that will be printed by the components/data.php template to avoid its mangling.

By default, the View data is a copy of the View template variables, to avoid the mangling of the JSON data some entries of the data might require to be removed, some might require to be formatted or escaped.

Parameters #


(<span class="TribeEventsViewsV2UtilsarrayTribeEventsViewsV2Utilsarray<string,string|">TribeEventsViewsV2Utilsarray>) (Required) The initial View data.

Top ↑

Return #

(TribeEventsViewsV2Utilsarray<string,string|TribeEventsViewsV2Utilsarray>) The filtered View data, some entries removed from it to avoid the data script being mangled by escaping and texturizing functions running on it.

Top ↑

Source #

File: src/Tribe/Views/V2/Utils/View.php

	public static function clean_data( $view_data ) {
		if ( ! is_array( $view_data ) ) {
			return $view_data;

		 * Remove the JSON-LD data, it's already printed by the `components/json-ld-data.php` template. Printing a
		 * `<script>`, the JSON-LD data, inside a `<script>`, the data, will cause issues.
		$view_data = array_diff_key( $view_data, array_flip( [ 'json_ld_data' ] ) );

		// Remove objects that should not be printed on the page, keep data objects.
		$view_data = array_filter( $view_data, static function ( $value ) {
			return ! is_object( $value ) || $value instanceof \stdClass;
		} );

		return $view_data;

Top ↑

Changelog #

Version Description
5.1.5 Introduced.