render_block_core_rss( array $attributes ): string
- Since
- 5.2.0
- Source
wp-includes/blocks/rss.php:17
core/rss block on server.Compatibility
- WordPress
- since 5.2.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.
Return value
string- Returns the block content with received rss items.
Performance profile
How much work a call to render_block_core_rss() 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
- Heavy
- Scaling
- Scales with input
- Instructions
- 21–98
- Plugin surface
- None
- Called by
- 0
Reads stored settings via get_option(), cached per request but not free on a cold cache.
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 283.
Nothing here hands control to plugin code.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- optionoption read or write
get_option()called directly - hookthird-party callbacks
apply_filters()one call below render_block_core_rss() - cacheobject cache
wp_cache_get()one call below render_block_core_rss() - serializeserialisation
maybe_unserialize()one call below render_block_core_rss()
Further down the call graph this can also reach 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 · 5 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_rss() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 21 | untrailingslashit(), site_url(), home_url(), __() |
!is_wp_error() && !->get_item_quantity() | 34 | untrailingslashit(), site_url(), home_url(), fetch_feed(), is_wp_error(), ->get_item_quantity(), __() |
is_wp_error() | 38 | untrailingslashit(), site_url(), home_url(), fetch_feed(), is_wp_error(), __(), ->get_error_message(), esc_html() |
!is_wp_error() && ->get_item_quantity() && $rel === "" | 71–92 | untrailingslashit(), site_url(), home_url(), fetch_feed(), is_wp_error(), ->get_item_quantity(), ->get_items(), class() |
!is_wp_error() && ->get_item_quantity() && $rel !== "" | 77–98 | untrailingslashit(), site_url(), home_url(), fetch_feed(), is_wp_error(), ->get_item_quantity(), ->get_items(), esc_attr(), class() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 283 | 21–98 | 25 | |
| 8.5 | 283 | 21–98 | 25 | |
| 8.4 | 283 | 21–98 | 25 | 14 fewer instructions than PHP 8.3 |
| 8.3 | 297 | 24–107 | 25 | |
| 8.2 | 297 | 24–107 | 25 | |
| 8.1 | 297 | 24–107 | 25 | |
| 7.4 | 297 | 24–107 | 25 |
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 · 14
- untrailingslashit()Removes trailing forward slashes and backslashes if they exist.
- site_url()Retrieves the URL for the current site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible.
- home_url()Retrieves the URL for the current site where the front end is accessible.
- __()Retrieves the translation of $text.
- fetch_feed()Builds SimplePie object based on RSS or Atom feed from URL.
- is_wp_error()Checks whether the given variable is a WordPress Error.
- esc_html()Escaping for HTML blocks.
- esc_attr()Escaping for HTML attributes.
- esc_url()Checks and cleans a URL.
- get_option()Retrieves an option value based on an option name.
- date_i18n()Retrieves the date in localized format, based on a sum of Unix timestamp and timezone offset in seconds.
- wp_trim_words()Trims text to a certain number of words.
Show all 14
- str_ends_with()Polyfill for `str_ends_with()` function added in PHP 8.0.
- 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.
Source code
function render_block_core_rss( $attributes ) { if ( in_array( untrailingslashit( $attributes['feedURL'] ), array( site_url(), home_url() ), true ) ) { return '<div class="components-placeholder"><div class="notice notice-error">' . __( 'Adding an RSS feed to this site’s homepage is not supported, as it could lead to a loop that slows down your site. Try using another block, like the <strong>Latest Posts</strong> block, to list posts from the site.' ) . '</div></div>'; } $rss = fetch_feed( $attributes['feedURL'] ); if ( is_wp_error( $rss ) ) { return '<div class="components-placeholder"><div class="notice notice-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $rss->get_error_message() ) . '</div></div>'; } if ( ! $rss->get_item_quantity() ) { return '<div class="components-placeholder"><div class="notice notice-error">' . __( 'An error has occurred, which probably means the feed is down. Try again later.' ) . '</div></div>'; } $rss_items = $rss->get_items( 0, $attributes['itemsToShow'] ); $list_items = ''; $open_in_new_tab = ! empty( $attributes['openInNewTab'] ); $rel = ! empty( $attributes['rel'] ) ? trim( $attributes['rel'] ) : ''; $link_attributes = ''; if ( $open_in_new_tab ) { $link_attributes .= ' target="_blank"'; } if ( '' !== $rel ) { $link_attributes .= ' rel="' . esc_attr( $rel ) . '"'; } foreach ( $rss_items as $item ) { $title = esc_html( trim( strip_tags( html_entity_decode( $item->get_title() ) ) ) ); if ( empty( $title ) ) { $title = __( '(no title)' ); } $link = $item->get_link(); $link = esc_url( $link ); if ( $link ) { $title = "<a href='{$link}'{$link_attributes}>{$title}</a>"; } $title = "<div class='wp-block-rss__item-title'>{$title}</div>"; $date_markup = ''; if ( ! empty( $attributes['displayDate'] ) ) { $timestamp = $item->get_date( 'U' ); if ( $timestamp ) { $gmt_offset = get_option( 'gmt_offset' ); $timestamp += (int) ( (float) $gmt_offset * HOUR_IN_SECONDS ); $date_markup = sprintf( '<time datetime="%1$s" class="wp-block-rss__item-publish-date">%2$s</time> ', esc_attr( date_i18n( 'c', $timestamp ) ), esc_html( date_i18n( get_option( 'date_format' ), $timestamp ) ) ); } } $author = ''; if ( $attributes['displayAuthor'] ) { $author = $item->get_author(); if ( is_object( $author ) ) { $author = $author->get_name(); if ( ! empty( $author ) ) { $author = '<span class="wp-block-rss__item-author">' . sprintf( /* translators: byline. %s: author. */ __( 'by %s' ), esc_html( strip_tags( $author ) ) ) . '</span>'; } } } $excerpt = ''; $description = $item->get_description(); if ( $attributes['displayExcerpt'] && ! empty( $description ) ) { $excerpt = html_entity_decode( $description, ENT_QUOTES, get_option( 'blog_charset' ) );Changelog
Introduced in 5.2.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/rss.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.