The get_block_metadata_i18n_schema WordPress PHP function retrieves the i18n schema for a block’s metadata read from the block.json file.
Usage
get_block_metadata_i18n_schema();
Parameters
- None
More information
See WordPress Developer Resources: get_block_metadata_i18n_schema
Examples
Retrieve i18n schema for block metadata
This example demonstrates how to get the i18n schema for a block’s metadata.
// Get the i18n schema for block metadata $i18n_schema = get_block_metadata_i18n_schema(); // Display the i18n schema print_r($i18n_schema);
Check if a specific key exists in the i18n schema
This example checks if a specific key, such as ‘title’, exists in the i18n schema.
// Get the i18n schema for block metadata
$i18n_schema = get_block_metadata_i18n_schema();
// Check if the 'title' key exists
if (array_key_exists('title', $i18n_schema)) {
echo "The 'title' key exists in the i18n schema.";
} else {
echo "The 'title' key does not exist in the i18n schema.";
}
Count the number of keys in the i18n schema
This example counts the number of keys in the i18n schema.
// Get the i18n schema for block metadata
$i18n_schema = get_block_metadata_i18n_schema();
// Count the number of keys in the i18n schema
$key_count = count($i18n_schema);
// Display the key count
echo "The i18n schema has {$key_count} keys.";
Get the i18n schema and filter by a specific data type
This example retrieves the i18n schema and filters the results by a specific data type, such as strings.
// Get the i18n schema for block metadata
$i18n_schema = get_block_metadata_i18n_schema();
// Filter the i18n schema for string data types
$string_keys = array_filter(
$i18n_schema,
function ($item) {
return $item === 'string';
}
);
// Display the filtered i18n schema
print_r($string_keys);
Modify the i18n schema
This example demonstrates how to modify the i18n schema, such as adding a new key or changing the data type of an existing key.
// Get the i18n schema for block metadata
$i18n_schema = get_block_metadata_i18n_schema();
// Add a new key to the i18n schema
$i18n_schema['new_key'] = 'string';
// Change the data type of an existing key
if (array_key_exists('title', $i18n_schema)) {
$i18n_schema['title'] = 'array';
}
// Display the modified i18n schema
print_r($i18n_schema);