W3cubDocs

/WordPress

WP_Theme_JSON::get_blocks_metadata(): array

Returns the metadata for each block.

Description

Example:

{
  'core/paragraph': {
    'selector': 'p',
    'elements': {
      'link' => 'link selector',
      'etc'  => 'element selector'
    }
  },
  'core/heading': {
    'selector': 'h1',
    'elements': {}
  },
  'core/image': {
    'selector': '.wp-block-image',
    'duotone': 'img',
    'elements': {}
  }
}

Return

array Block metadata.

Source


	if ( isset( $new_theme_json['settings']['blocks'] ) && is_array( $new_theme_json['settings']['blocks'] ) ) {
		foreach ( $new_theme_json['settings']['blocks'] as &$block ) {
			if ( isset( $block['appearanceTools'] ) && ( true === $block['appearanceTools'] ) ) {
				static::do_opt_in_into_settings( $block );
			}
		}
	}

	return $new_theme_json;
}

/**
 * Enables some settings.
 *
 * @since 5.9.0
 *
 * @param array $context The context to which the settings belong.
 */
protected static function do_opt_in_into_settings( &$context ) {
	foreach ( static::APPEARANCE_TOOLS_OPT_INS as $path ) {
		/*
		 * Use "unset prop" as a marker instead of "null" because
		 * "null" can be a valid value for some props (e.g. blockGap).
		 */
		if ( 'unset prop' === _wp_array_get( $context, $path, 'unset prop' ) ) {
			_wp_array_set( $context, $path, true );
		}
	}

	unset( $context['appearanceTools'] );
}

/**
 * Sanitizes the input according to the schemas.
 *
 * @since 5.8.0
 * @since 5.9.0 Added the `$valid_block_names` and `$valid_element_name` parameters.
 * @since 6.3.0 Added the `$valid_variations` parameter.
 * @since 6.6.0 Updated schema to allow extended block style variations.
 *
 * @param array $input               Structure to sanitize.
 * @param array $valid_block_names   List of valid block names.
 * @param array $valid_element_names List of valid element names.
 * @param array $valid_variations    List of valid variations per block.
 * @return array The sanitized output.
 */
protected static function sanitize( $input, $valid_block_names, $valid_element_names, $valid_variations ) {

	$output = array();

Changelog

Version Description
6.3.0 Refactored and stabilized selectors API.
6.1.0 Added features key with block support feature level selectors.
5.9.0 Added duotone key with CSS selector.
5.8.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_theme_json/get_blocks_metadata