WP_Theme_JSON_Resolver::read_json_file() WordPress Method

The WP_Theme_JSON_Resolver::read_json_file() method is used to read a theme's JSON file and return its contents. This is useful for retrieving theme metadata, such as the name, description, and version.

WP_Theme_JSON_Resolver::read_json_file( string $file_path ) #

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


Parameters

$file_path

(string)(Required)Path to file. Empty if no file.


Top ↑

Return

(array) Contents that adhere to the theme.json schema.


Top ↑

Source

File: wp-includes/class-wp-theme-json-resolver.php

	protected static function read_json_file( $file_path ) {
		$config = array();
		if ( $file_path ) {
			$decoded_file = wp_json_file_decode( $file_path, array( 'associative' => true ) );
			if ( is_array( $decoded_file ) ) {
				$config = $decoded_file;
			}
		}
		return $config;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.