get_media_item
函数
get_media_item ( $attachment_id, $args = null )
- 参数
-
-
(int)
$attachment_id
Attachment ID for modification.- Required: 是
-
(string|array)
$args
Optional. Override defaults.- Required: 否
- Default: null
-
(int)
- 返回值
-
- (string) HTML form for attachment.
- 定义位置
-
-
wp-admin/includes/media.php
, line 1570
-
wp-admin/includes/media.php
- 引入
- 2.5.0
- 弃用
- –
检索用于修改图片附件的HTML表格。
function get_media_item( $attachment_id, $args = null ) { global $redir_tab; $thumb_url = false; $attachment_id = (int) $attachment_id; if ( $attachment_id ) { $thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ); if ( $thumb_url ) { $thumb_url = $thumb_url[0]; } } $post = get_post( $attachment_id ); $current_post_id = ! empty( $_GET['post_id'] ) ? (int) $_GET['post_id'] : 0; $default_args = array( 'errors' => null, 'send' => $current_post_id ? post_type_supports( get_post_type( $current_post_id ), 'editor' ) : true, 'delete' => true, 'toggle' => true, 'show_title' => true, ); $parsed_args = wp_parse_args( $args, $default_args ); /** * Filters the arguments used to retrieve an image for the edit image form. * * @since 3.1.0 * * @see get_media_item * * @param array $parsed_args An array of arguments. */ $parsed_args = apply_filters( 'get_media_item_args', $parsed_args ); $toggle_on = __( 'Show' ); $toggle_off = __( 'Hide' ); $file = get_attached_file( $post->ID ); $filename = esc_html( wp_basename( $file ) ); $title = esc_attr( $post->post_title ); $post_mime_types = get_post_mime_types(); $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) ); $type = reset( $keys ); $type_html = ""; $form_fields = get_attachment_fields_to_edit( $post, $parsed_args['errors'] ); if ( $parsed_args['toggle'] ) { $class = empty( $parsed_args['errors'] ) ? 'startclosed' : 'startopen'; $toggle_links = " $toggle_on $toggle_off"; } else { $class = ''; $toggle_links = ''; } $display_title = ( ! empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case. $display_title = $parsed_args['show_title'] ? "" . wp_html_excerpt( $display_title, 60, '…' ) . '' : ''; $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' === $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' === $redir_tab ) ); $order = ''; foreach ( $form_fields as $key => $val ) { if ( 'menu_order' === $key ) { if ( $gallery ) { $order = " "; } else { $order = ""; } unset( $form_fields['menu_order'] ); break; } } $media_dims = ''; $meta = wp_get_attachment_metadata( $post->ID ); if ( isset( $meta['width'], $meta['height'] ) ) { $media_dims .= "{$meta['width']} × {$meta['height']} "; } /** * Filters the media metadata. * * @since 2.5.0 * * @param string $media_dims The HTML markup containing the media dimensions. * @param WP_Post $post The WP_Post attachment object. */ $media_dims = apply_filters( 'media_meta', $media_dims, $post ); $image_edit_button = ''; if ( wp_attachment_is_image( $post->ID ) && wp_image_editor_supports( array( 'mime_type' => $post->post_mime_type ) ) ) { $nonce = wp_create_nonce( "image_editor-$post->ID" ); $image_edit_button = ""; } $attachment_url = get_permalink( $attachment_id ); $item = " $type_html $toggle_links $order $display_title
$image_edit_button |
” . __( ‘File name:’ ) . “ $filename ” . __( ‘File type:’ ) . “ $post->post_mime_type ” . __( ‘Upload date:’ ) . ‘ ‘ . mysql2date( __( ‘F j, Y’ ), $post->post_date ) . ‘ ‘; if ( ! empty( $media_dims ) ) { ‘ . __( ‘Dimensions:’ ) . “ $media_dims n”; $item .= “ |
” . |
|
” . $parsed_args[‘send’] . ” $thumbnail $delete | |
“;
if ( ! empty( $field[ $field[‘input’] ] ) ) { if ( ! empty( $field[‘helps’] ) ) { ” . implode( “ n “, array_unique( (array) $field[‘helps’] ) ) . ‘ ‘; |
|
$html | |
{$form_fields[‘_final’]} |
n”;
foreach ( $hidden_fields as $name => $value ) {
$item .= “tn”;
}
if ( $post->post_parent n”;
}
return $item;
}