WP_Theme_JSON::get_name_from_defaults() WordPress Method

The WP_Theme_JSON::get_name_from_defaults() function is used to retrieve the name of a theme from its default values. This function is useful for themes that don't have a name assigned to them.

WP_Theme_JSON::get_name_from_defaults( string $slug, array $base_path ) #

Get a default‘s preset name by a provided slug.


Parameters

$slug

(string)(Required)The slug we want to find a match from default presets.

$base_path

(array)(Required)The path to inspect. It's 'settings' by default.


Top ↑

Return

(string|null)


Top ↑

Source

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

	protected function get_name_from_defaults( $slug, $base_path ) {
		$path            = array_merge( $base_path, array( 'default' ) );
		$default_content = _wp_array_get( $this->theme_json, $path, null );
		if ( ! $default_content ) {
			return null;
		}
		foreach ( $default_content as $item ) {
			if ( $slug === $item['slug'] ) {
				return $item['name'];
			}
		}
		return null;
	}


Top ↑

Changelog

Changelog
VersionDescription
5.9.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.