wp/wp-includes/blocks/rss.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    11  * @param array $attributes The block attributes.
    11  * @param array $attributes The block attributes.
    12  *
    12  *
    13  * @return string Returns the block content with received rss items.
    13  * @return string Returns the block content with received rss items.
    14  */
    14  */
    15 function render_block_core_rss( $attributes ) {
    15 function render_block_core_rss( $attributes ) {
       
    16 	if ( in_array( untrailingslashit( $attributes['feedURL'] ), array( site_url(), home_url() ), true ) ) {
       
    17 		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>';
       
    18 	}
       
    19 
    16 	$rss = fetch_feed( $attributes['feedURL'] );
    20 	$rss = fetch_feed( $attributes['feedURL'] );
    17 
    21 
    18 	if ( is_wp_error( $rss ) ) {
    22 	if ( is_wp_error( $rss ) ) {
    19 		return '<div class="components-placeholder"><div class="notice notice-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . $rss->get_error_message() . '</div></div>';
    23 		return '<div class="components-placeholder"><div class="notice notice-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . $rss->get_error_message() . '</div></div>';
    20 	}
    24 	}
    81 
    85 
    82 	$classnames = array();
    86 	$classnames = array();
    83 	if ( isset( $attributes['blockLayout'] ) && 'grid' === $attributes['blockLayout'] ) {
    87 	if ( isset( $attributes['blockLayout'] ) && 'grid' === $attributes['blockLayout'] ) {
    84 		$classnames[] = 'is-grid';
    88 		$classnames[] = 'is-grid';
    85 	}
    89 	}
    86 
       
    87 	if ( isset( $attributes['columns'] ) && 'grid' === $attributes['blockLayout'] ) {
    90 	if ( isset( $attributes['columns'] ) && 'grid' === $attributes['blockLayout'] ) {
    88 		$classnames[] = 'columns-' . $attributes['columns'];
    91 		$classnames[] = 'columns-' . $attributes['columns'];
    89 	}
    92 	}
       
    93 	if ( $attributes['displayDate'] ) {
       
    94 		$classnames[] = 'has-dates';
       
    95 	}
       
    96 	if ( $attributes['displayAuthor'] ) {
       
    97 		$classnames[] = 'has-authors';
       
    98 	}
       
    99 	if ( $attributes['displayExcerpt'] ) {
       
   100 		$classnames[] = 'has-excerpts';
       
   101 	}
       
   102 
    90 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) );
   103 	$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => implode( ' ', $classnames ) ) );
    91 
   104 
    92 	return sprintf( '<ul %s>%s</ul>', $wrapper_attributes, $list_items );
   105 	return sprintf( '<ul %s>%s</ul>', $wrapper_attributes, $list_items );
    93 }
   106 }
    94 
   107