WP_Theme_JSON_Resolver::read_json_file()protected staticWP 5.8.0

Processes a file that adheres to the theme.json schema and returns an array with its contents, or a void array if none found.

Метод класса: WP_Theme_JSON_Resolver{}

Хуков нет.

Возвращает

Массив. Contents that adhere to the theme.json schema.

Использование

$result = WP_Theme_JSON_Resolver::read_json_file( $file_path );
$file_path(строка) (обязательный)
Path to file. Empty if no file.

Список изменений

С версии 5.8.0 Введена.
С версии 6.1.0 Added caching.

Код WP_Theme_JSON_Resolver::read_json_file() WP 6.5.2

protected static function read_json_file( $file_path ) {
	if ( $file_path ) {
		if ( array_key_exists( $file_path, static::$theme_json_file_cache ) ) {
			return static::$theme_json_file_cache[ $file_path ];
		}

		$decoded_file = wp_json_file_decode( $file_path, array( 'associative' => true ) );
		if ( is_array( $decoded_file ) ) {
			static::$theme_json_file_cache[ $file_path ] = $decoded_file;
			return static::$theme_json_file_cache[ $file_path ];
		}
	}

	return array();
}