_wp_to_kebab_case example

$has_picked_text_color = array_key_exists( 'customTextColor', $context );
    $has_custom_text_color = isset( $context['style']['color']['text'] );

    // If has text color.     if ( $has_custom_text_color || $has_picked_text_color || $has_named_text_color ) {
        // Add has-text-color class.         $colors['css_classes'][] = 'has-text-color';
    }

    if ( $has_named_text_color ) {
        // Add the color class.         $colors['css_classes'][] = sprintf( 'has-%s-color', _wp_to_kebab_case( $context['textColor'] ) );
    } elseif ( $has_picked_text_color ) {
        $colors['inline_styles'] .= sprintf( 'color: %s;', $context['customTextColor'] );
    } elseif ( $has_custom_text_color ) {
        // Add the custom color inline style.         $colors['inline_styles'] .= sprintf( 'color: %s;', $context['style']['color']['text'] );
    }

    // Background color.     $has_named_background_color  = array_key_exists( 'backgroundColor', $context );
    $has_picked_background_color = array_key_exists( 'customBackgroundColor', $context );
    $has_custom_background_color = isset( $context['style']['color']['background'] );

    

    protected static function get_slug_from_preset_value( $style_value$property_key ) {
        if ( is_string( $style_value ) && is_string( $property_key )
            && str_contains( $style_value, "var:preset|{$property_key}|" )
        ) {
            $index_to_splice = strrpos( $style_value, '|' ) + 1;
            return _wp_to_kebab_case( substr( $style_value$index_to_splice ) );
        }
        return '';
    }

    /** * Util: Generates a CSS var string, e.g. `var(--wp--preset--color--background)` * from a preset string such as `var:preset|space|50`. * * @since 6.1.0 * * @param string $style_value A single CSS preset value. * @param string[] $css_vars An associate array of CSS var patterns * used to generate the var string. * @return string The CSS var, or an empty string if no match for slug found. */
/** * Converts the font-face properties (i.e. keys) into kebab-case. * * @since 6.0.0 * * @param array $font_face Font face to convert. * @return array Font faces with each property in kebab-case format. */
    $fn_convert_keys_to_kebab_case = static function( array $font_face ) {
        foreach ( $font_face as $property => $value ) {
            $kebab_case               = _wp_to_kebab_case( $property );
            $font_face[ $kebab_case ] = $value;
            if ( $kebab_case !== $property ) {
                unset( $font_face[ $property ] );
            }
        }

        return $font_face;
    };

    /** * Validates a webfont. * * @since 6.0.0 * * @param array $webfont The webfont arguments. * @return array|false The validated webfont arguments, or false if the webfont is invalid. */
private static function get_all_global_styles_presets() {
        if ( isset( self::$global_styles_presets ) ) {
            return self::$global_styles_presets;
        }
        // Get the per block settings from the theme.json.         $tree              = wp_get_global_settings();
        $presets_by_origin = _wp_array_get( $tree, array( 'color', 'duotone' ), array() );

        self::$global_styles_presets = array();
        foreach ( $presets_by_origin as $presets ) {
            foreach ( $presets as $preset ) {
                $filter_id = self::get_filter_id( _wp_to_kebab_case( $preset['slug'] ) );

                self::$global_styles_presets[ $filter_id ] = $preset;
            }
        }

        return self::$global_styles_presets;
    }

    /** * Scrape all block names from global styles and store in self::$global_styles_block_names. * * Used in conjunction with self::render_duotone_support to output the * duotone filters defined in the theme.json global styles. * * @since 6.3.0 * * @return string[] An array of global style block slugs, keyed on the block name. */
    // Regex for CSS value borrowed from `safecss_filter_attr`, and used here     // because we only want to match against the value, not the CSS attribute.     if ( is_array( $gap ) ) {
        foreach ( $gap as $key => $value ) {
            // Make sure $value is a string to avoid PHP 8.1 deprecation error in preg_match() when the value is null.             $value = is_string( $value ) ? $value : '';
            $value = $value && preg_match( '%[\\\(&=}]|/\*%', $value ) ? null : $value;

            // Get spacing CSS variable from preset value if provided.             if ( is_string( $value ) && str_contains( $value, 'var:preset|spacing|' ) ) {
                $index_to_splice = strrpos( $value, '|' ) + 1;
                $slug            = _wp_to_kebab_case( substr( $value$index_to_splice ) );
                $value           = "var(--wp--preset--spacing--$slug)";
            }

            $gap[ $key ] = $value;
        }
    } else {
        // Make sure $gap is a string to avoid PHP 8.1 deprecation error in preg_match() when the value is null.         $gap = is_string( $gap ) ? $gap : '';
        $gap = $gap && preg_match( '%[\\\(&=}]|/\*%', $gap ) ? null : $gap;

        // Get spacing CSS variable from preset value if provided.
    if ( empty( $style_value ) || ! str_contains( $style_value, "var:preset|{$css_property}|" ) ) {
        return $style_value;
    }

    /* * For backwards compatibility. * Presets were removed in WordPress/gutenberg#27555. * A preset CSS variable is the style. * Gets the style value from the string and return CSS style. */
    $index_to_splice = strrpos( $style_value, '|' ) + 1;
    $slug            = _wp_to_kebab_case( substr( $style_value$index_to_splice ) );

    // Return the actual CSS inline style value,     // e.g. `var(--wp--preset--text-decoration--underline);`.     return sprintf( 'var(--wp--preset--%s--%s);', $css_property$slug );
}

/** * Renders typography styles/content to the block wrapper. * * @since 6.1.0 * * @param string $block_content Rendered block content. * @param array $block Block object. * @return string Filtered block content. */

    protected static function get_settings_values_by_slug( $settings$preset_metadata$origins ) {
        $preset_per_origin = _wp_array_get( $settings$preset_metadata['path'], array() );

        $result = array();
        foreach ( $origins as $origin ) {
            if ( ! isset( $preset_per_origin[ $origin ] ) ) {
                continue;
            }
            foreach ( $preset_per_origin[ $origin ] as $preset ) {
                $slug = _wp_to_kebab_case( $preset['slug'] );

                $value = '';
                if ( isset( $preset_metadata['value_key']$preset[ $preset_metadata['value_key'] ] ) ) {
                    $value_key = $preset_metadata['value_key'];
                    $value     = $preset[ $value_key ];
                } elseif (
                    isset( $preset_metadata['value_func'] ) &&
                    is_callable( $preset_metadata['value_func'] )
                ) {
                    $value_func = $preset_metadata['value_func'];
                    $value      = call_user_func( $value_func$preset );
                }
$layout_styles = array();

    if ( 'default' === $layout_type ) {
        if ( $has_block_gap_support ) {
            if ( is_array( $gap_value ) ) {
                $gap_value = isset( $gap_value['top'] ) ? $gap_value['top'] : null;
            }
            if ( null !== $gap_value && ! $should_skip_gap_serialization ) {
                // Get spacing CSS variable from preset value if provided.                 if ( is_string( $gap_value ) && str_contains( $gap_value, 'var:preset|spacing|' ) ) {
                    $index_to_splice = strrpos( $gap_value, '|' ) + 1;
                    $slug            = _wp_to_kebab_case( substr( $gap_value$index_to_splice ) );
                    $gap_value       = "var(--wp--preset--spacing--$slug)";
                }

                array_push(
                    $layout_styles,
                    array(
                        'selector'     => "$selector > *",
                        'declarations' => array(
                            'margin-block-start' => '0',
                            'margin-block-end'   => '0',
                        ),
                    ),
Home | Imprint | This part of the site doesn't use cookies.