WP_Theme_JSON_Resolver::get_file_path_from_theme()protected staticWP 5.8.0

Builds the path to the given file and checks that it is readable.

If it isn't, returns an empty string, otherwise returns the whole file path.

Method of the class: WP_Theme_JSON_Resolver{}

No Hooks.

Return

String. The whole file path or empty if the file doesn't exist.

Usage

$result = WP_Theme_JSON_Resolver::get_file_path_from_theme( $file_name, $template );
$file_name(string) (required)
Name of the file.
$template(true|false)
Use template theme directory.
Default: false

Changelog

Since 5.8.0 Introduced.
Since 5.9.0 Adapted to work with child themes, added the $template argument.

WP_Theme_JSON_Resolver::get_file_path_from_theme() code WP 6.5.3

protected static function get_file_path_from_theme( $file_name, $template = false ) {
	$path      = $template ? get_template_directory() : get_stylesheet_directory();
	$candidate = $path . '/' . $file_name;

	return is_readable( $candidate ) ? $candidate : '';
}