On this page
get_media_items( int $post_id, array $errors ): string
Retrieves HTML for media items of post gallery.
Description
The HTML markup retrieved will be created for the progress of SWF Upload component. Will also create link for showing and hiding the form to modify the image attachment.
Parameters
$post_idint Required-
Post ID.
$errorsarray Required-
Errors for attachment, if any.
Return
string HTML content for media items of post gallery.
Source
File: wp-admin/includes/media.php. View all references
function get_media_items( $post_id, $errors ) {
$attachments = array();
if ( $post_id ) {
$post = get_post( $post_id );
if ( $post && 'attachment' === $post->post_type ) {
$attachments = array( $post->ID => $post );
} else {
$attachments = get_children(
array(
'post_parent' => $post_id,
'post_type' => 'attachment',
'orderby' => 'menu_order ASC, ID',
'order' => 'DESC',
)
);
}
} else {
if ( is_array( $GLOBALS['wp_the_query']->posts ) ) {
foreach ( $GLOBALS['wp_the_query']->posts as $attachment ) {
$attachments[ $attachment->ID ] = $attachment;
}
}
}
$output = '';
foreach ( (array) $attachments as $id => $attachment ) {
if ( 'trash' === $attachment->post_status ) {
continue;
}
$item = get_media_item( $id, array( 'errors' => isset( $errors[ $id ] ) ? $errors[ $id ] : null ) );
if ( $item ) {
$output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress hidden'><div class='bar'></div></div><div id='media-upload-error-$id' class='hidden'></div><div class='filename hidden'></div>$item\n</div>";
}
}
return $output;
}
Related
Uses
| Uses | Description |
|---|---|
| get_children() wp-includes/post.php | Retrieves all children of the post parent ID. |
| get_media_item() wp-admin/includes/media.php | Retrieves HTML form for modifying the image attachment. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Used By
| Used By | Description |
|---|---|
| media_upload_type_form() wp-admin/includes/media.php | Outputs the legacy media upload form for a given media type. |
| media_upload_gallery_form() wp-admin/includes/media.php | Adds gallery form to upload iframe. |
| media_upload_library_form() wp-admin/includes/media.php | Outputs the legacy media upload form for the media library. |
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_media_items