WP_Duotone::render_duotone_support( string $block_content, array $block, WP_Block $wp_block ): string
- Since
- 6.3.0
- Source
wp-includes/class-wp-duotone.php:1088
Description
The hooks self::set_global_style_block_names and self::set_global_styles_presets must be called before this function.
Compatibility
- WordPress
- since 6.3.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$block_contentstring- Rendered block content.
$blockarray- Block object.
$wp_blockWP_Block- The block instance.
Return value
string- Filtered block content.
Performance profile
How much work a call to WP_Duotone::render_duotone_support() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Trivial
- Scaling
- Constant
- Instructions
- 6–83
- Plugin surface
- None
- Called by
- 1
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 139.
Nothing here hands control to plugin code.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()one call below WP_Duotone::render_duotone_support()
What one call costs · 21 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost WP_Duotone::render_duotone_support() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!$block | 6 | none |
$block | 13 | ::get_selector() |
$block && !isset($value) && !$global_styles_block_names | 24 | ::get_selector(), ::get_all_global_style_block_names() |
$block && !->next_tag() | 35–49 | ::get_selector(), ::get_all_global_style_block_names(), slug(), ->next_tag(), ->get_updated_html() |
$block && ->next_tag() | 38–52 | ::get_selector(), ::get_all_global_style_block_names(), slug(), ->next_tag(), ->add_class(), ->get_updated_html() |
$block && isset($value) && is_string($duotone_attr) && !is_array($duotone_attr) && !->next_tag() | 50–53 | ::get_selector(), ::get_all_global_style_block_names(), ::is_preset(), slug(), ->next_tag(), ->get_updated_html() |
$block && !isset($value) && $global_styles_block_names && !->next_tag() | 50 | ::get_selector(), ::get_all_global_style_block_names(), ::get_filter_id(), ::get_css_var(), ::enqueue_global_styles_preset(), slug(), ->next_tag(), ->get_updated_html() |
$block && isset($value) && is_string($duotone_attr) && !is_array($duotone_attr) && ->next_tag() | 53–56 | ::get_selector(), ::get_all_global_style_block_names(), ::is_preset(), slug(), ->next_tag(), ->add_class(), ->get_updated_html() |
$block && !isset($value) && $global_styles_block_names && ->next_tag() | 53 | ::get_selector(), ::get_all_global_style_block_names(), ::get_filter_id(), ::get_css_var(), ::enqueue_global_styles_preset(), slug(), ->next_tag(), ->add_class(), ->get_updated_html() |
$block && isset($value) && !is_string($duotone_attr) && !->next_tag() | 62–65 | ::get_selector(), ::get_all_global_style_block_names(), ::get_slug_from_attribute(), ::get_filter_id(), ::get_css_var(), ::enqueue_global_styles_preset(), slug(), ->next_tag(), ->get_updated_html() |
$block && isset($value) && !is_string($duotone_attr) && !->next_tag() | 64–67 | ::get_selector(), ::get_all_global_style_block_names(), sanitize_key(), wp_unique_id(), ::get_filter_id(), ::enqueue_block_css(), slug(), ->next_tag(), ->get_updated_html() |
$block && isset($value) && !is_string($duotone_attr) && ->next_tag() | 65–68 | ::get_selector(), ::get_all_global_style_block_names(), ::get_slug_from_attribute(), ::get_filter_id(), ::get_css_var(), ::enqueue_global_styles_preset(), slug(), ->next_tag(), ->add_class(), ->get_updated_html() |
9 further outcomes, up to 83 instructions
$block && isset($value) && is_string($duotone_attr) && !->next_tag() | 66–69 | ::get_selector(), ::get_all_global_style_block_names(), ::is_preset(), ::get_slug_from_attribute(), ::get_filter_id(), ::get_css_var(), ::enqueue_global_styles_preset(), slug(), ->next_tag(), ->get_updated_html() |
$block && isset($value) && !is_string($duotone_attr) && ->next_tag() | 67–70 | ::get_selector(), ::get_all_global_style_block_names(), sanitize_key(), wp_unique_id(), ::get_filter_id(), ::enqueue_block_css(), slug(), ->next_tag(), ->add_class(), ->get_updated_html() |
$block && isset($value) && is_string($duotone_attr) && !->next_tag() | 68–71 | ::get_selector(), ::get_all_global_style_block_names(), ::is_preset(), sanitize_key(), wp_unique_id(), ::get_filter_id(), ::enqueue_block_css(), slug(), ->next_tag(), ->get_updated_html() |
$block && isset($value) && is_string($duotone_attr) && ->next_tag() | 69–72 | ::get_selector(), ::get_all_global_style_block_names(), ::is_preset(), ::get_slug_from_attribute(), ::get_filter_id(), ::get_css_var(), ::enqueue_global_styles_preset(), slug(), ->next_tag(), ->add_class(), ->get_updated_html() |
$block && isset($value) && is_string($duotone_attr) && ->next_tag() | 71–74 | ::get_selector(), ::get_all_global_style_block_names(), ::is_preset(), sanitize_key(), wp_unique_id(), ::get_filter_id(), ::enqueue_block_css(), slug(), ->next_tag(), ->add_class(), ->get_updated_html() |
$block && isset($value) && !is_string($duotone_attr) && is_array($duotone_attr) && !->next_tag() | 73–76 | ::get_selector(), ::get_all_global_style_block_names(), sanitize_key(), wp_unique_id(), ::get_filter_id(), ::get_filter_url(), ::enqueue_custom_filter(), slug(), ->next_tag(), ->get_updated_html() |
$block && isset($value) && !is_string($duotone_attr) && is_array($duotone_attr) && ->next_tag() | 76–79 | ::get_selector(), ::get_all_global_style_block_names(), sanitize_key(), wp_unique_id(), ::get_filter_id(), ::get_filter_url(), ::enqueue_custom_filter(), slug(), ->next_tag(), ->add_class(), ->get_updated_html() |
$block && isset($value) && is_string($duotone_attr) && is_array($duotone_attr) && !->next_tag() | 77–80 | ::get_selector(), ::get_all_global_style_block_names(), ::is_preset(), sanitize_key(), wp_unique_id(), ::get_filter_id(), ::get_filter_url(), ::enqueue_custom_filter(), slug(), ->next_tag(), ->get_updated_html() |
$block && isset($value) && is_string($duotone_attr) && is_array($duotone_attr) && ->next_tag() | 80–83 | ::get_selector(), ::get_all_global_style_block_names(), ::is_preset(), sanitize_key(), wp_unique_id(), ::get_filter_id(), ::get_filter_url(), ::enqueue_custom_filter(), slug(), ->next_tag(), ->add_class(), ->get_updated_html() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 139 | 6–83 | 12 | |
| 8.5 | 139 | 6–83 | 12 | |
| 8.4 | 139 | 6–83 | 12 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 142 | 6–86 | 12 | |
| 8.2 | 142 | 6–86 | 12 | |
| 8.1 | 142 | 6–86 | 12 | |
| 7.4 | 142 | 6–86 | 12 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Uses · 13
- wp_unique_id()Gets unique ID.
- sanitize_key()Sanitizes a string key.
- WP_Duotone::get_selector()Get the CSS selector for a block type.
- WP_Duotone::get_all_global_style_block_names()Scrape all block names from global styles and store in self::$global_styles_block_names.
- WP_Duotone::is_preset()Checks if we have a valid duotone preset.
- WP_Duotone::get_slug_from_attribute()Takes the inline CSS duotone variable from a block and return the slug.
- WP_Duotone::get_filter_id()Get the ID of the duotone filter.
- WP_Duotone::get_css_var()Get the CSS variable for a duotone preset.
- WP_Duotone::enqueue_global_styles_preset()Enqueue preset assets for the page.
- WP_Duotone::enqueue_block_css()Enqueue a block CSS declaration for the page.
- WP_Duotone::get_filter_url()Get the URL for a duotone filter.
- WP_Duotone::enqueue_custom_filter()Enqueue custom filter assets for the page.
Show all 13
- WP_HTML_Tag_Processor::__construct()Constructor.
Used by · 1
- wp_render_duotone_support()Renders out the duotone stylesheet and SVG.
Source code
public static function render_duotone_support( $block_content, $block, $wp_block ) { if ( ! $block['blockName'] ) { return $block_content; } $duotone_selector = self::get_selector( $wp_block->block_type ); if ( ! $duotone_selector ) { return $block_content; } $global_styles_block_names = self::get_all_global_style_block_names(); // The block should have a duotone attribute or have duotone defined in its theme.json to be processed. $has_duotone_attribute = isset( $block['attrs']['style']['color']['duotone'] ); $has_global_styles_duotone = array_key_exists( $block['blockName'], $global_styles_block_names ); if ( ! $has_duotone_attribute && ! $has_global_styles_duotone ) { return $block_content; } // Generate the pieces needed for rendering a duotone to the page. if ( $has_duotone_attribute ) { /* * Possible values for duotone attribute: * 1. Array of colors - e.g. array('#000000', '#ffffff'). * 2. Variable for an existing Duotone preset - e.g. 'var:preset|duotone|blue-orange' or 'var(--wp--preset--duotone--blue-orange)'' * 3. A CSS string - e.g. 'unset' to remove globally applied duotone. */ $duotone_attr = $block['attrs']['style']['color']['duotone']; $is_preset = is_string( $duotone_attr ) && self::is_preset( $duotone_attr ); $is_css = is_string( $duotone_attr ) && ! $is_preset; $is_custom = is_array( $duotone_attr ); if ( $is_preset ) { $slug = self::get_slug_from_attribute( $duotone_attr ); // e.g. 'blue-orange'. $filter_id = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-blue-orange'. $filter_value = self::get_css_var( $slug ); // e.g. 'var(--wp--preset--duotone--blue-orange)'. // CSS custom property, SVG filter, and block CSS. self::enqueue_global_styles_preset( $filter_id, $duotone_selector, $filter_value ); } elseif ( $is_css ) { $slug = wp_unique_id( sanitize_key( $duotone_attr . '-' ) ); // e.g. 'unset-1'. $filter_id = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-unset-1'. $filter_value = $duotone_attr; // e.g. 'unset'. // Just block CSS. self::enqueue_block_css( $filter_id, $duotone_selector, $filter_value ); } elseif ( $is_custom ) { $slug = wp_unique_id( sanitize_key( implode( '-', $duotone_attr ) . '-' ) ); // e.g. '000000-ffffff-2'. $filter_id = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-000000-ffffff-2'. $filter_value = self::get_filter_url( $filter_id ); // e.g. 'url(#wp-duotone-filter-000000-ffffff-2)'. $filter_data = array( 'slug' => $slug, 'colors' => $duotone_attr, ); // SVG filter and block CSS. self::enqueue_custom_filter( $filter_id, $duotone_selector, $filter_value, $filter_data ); } } elseif ( $has_global_styles_duotone ) { $slug = $global_styles_block_names[ $block['blockName'] ]; // e.g. 'blue-orange'. $filter_id = self::get_filter_id( $slug ); // e.g. 'wp-duotone-filter-blue-orange'. $filter_value = self::get_css_var( $slug ); // e.g. 'var(--wp--preset--duotone--blue-orange)'. // CSS custom property, SVG filter, and block CSS. self::enqueue_global_styles_preset( $filter_id, $duotone_selector, $filter_value ); } // Like the layout hook, this assumes the hook only applies to blocks with a single wrapper. $tags = new WP_HTML_Tag_Processor( $block_content ); if ( $tags->next_tag() ) { $tags->add_class( $filter_id ); } return $tags->get_updated_html(); }Changelog
Introduced in 6.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/class-wp-duotone.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.