get_styles_for_block example


    protected function get_block_classes( $style_nodes ) {
        $block_rules = '';

        foreach ( $style_nodes as $metadata ) {
            if ( null === $metadata['selector'] ) {
                continue;
            }
            $block_rules .= static::get_styles_for_block( $metadata );
        }

        return $block_rules;
    }

    /** * Gets the CSS layout rules for a particular block from theme.json layout definitions. * * @since 6.1.0 * @since 6.3.0 Reduced specificity for layout margin rules. * * @param array $block_metadata Metadata about the block to get styles for. * @return string Layout styles for the block. */


/** * Adds global style rules to the inline style for each block. * * @since 6.1.0 */
function wp_add_global_styles_for_blocks() {
    $tree        = WP_Theme_JSON_Resolver::get_merged_data();
    $block_nodes = $tree->get_styles_block_nodes();
    foreach ( $block_nodes as $metadata ) {
        $block_css = $tree->get_styles_for_block( $metadata );

        if ( ! wp_should_load_separate_core_block_assets() ) {
            wp_add_inline_style( 'global-styles', $block_css );
            continue;
        }

        $stylesheet_handle = 'global-styles';
        if ( isset( $metadata['name'] ) ) {
            /* * These block styles are added on block_render. * This hooks inline CSS to them so that they are loaded conditionally * based on whether or not the block is used on the page. */
Home | Imprint | This part of the site doesn't use cookies.