Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.
WP_Duotone::get_filter_svg( string $filter_id, array $colors ): string
Gets the SVG for the duotone filter definition.
Description
Whitespace is removed when SCRIPT_DEBUG is not enabled.
Parameters
-
$filter_id
string Required -
The ID of the filter.
-
$colors
array Required -
An array of color strings.
Return
string An SVG with a duotone filter definition.
Source
File: wp-includes/class-wp-duotone.php
.
View all references
private static function get_filter_svg( $filter_id, $colors ) {
$duotone_values = array(
'r' => array(),
'g' => array(),
'b' => array(),
'a' => array(),
);
foreach ( $colors as $color_str ) {
$color = self::colord_parse( $color_str );
if ( null === $color ) {
$error_message = sprintf(
/* translators: %s: duotone colors */
__( '"%s" in theme.json settings.color.duotone is not a hex or rgb string.' ),
$color_str
);
_doing_it_wrong( __METHOD__, $error_message, '6.3.0' );
} else {
$duotone_values['r'][] = $color['r'] / 255;
$duotone_values['g'][] = $color['g'] / 255;
$duotone_values['b'][] = $color['b'] / 255;
$duotone_values['a'][] = $color['a'];
}
}
ob_start();
?>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 0 0"
width="0"
height="0"
focusable="false"
role="none"
style="visibility: hidden; position: absolute; left: -9999px; overflow: hidden;"
>
<defs>
<filter id="<?php echo esc_attr( $filter_id ); ?>">
<feColorMatrix
color-interpolation-filters="sRGB"
type="matrix"
values="
.299 .587 .114 0 0
.299 .587 .114 0 0
.299 .587 .114 0 0
.299 .587 .114 0 0
"
/>
<feComponentTransfer color-interpolation-filters="sRGB" >
<feFuncR type="table" tableValues="<?php echo esc_attr( implode( ' ', $duotone_values['r'] ) ); ?>" />
<feFuncG type="table" tableValues="<?php echo esc_attr( implode( ' ', $duotone_values['g'] ) ); ?>" />
<feFuncB type="table" tableValues="<?php echo esc_attr( implode( ' ', $duotone_values['b'] ) ); ?>" />
<feFuncA type="table" tableValues="<?php echo esc_attr( implode( ' ', $duotone_values['a'] ) ); ?>" />
</feComponentTransfer>
<feComposite in2="SourceGraphic" operator="in" />
</filter>
</defs>
</svg>
<?php
$svg = ob_get_clean();
if ( ! SCRIPT_DEBUG ) {
// Clean up the whitespace.
$svg = preg_replace( "/[\r\n\t ]+/", ' ', $svg );
$svg = str_replace( '> <', '><', $svg );
$svg = trim( $svg );
}
return $svg;
}
Changelog
Version | Description |
---|---|
6.3.0 | Introduced. |