wp_xmlrpc_server::_prepare_media_item() WordPress Method

The wp_xmlrpc_server::_prepare_media_item() method is used to prepare a media item for insertion into a post. This method accepts an array of data describing the media item and returns an array of data that can be used to insert the media item into a post.

wp_xmlrpc_server::_prepare_media_item( WP_Post $media_item, string $thumbnail_size = 'thumbnail' ) #

Prepares media item data for return in an XML-RPC object.


Parameters

$media_item

(WP_Post)(Required)The unprepared media item data.

$thumbnail_size

(string)(Optional)The image size to use for the thumbnail URL.

Default value: 'thumbnail'


Top ↑

Return

(array) The prepared media item data.


Top ↑

Source

File: wp-includes/class-wp-xmlrpc-server.php

	protected function _prepare_media_item( $media_item, $thumbnail_size = 'thumbnail' ) {
		$_media_item = array(
			'attachment_id'    => (string) $media_item->ID,
			'date_created_gmt' => $this->_convert_date_gmt( $media_item->post_date_gmt, $media_item->post_date ),
			'parent'           => $media_item->post_parent,
			'link'             => wp_get_attachment_url( $media_item->ID ),
			'title'            => $media_item->post_title,
			'caption'          => $media_item->post_excerpt,
			'description'      => $media_item->post_content,
			'metadata'         => wp_get_attachment_metadata( $media_item->ID ),
			'type'             => $media_item->post_mime_type,
		);

		$thumbnail_src = image_downsize( $media_item->ID, $thumbnail_size );
		if ( $thumbnail_src ) {
			$_media_item['thumbnail'] = $thumbnail_src[0];
		} else {
			$_media_item['thumbnail'] = $_media_item['link'];
		}

		/**
		 * Filters XML-RPC-prepared data for the given media item.
		 *
		 * @since 3.4.0
		 *
		 * @param array   $_media_item    An array of media item data.
		 * @param WP_Post $media_item     Media item object.
		 * @param string  $thumbnail_size Image size.
		 */
		return apply_filters( 'xmlrpc_prepare_media_item', $_media_item, $media_item, $thumbnail_size );
	}

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