render_block_core_social_link( Array $attributes, String $content, WP_Block $block ): string
- Since
- 5.4.0
- Source
wp-includes/blocks/social-link.php:19
core/social-link block on server.Compatibility
- WordPress
- since 5.4.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
$attributesArray- The block attributes.
$contentString- InnerBlocks content of the Block.
$blockWP_Block- Block object.
Return value
string- Rendered HTML of the referenced block.
Performance profile
How much work a call to render_block_core_social_link() 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
- 31–124
- Plugin surface
- None
- Called by
- 0
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 138.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()one call below render_block_core_social_link()
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 14 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_social_link() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 31–38 | none |
| always | 33–40 | block_core_social_link_get_name() |
!is_email() && $rel === "" | 94–108 | is_email(), parse_url(), block_core_social_link_get_icon(), block_core_social_link_get_color_classes(), block_core_social_link_get_color_styles(), class(), esc_url(), esc_html(), get_block_wrapper_attributes(), ->next_tag(), ->get_updated_html() |
!is_email() && $rel === "" | 96–110 | block_core_social_link_get_name(), is_email(), parse_url(), block_core_social_link_get_icon(), block_core_social_link_get_color_classes(), block_core_social_link_get_color_styles(), class(), esc_url(), esc_html(), get_block_wrapper_attributes(), ->next_tag(), ->get_updated_html() |
!is_email() && $rel !== "" | 99–113 | is_email(), parse_url(), block_core_social_link_get_icon(), block_core_social_link_get_color_classes(), block_core_social_link_get_color_styles(), class(), esc_url(), esc_html(), get_block_wrapper_attributes(), ->next_tag(), ->set_attribute(), ->get_updated_html() |
is_email() && $rel === "" | 99–113 | is_email(), antispambot(), parse_url(), block_core_social_link_get_icon(), block_core_social_link_get_color_classes(), block_core_social_link_get_color_styles(), class(), esc_url(), esc_html(), get_block_wrapper_attributes(), ->next_tag(), ->get_updated_html() |
!is_email() && $rel !== "" | 101–115 | block_core_social_link_get_name(), is_email(), parse_url(), block_core_social_link_get_icon(), block_core_social_link_get_color_classes(), block_core_social_link_get_color_styles(), class(), esc_url(), esc_html(), get_block_wrapper_attributes(), ->next_tag(), ->set_attribute(), ->get_updated_html() |
is_email() && $rel === "" | 101–115 | block_core_social_link_get_name(), is_email(), antispambot(), parse_url(), block_core_social_link_get_icon(), block_core_social_link_get_color_classes(), block_core_social_link_get_color_styles(), class(), esc_url(), esc_html(), get_block_wrapper_attributes(), ->next_tag(), ->get_updated_html() |
!is_email() | 103–117 | is_email(), parse_url(), block_core_social_link_get_icon(), block_core_social_link_get_color_classes(), block_core_social_link_get_color_styles(), class(), esc_url(), esc_html(), get_block_wrapper_attributes(), ->next_tag(), ->set_attribute(), ->set_attribute(), ->get_updated_html() |
is_email() && $rel !== "" | 104–118 | is_email(), antispambot(), parse_url(), block_core_social_link_get_icon(), block_core_social_link_get_color_classes(), block_core_social_link_get_color_styles(), class(), esc_url(), esc_html(), get_block_wrapper_attributes(), ->next_tag(), ->set_attribute(), ->get_updated_html() |
!is_email() | 105–119 | block_core_social_link_get_name(), is_email(), parse_url(), block_core_social_link_get_icon(), block_core_social_link_get_color_classes(), block_core_social_link_get_color_styles(), class(), esc_url(), esc_html(), get_block_wrapper_attributes(), ->next_tag(), ->set_attribute(), ->set_attribute(), ->get_updated_html() |
is_email() && $rel !== "" | 106–120 | block_core_social_link_get_name(), is_email(), antispambot(), parse_url(), block_core_social_link_get_icon(), block_core_social_link_get_color_classes(), block_core_social_link_get_color_styles(), class(), esc_url(), esc_html(), get_block_wrapper_attributes(), ->next_tag(), ->set_attribute(), ->get_updated_html() |
2 further outcomes, up to 124 instructions
is_email() | 108–122 | is_email(), antispambot(), parse_url(), block_core_social_link_get_icon(), block_core_social_link_get_color_classes(), block_core_social_link_get_color_styles(), class(), esc_url(), esc_html(), get_block_wrapper_attributes(), ->next_tag(), ->set_attribute(), ->set_attribute(), ->get_updated_html() |
is_email() | 110–124 | block_core_social_link_get_name(), is_email(), antispambot(), parse_url(), block_core_social_link_get_icon(), block_core_social_link_get_color_classes(), block_core_social_link_get_color_styles(), class(), esc_url(), esc_html(), get_block_wrapper_attributes(), ->next_tag(), ->set_attribute(), ->set_attribute(), ->get_updated_html() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 137 | 31–123 | 15 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 138 | 31–124 | 15 | |
| 8.4 | 138 | 31–124 | 15 | 13 fewer instructions than PHP 8.3 |
| 8.3 | 151 | 31–135 | 15 | |
| 8.2 | 151 | 31–135 | 15 | |
| 8.1 | 151 | 31–135 | 15 | 1 fewer instruction than PHP 7.4 |
| 7.4 | 152 | 31–136 | 15 |
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 · 11
- block_core_social_link_get_name()Returns the brand name for social link.
- is_email()Verifies that an email is valid.
- antispambot()Obscures email addresses in HTML to prevent spam bots from harvesting them.
- str_starts_with()Polyfill for `str_starts_with()` function added in PHP 8.0.
- block_core_social_link_get_icon()Returns the SVG for social link.
- get_block_wrapper_attributes()Generates a string of attributes by applying to the current block being rendered all of the features that the block supports.
- block_core_social_link_get_color_classes()Returns CSS classes for icon and icon background colors.
- block_core_social_link_get_color_styles()Returns CSS styles for icon and icon background colors.
- esc_url()Checks and cleans a URL.
- esc_html()Escaping for HTML blocks.
- WP_HTML_Tag_Processor::__construct()Constructor.
Source code
function render_block_core_social_link( $attributes, $content, $block ) { $open_in_new_tab = $block->context['openInNewTab'] ?? false; $text = ! empty( $attributes['label'] ) ? trim( $attributes['label'] ) : ''; $service = $attributes['service'] ?? 'Icon'; $url = $attributes['url'] ?? false; $text = $text ? $text : block_core_social_link_get_name( $service ); $rel = $attributes['rel'] ?? ''; $show_labels = array_key_exists( 'showLabels', $block->context ) ? $block->context['showLabels'] : false; // Don't render a link if there is no URL set. if ( ! $url ) { return ''; } /** * Prepend emails with `mailto:` if not set. * The `is_email` returns false for emails with schema. */ if ( is_email( $url ) ) { $url = 'mailto:' . antispambot( $url ); } /** * Prepend URL with https:// if it doesn't appear to contain a scheme * and it's not a relative link or a fragment. */ if ( ! parse_url( $url, PHP_URL_SCHEME ) && ! str_starts_with( $url, '//' ) && ! str_starts_with( $url, '#' ) ) { $url = 'https://' . $url; } $icon = block_core_social_link_get_icon( $service ); $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => 'wp-social-link wp-social-link-' . $service . block_core_social_link_get_color_classes( $block->context ), 'style' => block_core_social_link_get_color_styles( $block->context ), ) ); $link = '<li ' . $wrapper_attributes . '>'; $link .= '<a href="' . esc_url( $url ) . '" class="wp-block-social-link-anchor">'; $link .= $icon; $link .= '<span class="wp-block-social-link-label' . ( $show_labels ? '' : ' screen-reader-text' ) . '">' . esc_html( $text ) . '</span>'; $link .= '</a></li>'; $processor = new WP_HTML_Tag_Processor( $link ); $processor->next_tag( 'a' ); if ( $open_in_new_tab ) { $processor->set_attribute( 'rel', trim( $rel . ' noopener nofollow' ) ); $processor->set_attribute( 'target', '_blank' ); } elseif ( '' !== $rel ) { $processor->set_attribute( 'rel', trim( $rel ) ); } return $processor->get_updated_html();}Changelog
Introduced in 5.4.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/blocks/social-link.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.