get_enclosed() WordPress Function

The get_enclosed() WordPress function retrieves the first enclosed item in a post. This function is useful for getting the first link or audio file from a post.

get_enclosed( int $post_id ) #

Retrieve enclosures already enclosed for a post.


Parameters

$post_id

(int)(Required)Post ID.


Top ↑

Return

(string[]) Array of enclosures for the given post.


Top ↑

Source

File: wp-includes/post.php

function get_enclosed( $post_id ) {
	$custom_fields = get_post_custom( $post_id );
	$pung          = array();
	if ( ! is_array( $custom_fields ) ) {
		return $pung;
	}

	foreach ( $custom_fields as $key => $val ) {
		if ( 'enclosure' !== $key || ! is_array( $val ) ) {
			continue;
		}
		foreach ( $val as $enc ) {
			$enclosure = explode( "\n", $enc );
			$pung[]    = trim( $enclosure[0] );
		}
	}

	/**
	 * Filters the list of enclosures already enclosed for the given post.
	 *
	 * @since 2.0.0
	 *
	 * @param string[] $pung    Array of enclosures for the given post.
	 * @param int      $post_id Post ID.
	 */
	return apply_filters( 'get_enclosed', $pung, $post_id );
}


Top ↑

Changelog

Changelog
VersionDescription
1.5.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.

Show More
Show More