显示当前帖子的rss附件。

原型

rss_enclosure()

描述

使用全局$ post检查帖子是否需要密码以及用户是否拥有帖子的密码。如果没有,那么它将在显示之前返回。

源文件

路径:wp-includes/feed.php

<?php
...
function rss_enclosure() {
	if ( post_password_required() )
		return;
	foreach ( (array) get_post_custom() as $key => $val) {
		if ($key == 'enclosure') {
			foreach ( (array) $val as $enc ) {
				$enclosure = explode("n", $enc);
				// only get the first element, e.g. audio/mpeg from 'audio/mpeg mpga mp2 mp3'
				$t = preg_split('/[ t]/', trim($enclosure[2]) );
				$type = $t[0];
				/**
				 * Filters the RSS enclosure HTML link tag for the current post.
				 *
				 * @since 2.2.0
				 *
				 * @param string $html_link_tag The HTML link tag with a URI and other attributes.
				 */
				echo apply_filters( 'rss_enclosure', '<enclosure url="' . esc_url( trim( $enclosure[0] ) ) . '" length="' . absint( trim( $enclosure[1] ) ) . '" type="' . esc_attr( $type ) . '" />' . "n" );
			}
		}
	}
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/rss_enclosure/