Edit File by line
/home/barbar84/www/wp-inclu.../blocks
File: rss.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Server-side rendering of the `core/rss` block.
[2] Fix | Delete
*
[3] Fix | Delete
* @package WordPress
[4] Fix | Delete
*/
[5] Fix | Delete
[6] Fix | Delete
/**
[7] Fix | Delete
* Renders the `core/rss` block on server.
[8] Fix | Delete
*
[9] Fix | Delete
* @param array $attributes The block attributes.
[10] Fix | Delete
*
[11] Fix | Delete
* @return string Returns the block content with received rss items.
[12] Fix | Delete
*/
[13] Fix | Delete
function render_block_core_rss( $attributes ) {
[14] Fix | Delete
$rss = fetch_feed( $attributes['feedURL'] );
[15] Fix | Delete
[16] Fix | Delete
if ( is_wp_error( $rss ) ) {
[17] Fix | Delete
return '<div class="components-placeholder"><div class="notice notice-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $rss->get_error_message() ) . '</div></div>';
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
if ( ! $rss->get_item_quantity() ) {
[21] Fix | Delete
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>';
[22] Fix | Delete
}
[23] Fix | Delete
[24] Fix | Delete
$rss_items = $rss->get_items( 0, $attributes['itemsToShow'] );
[25] Fix | Delete
$list_items = '';
[26] Fix | Delete
foreach ( $rss_items as $item ) {
[27] Fix | Delete
$title = esc_html( trim( strip_tags( $item->get_title() ) ) );
[28] Fix | Delete
if ( empty( $title ) ) {
[29] Fix | Delete
$title = __( '(no title)' );
[30] Fix | Delete
}
[31] Fix | Delete
$link = $item->get_link();
[32] Fix | Delete
$link = esc_url( $link );
[33] Fix | Delete
if ( $link ) {
[34] Fix | Delete
$title = "<a href='{$link}'>{$title}</a>";
[35] Fix | Delete
}
[36] Fix | Delete
$title = "<div class='wp-block-rss__item-title'>{$title}</div>";
[37] Fix | Delete
[38] Fix | Delete
$date = '';
[39] Fix | Delete
if ( $attributes['displayDate'] ) {
[40] Fix | Delete
$date = $item->get_date( 'U' );
[41] Fix | Delete
[42] Fix | Delete
if ( $date ) {
[43] Fix | Delete
$date = sprintf(
[44] Fix | Delete
'<time datetime="%1$s" class="wp-block-rss__item-publish-date">%2$s</time> ',
[45] Fix | Delete
esc_attr( date_i18n( get_option( 'c' ), $date ) ),
[46] Fix | Delete
esc_attr( date_i18n( get_option( 'date_format' ), $date ) )
[47] Fix | Delete
);
[48] Fix | Delete
}
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
$author = '';
[52] Fix | Delete
if ( $attributes['displayAuthor'] ) {
[53] Fix | Delete
$author = $item->get_author();
[54] Fix | Delete
if ( is_object( $author ) ) {
[55] Fix | Delete
$author = $author->get_name();
[56] Fix | Delete
$author = '<span class="wp-block-rss__item-author">' . sprintf(
[57] Fix | Delete
/* translators: %s: the author. */
[58] Fix | Delete
__( 'by %s' ),
[59] Fix | Delete
esc_html( strip_tags( $author ) )
[60] Fix | Delete
) . '</span>';
[61] Fix | Delete
}
[62] Fix | Delete
}
[63] Fix | Delete
[64] Fix | Delete
$excerpt = '';
[65] Fix | Delete
if ( $attributes['displayExcerpt'] ) {
[66] Fix | Delete
$excerpt = html_entity_decode( $item->get_description(), ENT_QUOTES, get_option( 'blog_charset' ) );
[67] Fix | Delete
$excerpt = esc_attr( wp_trim_words( $excerpt, $attributes['excerptLength'], ' [&hellip;]' ) );
[68] Fix | Delete
[69] Fix | Delete
// Change existing [...] to [&hellip;].
[70] Fix | Delete
if ( '[...]' === substr( $excerpt, -5 ) ) {
[71] Fix | Delete
$excerpt = substr( $excerpt, 0, -5 ) . '[&hellip;]';
[72] Fix | Delete
}
[73] Fix | Delete
[74] Fix | Delete
$excerpt = '<div class="wp-block-rss__item-excerpt">' . esc_html( $excerpt ) . '</div>';
[75] Fix | Delete
}
[76] Fix | Delete
[77] Fix | Delete
$list_items .= "<li class='wp-block-rss__item'>{$title}{$date}{$author}{$excerpt}</li>";
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
$classnames = array();
[81] Fix | Delete
if ( isset( $attributes['blockLayout'] ) && 'grid' === $attributes['blockLayout'] ) {
[82] Fix | Delete
$classnames[] = 'is-grid';
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
if ( isset( $attributes['columns'] ) && 'grid' === $attributes['blockLayout'] ) {
[86] Fix | Delete
$classnames[] = 'columns-' . $attributes['columns'];
[87] Fix | Delete
}
[88] Fix | Delete
$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) );
[89] Fix | Delete
[90] Fix | Delete
return sprintf( '<ul %s>%s</ul>', $wrapper_attributes, $list_items );
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
/**
[94] Fix | Delete
* Registers the `core/rss` block on server.
[95] Fix | Delete
*/
[96] Fix | Delete
function register_block_core_rss() {
[97] Fix | Delete
register_block_type_from_metadata(
[98] Fix | Delete
__DIR__ . '/rss',
[99] Fix | Delete
array(
[100] Fix | Delete
'render_callback' => 'render_block_core_rss',
[101] Fix | Delete
)
[102] Fix | Delete
);
[103] Fix | Delete
}
[104] Fix | Delete
add_action( 'init', 'register_block_core_rss' );
[105] Fix | Delete
[106] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function