: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
* Displays the atom enclosure for the current post.
* Uses the global $post to check whether the post requires a password and if
* the user has the password for the post. If not then it will return before
* Also uses the function get_post_custom() to get the post's 'enclosure'
* metadata field and parses the value to display the enclosure(s). The
* enclosure(s) consist of link HTML tag(s) with a URI and other attributes.
function atom_enclosure() {
if ( post_password_required() ) {
foreach ( (array) get_post_custom() as $key => $val ) {
if ( 'enclosure' === $key ) {
foreach ( (array) $val as $enc ) {
$enclosure = explode( "\n", $enc );
$mimes = get_allowed_mime_types();
if ( isset( $enclosure[0] ) && is_string( $enclosure[0] ) ) {
$url = trim( $enclosure[0] );
// Parse length and type.
for ( $i = 1; $i <= 2; $i++ ) {
if ( isset( $enclosure[ $i ] ) ) {
if ( is_numeric( $enclosure[ $i ] ) ) {
$length = trim( $enclosure[ $i ] );
} elseif ( in_array( $enclosure[ $i ], $mimes, true ) ) {
$type = trim( $enclosure[ $i ] );
$html_link_tag = sprintf(
"<link href=\"%s\" rel=\"enclosure\" length=\"%d\" type=\"%s\" />\n",
* Filters the atom enclosure HTML link tag for the current post.
* @param string $html_link_tag The HTML link tag with a URI and other attributes.
echo apply_filters( 'atom_enclosure', $html_link_tag );
* Determines the type of a string of data with the data formatted.
* Tell whether the type is text, HTML, or XHTML, per RFC 4287 section 3.1.
* In the case of WordPress, text is defined as containing no markup,
* XHTML is defined as "well formed", and HTML as tag soup (i.e., the rest).
* Container div tags are added to XHTML values, per section 3.1.1.3.
* @link http://www.atomenabled.org/developers/syndication/atom-format-spec.php#rfc.section.3.1
* @param string $data Input string.
* @return array array(type, value)
function prep_atom_text_construct( $data ) {
if ( ! str_contains( $data, '<' ) && ! str_contains( $data, '&' ) ) {
return array( 'text', $data );
if ( ! function_exists( 'xml_parser_create' ) ) {
wp_trigger_error( '', __( "PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension." ) );
return array( 'html', "<![CDATA[$data]]>" );
$parser = xml_parser_create();
xml_parse( $parser, '<div>' . $data . '</div>', true );
$code = xml_get_error_code( $parser );
xml_parser_free( $parser );
if ( ! str_contains( $data, '<' ) ) {
return array( 'text', $data );
$data = "<div xmlns='http://www.w3.org/1999/xhtml'>$data</div>";
return array( 'xhtml', $data );
if ( ! str_contains( $data, ']]>' ) ) {
return array( 'html', "<![CDATA[$data]]>" );
return array( 'html', htmlspecialchars( $data ) );
* Displays Site Icon in atom feeds.
* @see get_site_icon_url()
function atom_site_icon() {
$url = get_site_icon_url( 32 );
echo '<icon>' . convert_chars( $url ) . "</icon>\n";
* Displays Site Icon in RSS2.
function rss2_site_icon() {
$rss_title = get_wp_title_rss();
if ( empty( $rss_title ) ) {
$rss_title = get_bloginfo_rss( 'name' );
$url = get_site_icon_url( 32 );
<url>' . convert_chars( $url ) . '</url>
<title>' . $rss_title . '</title>
<link>' . get_bloginfo_rss( 'url' ) . '</link>
* Returns the link for the currently displayed feed.
* @return string Correct link for the atom:self element.
function get_self_link() {
$parsed = parse_url( home_url() );
$domain = $parsed['host'];
if ( isset( $parsed['port'] ) ) {
$domain .= ':' . $parsed['port'];
return set_url_scheme( 'http://' . $domain . wp_unslash( $_SERVER['REQUEST_URI'] ) );
* Displays the link for the currently displayed feed in a XSS safe way.
* Generate a correct link for the atom:self element.
* Filters the current feed URL.
* @param string $feed_link The link for the feed with set URL scheme.
echo esc_url( apply_filters( 'self_link', get_self_link() ) );
* Gets the UTC time of the most recently modified post from WP_Query.
* If viewing a comment feed, the time of the most recently modified
* comment will be returned.
* @global WP_Query $wp_query WordPress Query object.
* @param string $format Date format string to return the time in.
* @return string|false The time in requested format, or false on failure.
function get_feed_build_date( $format ) {
$max_modified_time = false;
$utc = new DateTimeZone( 'UTC' );
if ( ! empty( $wp_query ) && $wp_query->have_posts() ) {
// Extract the post modified times from the posts.
$modified_times = wp_list_pluck( $wp_query->posts, 'post_modified_gmt' );
// If this is a comment feed, check those objects too.
if ( $wp_query->is_comment_feed() && $wp_query->comment_count ) {
// Extract the comment modified times from the comments.
$comment_times = wp_list_pluck( $wp_query->comments, 'comment_date_gmt' );
// Add the comment times to the post times for comparison.
$modified_times = array_merge( $modified_times, $comment_times );
// Determine the maximum modified time.
$datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', max( $modified_times ), $utc );
if ( false === $datetime ) {
// Fall back to last time any post was modified or published.
$datetime = date_create_immutable_from_format( 'Y-m-d H:i:s', get_lastpostmodified( 'GMT' ), $utc );
if ( false !== $datetime ) {
$max_modified_time = $datetime->format( $format );
* Filters the date the last post or comment in the query was modified.
* @param string|false $max_modified_time Date the last post or comment was modified in the query, in UTC.
* @param string $format The date format requested in get_feed_build_date().
return apply_filters( 'get_feed_build_date', $max_modified_time, $format );
* Returns the content type for specified feed type.
* @param string $type Type of feed. Possible values include 'rss', rss2', 'atom', and 'rdf'.
* @return string Content type for specified feed type.
function feed_content_type( $type = '' ) {
$type = get_default_feed();
'rss' => 'application/rss+xml',
'rss2' => 'application/rss+xml',
'rss-http' => 'text/xml',
'atom' => 'application/atom+xml',
'rdf' => 'application/rdf+xml',
$content_type = ( ! empty( $types[ $type ] ) ) ? $types[ $type ] : 'application/octet-stream';
* Filters the content type for a specific feed type.
* @param string $content_type Content type indicating the type of data that a feed contains.
* @param string $type Type of feed. Possible values include 'rss', rss2', 'atom', and 'rdf'.
return apply_filters( 'feed_content_type', $content_type, $type );
* Builds SimplePie object based on RSS or Atom feed from URL.
* @param string|string[] $url URL of feed to retrieve. If an array of URLs, the feeds are merged
* using SimplePie's multifeed feature.
* See also {@link http://simplepie.org/wiki/faq/typical_multifeed_gotchas}
* @return SimplePie|WP_Error SimplePie object on success or WP_Error object on failure.
function fetch_feed( $url ) {
if ( ! class_exists( 'SimplePie', false ) ) {
require_once ABSPATH . WPINC . '/class-simplepie.php';
require_once ABSPATH . WPINC . '/class-wp-feed-cache-transient.php';
require_once ABSPATH . WPINC . '/class-wp-simplepie-file.php';
require_once ABSPATH . WPINC . '/class-wp-simplepie-sanitize-kses.php';
$feed->set_sanitize_class( 'WP_SimplePie_Sanitize_KSES' );
* We must manually overwrite $feed->sanitize because SimplePie's constructor
* sets it before we have a chance to set the sanitization class.
$feed->sanitize = new WP_SimplePie_Sanitize_KSES();
// Register the cache handler using the recommended method for SimplePie 1.3 or later.
if ( method_exists( 'SimplePie_Cache', 'register' ) ) {
SimplePie_Cache::register( 'wp_transient', 'WP_Feed_Cache_Transient' );
$feed->set_cache_location( 'wp_transient' );
// Back-compat for SimplePie 1.2.x.
require_once ABSPATH . WPINC . '/class-wp-feed-cache.php';
$feed->set_cache_class( 'WP_Feed_Cache' );
$feed->set_file_class( 'WP_SimplePie_File' );
$feed->set_feed_url( $url );
/** This filter is documented in wp-includes/class-wp-feed-cache-transient.php */
$feed->set_cache_duration( apply_filters( 'wp_feed_cache_transient_lifetime', 12 * HOUR_IN_SECONDS, $url ) );
* Fires just before processing the SimplePie feed object.
* @param SimplePie $feed SimplePie feed object (passed by reference).
* @param string|string[] $url URL of feed or array of URLs of feeds to retrieve.
do_action_ref_array( 'wp_feed_options', array( &$feed, $url ) );
$feed->set_output_encoding( get_option( 'blog_charset' ) );
return new WP_Error( 'simplepie-error', $feed->error() );