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

			continue;
		}

		$result = static::remove_keys_not_in_schema( $input[ $subtree ], $schema[ $subtree ] );

		if ( empty( $result ) ) {
			unset( $output[ $subtree ] );
		} else {
			$output[ $subtree ] = static::resolve_custom_css_format( $result );
		}
	}

	return $output;
}

/**
 * Appends a sub-selector to an existing one.
 *
 * Given the compounded $selector "h1, h2, h3"
 * and the $to_append selector ".some-class" the result will be
 * "h1.some-class, h2.some-class, h3.some-class".
 *
 * @since 5.8.0
 * @since 6.1.0 Added append position.
 * @since 6.3.0 Removed append position parameter.
 *
 * @param string $selector  Original selector.
 * @param string $to_append Selector to append.
 * @return string The new selector.
 */
protected static function append_to_selector( $selector, $to_append ) {
	if ( ! str_contains( $selector, ',' ) ) {
		return $selector . $to_append;
	}
	$new_selectors = array();
	$selectors     = explode( ',', $selector );
	foreach ( $selectors as $sel ) {
		$new_selectors[] = $sel . $to_append;
	}
	return implode( ',', $new_selectors );
}

/**
 * Prepends a sub-selector to an existing one.
 *
 * Given the compounded $selector "h1, h2, h3"
 * and the $to_prepend selector ".some-class " the result will be
 * ".some-class h1, .some-class  h2, .some-class  h3".
 *
 * @since 6.3.0
 *

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.