wp_get_block_name_from_theme_json_path( array $path ): string

In this article

This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

Gets the block name from a given theme.json path.

Parameters

$patharrayrequired
An array of keys describing the path to a property in theme.json.

Return

string Identified block name, or empty string if none found.

Source

function wp_get_block_name_from_theme_json_path( $path ) {
	// Block name is expected to be the third item after 'styles' and 'blocks'.
	if (
		count( $path ) >= 3
		&& 'styles' === $path[0]
		&& 'blocks' === $path[1]
		&& str_contains( $path[2], '/' )
	) {
		return $path[2];
	}

	/*
	 * As fallback and for backward compatibility, allow any core block to be
	 * at any position.
	 */
	$result = array_values(
		array_filter(
			$path,
			static function ( $item ) {
				if ( str_contains( $item, 'core/' ) ) {
					return true;
				}
				return false;
			}
		)
	);
	if ( isset( $result[0] ) ) {
		return $result[0];
	}
	return '';
}

Changelog

VersionDescription
6.3.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.