π File Manager
π Edit File: rss.php
<?php /** * Server-side rendering of the `core/rss` block. * * @package WordPress */ /** * Renders the `core/rss` block on server. * * @since 5.2.0 * * @param array $attributes The block attributes. * * @return string Returns the block content with received rss items. */ 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 = ''; foreach ( $rss_items as $item ) { $title = esc_html( trim( strip_tags( $item->get_title() ) ) ); if ( empty( $title ) ) { $title = __( '(no title)' ); } $link = $item->get_link(); $link = esc_url( $link ); if ( $link ) { $title = "<a href='{$link}'>{$title}</a>"; } $title = "<div class='wp-block-rss__item-title'>{$title}</div>"; $date = ''; if ( $attributes['displayDate'] ) { $date = $item->get_date( 'U' ); if ( $date ) { $date = sprintf( '<time datetime="%1$s" class="wp-block-rss__item-publish-date">%2$s</time> ', esc_attr( date_i18n( 'c', $date ) ), esc_attr( date_i18n( get_option( 'date_format' ), $date ) ) ); } } $author = ''; if ( $attributes['displayAuthor'] ) { $author = $item->get_author(); if ( is_object( $author ) ) { $author = $author->get_name(); $author = '<span class="wp-block-rss__item-author">' . sprintf( /* translators: byline. %s: author. */ __( 'by %s' ), esc_html( strip_tags( $author ) ) ) . '</span>'; } } $excerpt = ''; if ( $attributes['displayExcerpt'] ) { $excerpt = html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) ); $excerpt = esc_attr( wp_trim_words( $excerpt, $attributes['excerptLength'], ' […]' ) ); // Change existing [...] to […]. if ( '[...]' === substr( $excerpt, -5 ) ) { $excerpt = substr( $excerpt, 0, -5 ) . '[…]'; } $excerpt = '<div class="wp-block-rss__item-excerpt">' . esc_html( $excerpt ) . '</div>'; } $list_items .= "<li class='wp-block-rss__item'>{$title}{$date}{$author}{$excerpt}</li>"; } $classnames = array(); if ( isset( $attributes['blockLayout'] ) && 'grid' === $attributes['blockLayout'] ) { $classnames[] = 'is-grid'; } if ( isset( $attributes['columns'] ) && 'grid' === $attributes['blockLayout'] ) { $classnames[] = 'columns-' . $attributes['columns']; } if ( $attributes['displayDate'] ) { $classnames[] = 'has-dates'; } if ( $attributes['displayAuthor'] ) { $classnames[] = 'has-authors'; } if ( $attributes['displayExcerpt'] ) { $classnames[] = 'has-excerpts'; } $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) ); return sprintf( '<ul %s>%s</ul>', $wrapper_attributes, $list_items ); } /** * Registers the `core/rss` block on server. * * @since 5.2.0 */ function register_block_core_rss() { register_block_type_from_metadata( __DIR__ . '/rss', array( 'render_callback' => 'render_block_core_rss', ) ); } add_action( 'init', 'register_block_core_rss' );
Cancel
Type
Item Name
Actions
π
..
π
archives
βοΈ
π
audio
βοΈ
π
avatar
βοΈ
π
block
βοΈ
π
button
βοΈ
π
buttons
βοΈ
π
calendar
βοΈ
π
categories
βοΈ
π
code
βοΈ
π
column
βοΈ
π
columns
βοΈ
π
comment-author-name
βοΈ
π
comment-content
βοΈ
π
comment-date
βοΈ
π
comment-edit-link
βοΈ
π
comment-reply-link
βοΈ
π
comment-template
βοΈ
π
comments
βοΈ
π
comments-pagination
βοΈ
π
comments-pagination-next
βοΈ
π
comments-pagination-numbers
βοΈ
π
comments-pagination-previous
βοΈ
π
comments-title
βοΈ
π
cover
βοΈ
π
details
βοΈ
π
embed
βοΈ
π
file
βοΈ
π
footnotes
βοΈ
π
freeform
βοΈ
π
gallery
βοΈ
π
group
βοΈ
π
heading
βοΈ
π
home-link
βοΈ
π
html
βοΈ
π
image
βοΈ
π
latest-comments
βοΈ
π
latest-posts
βοΈ
π
legacy-widget
βοΈ
π
list
βοΈ
π
list-item
βοΈ
π
loginout
βοΈ
π
media-text
βοΈ
π
missing
βοΈ
π
more
βοΈ
π
navigation
βοΈ
π
navigation-link
βοΈ
π
navigation-submenu
βοΈ
π
nextpage
βοΈ
π
page-list
βοΈ
π
page-list-item
βοΈ
π
paragraph
βοΈ
π
pattern
βοΈ
π
post-author
βοΈ
π
post-author-biography
βοΈ
π
post-author-name
βοΈ
π
post-comments-form
βοΈ
π
post-content
βοΈ
π
post-date
βοΈ
π
post-excerpt
βοΈ
π
post-featured-image
βοΈ
π
post-navigation-link
βοΈ
π
post-template
βοΈ
π
post-terms
βοΈ
π
post-title
βοΈ
π
preformatted
βοΈ
π
pullquote
βοΈ
π
query
βοΈ
π
query-no-results
βοΈ
π
query-pagination
βοΈ
π
query-pagination-next
βοΈ
π
query-pagination-numbers
βοΈ
π
query-pagination-previous
βοΈ
π
query-title
βοΈ
π
quote
βοΈ
π
read-more
βοΈ
π
rss
βοΈ
π
search
βοΈ
π
separator
βοΈ
π
shortcode
βοΈ
π
site-logo
βοΈ
π
site-tagline
βοΈ
π
site-title
βοΈ
π
social-link
βοΈ
π
social-links
βοΈ
π
spacer
βοΈ
π
table
βοΈ
π
tag-cloud
βοΈ
π
template-part
βοΈ
π
term-description
βοΈ
π
text-columns
βοΈ
π
verse
βοΈ
π
video
βοΈ
π
widget-group
βοΈ
π
archives.php
βοΈ
π
π
avatar.php
βοΈ
π
π
block.php
βοΈ
π
π
blocks-json.php
βοΈ
π
π
button.php
βοΈ
π
π
calendar.php
βοΈ
π
π
categories.php
βοΈ
π
π
comment-author-name.php
βοΈ
π
π
comment-content.php
βοΈ
π
π
comment-date.php
βοΈ
π
π
comment-edit-link.php
βοΈ
π
π
comment-reply-link.php
βοΈ
π
π
comment-template.php
βοΈ
π
π
comments-pagination-next.php
βοΈ
π
π
comments-pagination-numbers.php
βοΈ
π
π
comments-pagination-previous.php
βοΈ
π
π
comments-pagination.php
βοΈ
π
π
comments-title.php
βοΈ
π
π
comments.php
βοΈ
π
π
cover.php
βοΈ
π
π
file.php
βοΈ
π
π
footnotes.php
βοΈ
π
π
gallery.php
βοΈ
π
π
heading.php
βοΈ
π
π
home-link.php
βοΈ
π
π
image.php
βοΈ
π
π
index.php
βοΈ
π
π
latest-comments.php
βοΈ
π
π
latest-posts.php
βοΈ
π
π
legacy-widget.php
βοΈ
π
π
list.php
βοΈ
π
π
loginout.php
βοΈ
π
π
media-text.php
βοΈ
π
π
navigation-link.php
βοΈ
π
π
navigation-submenu.php
βοΈ
π
π
navigation.php
βοΈ
π
π
page-list-item.php
βοΈ
π
π
page-list.php
βοΈ
π
π
pattern.php
βοΈ
π
π
post-author-biography.php
βοΈ
π
π
post-author-name.php
βοΈ
π
π
post-author.php
βοΈ
π
π
post-comments-form.php
βοΈ
π
π
post-content.php
βοΈ
π
π
post-date.php
βοΈ
π
π
post-excerpt.php
βοΈ
π
π
post-featured-image.php
βοΈ
π
π
post-navigation-link.php
βοΈ
π
π
post-template.php
βοΈ
π
π
post-terms.php
βοΈ
π
π
post-title.php
βοΈ
π
π
query-no-results.php
βοΈ
π
π
query-pagination-next.php
βοΈ
π
π
query-pagination-numbers.php
βοΈ
π
π
query-pagination-previous.php
βοΈ
π
π
query-pagination.php
βοΈ
π
π
query-title.php
βοΈ
π
π
query.php
βοΈ
π
π
read-more.php
βοΈ
π
π
require-dynamic-blocks.php
βοΈ
π
π
require-static-blocks.php
βοΈ
π
π
rss.php
βοΈ
π
π
search.php
βοΈ
π
π
shortcode.php
βοΈ
π
π
site-logo.php
βοΈ
π
π
site-tagline.php
βοΈ
π
π
site-title.php
βοΈ
π
π
social-link.php
βοΈ
π
π
tag-cloud.php
βοΈ
π
π
template-part.php
βοΈ
π
π
term-description.php
βοΈ
π
π
widget-group.php
βοΈ
π