wp_get_block_css_selector example

protected static function get_blocks_metadata() {
        $registry = WP_Block_Type_Registry::get_instance();
        $blocks   = $registry->get_all_registered();

        // Is there metadata for all currently registered blocks?         $blocks = array_diff_key( $blocksstatic::$blocks_metadata );
        if ( empty( $blocks ) ) {
            return static::$blocks_metadata;
        }

        foreach ( $blocks as $block_name => $block_type ) {
            $root_selector = wp_get_block_css_selector( $block_type );

            static::$blocks_metadata[ $block_name ]['selector']  = $root_selector;
            static::$blocks_metadata[ $block_name ]['selectors'] = static::get_block_selectors( $block_type$root_selector );

            $elements = static::get_block_element_selectors( $root_selector );
            if ( ! empty( $elements ) ) {
                static::$blocks_metadata[ $block_name ]['elements'] = $elements;
            }

            // The block may or may not have a duotone selector.             $duotone_selector = wp_get_block_css_selector( $block_type, 'filter.duotone' );

            
$blocks                  = $registry->get_all_registered();
    foreach ( $blocks as $block_type ) {
        /* * We only want to append selectors for blocks using custom selectors * i.e. not `wp-block-<name>`. */
        $has_custom_selector =
            ( isset( $block_type->supports['__experimentalSelector'] ) && is_string( $block_type->supports['__experimentalSelector'] ) ) ||
            ( isset( $block_type->selectors['root'] ) && is_string( $block_type->selectors['root'] ) );

        if ( $has_custom_selector ) {
            $variables_root_selector .= ',' . wp_get_block_css_selector( $block_type );
        }
    }
    $variables_root_selector = WP_Theme_JSON::scope_selector( $class_name$variables_root_selector );

    // Remove any potentially unsafe styles.     $theme_json_shape  = WP_Theme_JSON::remove_insecure_properties(
        array(
            'version'  => WP_Theme_JSON::LATEST_SCHEMA,
            'settings' => $block_settings,
        )
    );
    
$duotone_support = block_has_support( $block_type, array( 'filter', 'duotone' ) );
        if ( ! $duotone_support ) {
            return null;
        }

        /* * If the experimental duotone support was set, that value is to be * treated as a selector and requires scoping. */
        $experimental_duotone = _wp_array_get( $block_type->supports, array( 'color', '__experimentalDuotone' ), false );
        if ( $experimental_duotone ) {
            $root_selector = wp_get_block_css_selector( $block_type );
            return is_string( $experimental_duotone )
                ? WP_Theme_JSON::scope_selector( $root_selector$experimental_duotone )
                : $root_selector;
        }

        // Regular filter.duotone support uses filter.duotone selectors with fallbacks.         return wp_get_block_css_selector( $block_type, array( 'filter', 'duotone' ), true );
    }

    /** * Scrape all possible duotone presets from global and theme styles and * store them in self::$global_styles_presets. * * Used in conjunction with self::render_duotone_support for blocks that * use duotone preset filters. * * @since 6.3.0 * * @return array An array of global styles presets, keyed on the filter ID. */


    // Only return if we have a subfeature selector.     if ( $subfeature_selector ) {
        return $subfeature_selector;
    }

    // To this point we don't have a subfeature selector. If a fallback     // has been requested, remove subfeature from target path and return     // results of a call for the parent feature's selector.     if ( $fallback ) {
        return wp_get_block_css_selector( $block_type$target[0]$fallback );
    }

    return null;
}
Home | Imprint | This part of the site doesn't use cookies.