wp/wp-includes/blocks/rss.php
changeset 21 48c4eec2b7e6
parent 19 3d72ae0968f4
child 22 8c2e4d02f4ef
equal deleted inserted replaced
20:7b1b88e27a20 21:48c4eec2b7e6
     5  * @package WordPress
     5  * @package WordPress
     6  */
     6  */
     7 
     7 
     8 /**
     8 /**
     9  * Renders the `core/rss` block on server.
     9  * Renders the `core/rss` block on server.
       
    10  *
       
    11  * @since 5.2.0
    10  *
    12  *
    11  * @param array $attributes The block attributes.
    13  * @param array $attributes The block attributes.
    12  *
    14  *
    13  * @return string Returns the block content with received rss items.
    15  * @return string Returns the block content with received rss items.
    14  */
    16  */
    18 	}
    20 	}
    19 
    21 
    20 	$rss = fetch_feed( $attributes['feedURL'] );
    22 	$rss = fetch_feed( $attributes['feedURL'] );
    21 
    23 
    22 	if ( is_wp_error( $rss ) ) {
    24 	if ( is_wp_error( $rss ) ) {
    23 		return '<div class="components-placeholder"><div class="notice notice-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . $rss->get_error_message() . '</div></div>';
    25 		return '<div class="components-placeholder"><div class="notice notice-error"><strong>' . __( 'RSS Error:' ) . '</strong> ' . esc_html( $rss->get_error_message() ) . '</div></div>';
    24 	}
    26 	}
    25 
    27 
    26 	if ( ! $rss->get_item_quantity() ) {
    28 	if ( ! $rss->get_item_quantity() ) {
    27 		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>';
    29 		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>';
    28 	}
    30 	}
    46 			$date = $item->get_date( 'U' );
    48 			$date = $item->get_date( 'U' );
    47 
    49 
    48 			if ( $date ) {
    50 			if ( $date ) {
    49 				$date = sprintf(
    51 				$date = sprintf(
    50 					'<time datetime="%1$s" class="wp-block-rss__item-publish-date">%2$s</time> ',
    52 					'<time datetime="%1$s" class="wp-block-rss__item-publish-date">%2$s</time> ',
    51 					date_i18n( get_option( 'c' ), $date ),
    53 					esc_attr( date_i18n( 'c', $date ) ),
    52 					date_i18n( get_option( 'date_format' ), $date )
    54 					esc_attr( date_i18n( get_option( 'date_format' ), $date ) )
    53 				);
    55 				);
    54 			}
    56 			}
    55 		}
    57 		}
    56 
    58 
    57 		$author = '';
    59 		$author = '';
   105 	return sprintf( '<ul %s>%s</ul>', $wrapper_attributes, $list_items );
   107 	return sprintf( '<ul %s>%s</ul>', $wrapper_attributes, $list_items );
   106 }
   108 }
   107 
   109 
   108 /**
   110 /**
   109  * Registers the `core/rss` block on server.
   111  * Registers the `core/rss` block on server.
       
   112  *
       
   113  * @since 5.2.0
   110  */
   114  */
   111 function register_block_core_rss() {
   115 function register_block_core_rss() {
   112 	register_block_type_from_metadata(
   116 	register_block_type_from_metadata(
   113 		__DIR__ . '/rss',
   117 		__DIR__ . '/rss',
   114 		array(
   118 		array(