atom_enclosure() WordPress Function

The atom_enclosure() function is used to display an Atom feed enclosure.

atom_enclosure() #

Display the atom enclosure for the current post.


Description

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 displaying.

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.


Top ↑

Source

File: wp-includes/feed.php

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

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

				$url    = '';
				$type   = '';
				$length = 0;

				$mimes = get_allowed_mime_types();

				// Parse URL.
				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",
					esc_url( $url ),
					esc_attr( $length ),
					esc_attr( $type )
				);

				/**
				 * Filters the atom 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( 'atom_enclosure', $html_link_tag );
			}
		}
	}
}


Top ↑

Changelog

Changelog
VersionDescription
2.2.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.