WP_Theme_JSON::get_blocks_metadata(): array

In this article

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( $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();

	if ( ! is_array( $input ) ) {
		return $output;
	}

Changelog

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

User Contributed Notes

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