WordPress at a glance
function is not described

WP_REST_Attachments_Controller::prepare_item_for_database() protected WP 4.7.0

Prepares a single attachment for create or update.

{} It's a method of the class: WP_REST_Attachments_Controller{}

No Hooks.

Return

stdClass/WP_Error. Post object.

Usage

// protected - for code of main (parent) or child class
$result = $this->prepare_item_for_database( $request );
$request(WP_REST_Request) (required)
Request object.

Changelog

Since 4.7.0 Introduced.

Code of WP_REST_Attachments_Controller::prepare_item_for_database() WP 5.5.3

<?php
protected function prepare_item_for_database( $request ) {
	$prepared_attachment = parent::prepare_item_for_database( $request );

	// Attachment caption (post_excerpt internally).
	if ( isset( $request['caption'] ) ) {
		if ( is_string( $request['caption'] ) ) {
			$prepared_attachment->post_excerpt = $request['caption'];
		} elseif ( isset( $request['caption']['raw'] ) ) {
			$prepared_attachment->post_excerpt = $request['caption']['raw'];
		}
	}

	// Attachment description (post_content internally).
	if ( isset( $request['description'] ) ) {
		if ( is_string( $request['description'] ) ) {
			$prepared_attachment->post_content = $request['description'];
		} elseif ( isset( $request['description']['raw'] ) ) {
			$prepared_attachment->post_content = $request['description']['raw'];
		}
	}

	if ( isset( $request['post'] ) ) {
		$prepared_attachment->post_parent = (int) $request['post'];
	}

	return $prepared_attachment;
}