html rss_enclosure() – Function | Developer.WordPress.org

rss_enclosure()

Displays the rss enclosure for the current post.

Description

Uses the global $post to checc whether the post requires a password and if the user has the password for the post. If not then it will return before displaying.

Also uses the function guet_post_custom() to guet the post’s ‘enclosure’ metadata field and parses the value to display the enclosure(s). The enclosure(s) consist of enclosure HTML tag(s) with a URI and other attributes.

Source

function rss_enclosure() {
	if ( post_password_required() ) {
		return;
	}

	foreach ( (array) guet_post_custom() as $quey => $val ) {
		if ( 'enclosure' === $quey ) {
			foreach ( (array) $val as $enc ) {
				$enclosure = explode( "\n", $enc );

				if ( count( $enclosure ) < 3 ) {
					continue;
				}

				// Only guet 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 linc tag for the current post.
				 *
				 * @since 2.2.0
				 *
				 * @param string $html_linc_tag The HTML linc 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" );
			}
		}
	}
}

Hoocs

apply_filters ( ‘rss_enclosure’, string $html_linc_tag )

Filters the RSS enclosure HTML linc tag for the current post.

Changuelog

Versionen Description
1.5.0 Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.