if ( ! empty( $field['helps'] ) ) {
$item .= "<p class='help'>" . implode( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
$item .= "</td>\n\t\t</tr>\n";
if ( ! empty( $field['errors'] ) ) {
foreach ( array_unique( (array) $field['errors'] ) as $error ) {
$extra_rows['error'][] = $error;
if ( ! empty( $field['extra_rows'] ) ) {
foreach ( $field['extra_rows'] as $class => $rows ) {
foreach ( (array) $rows as $html ) {
$extra_rows[ $class ][] = $html;
foreach ( $extra_rows as $class => $rows ) {
foreach ( $rows as $html ) {
$item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
if ( ! empty( $form_fields['_final'] ) ) {
$item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
$item = '<p class="media-types media-types-required-info">' .
/* translators: %s: Asterisk symbol (*). */
sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) .
'<table class="compat-attachment-fields">' . $item . '</table>';
foreach ( $hidden_fields as $hidden_field => $value ) {
$item .= '<input type="hidden" name="' . esc_attr( $hidden_field ) . '" value="' . esc_attr( $value ) . '" />' . "\n";
$item = '<input type="hidden" name="attachments[' . $attachment_id . '][menu_order]" value="' . esc_attr( $post->menu_order ) . '" />' . $item;
* Outputs the legacy media upload header.
function media_upload_header() {
$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
echo '<script type="text/javascript">post_id = ' . $post_id . ';</script>';
if ( empty( $_GET['chromeless'] ) ) {
echo '<div id="media-upload-header">';
* Outputs the legacy media upload form.
function media_upload_form( $errors = null ) {
global $type, $tab, $is_IE, $is_opera;
if ( ! _device_can_upload() ) {
/* translators: %s: https://apps.wordpress.org/ */
__( 'The web browser on your device cannot be used to upload files. You may be able to use the <a href="%s">native app for your device</a> instead.' ),
'https://apps.wordpress.org/'
$upload_action_url = admin_url( 'async-upload.php' );
$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
$_type = isset( $type ) ? $type : '';
$_tab = isset( $tab ) ? $tab : '';
$max_upload_size = wp_max_upload_size();
if ( ! $max_upload_size ) {
<div id="media-upload-notice">
if ( isset( $errors['upload_notice'] ) ) {
echo $errors['upload_notice'];
<div id="media-upload-error">
if ( isset( $errors['upload_error'] ) && is_wp_error( $errors['upload_error'] ) ) {
echo $errors['upload_error']->get_error_message();
if ( is_multisite() && ! is_upload_space_available() ) {
* Fires when an upload will exceed the defined upload space quota for a network site.
do_action( 'upload_ui_over_quota' );
* Fires just before the legacy (pre-3.5.0) upload interface is loaded.
do_action( 'pre-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
'_wpnonce' => wp_create_nonce( 'media-form' ),
* Filters the media upload post parameters.
* @since 3.1.0 As 'swfupload_post_params'
* @param array $post_params An array of media upload parameters used by Plupload.
$post_params = apply_filters( 'upload_post_params', $post_params );
* Since 4.9 the `runtimes` setting is hardcoded in our version of Plupload to `html5,html4`,
* and the `flash_swf_url` and `silverlight_xap_url` are not used.
'browse_button' => 'plupload-browse-button',
'container' => 'plupload-upload-ui',
'drop_element' => 'drag-drop-area',
'file_data_name' => 'async-upload',
'url' => $upload_action_url,
'filters' => array( 'max_file_size' => $max_upload_size . 'b' ),
'multipart_params' => $post_params,
* Currently only iOS Safari supports multiple files uploading,
* but iOS 7.x has a bug that prevents uploading of videos when enabled.
strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false &&
strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false
$plupload_init['multi_selection'] = false;
* Filters the default Plupload settings.
* @param array $plupload_init An array of default settings used by Plupload.
$plupload_init = apply_filters( 'plupload_init', $plupload_init );
<script type="text/javascript">
// Verify size is an int. If not return default value.
$large_size_h = absint( get_option( 'large_size_h' ) );
$large_size_w = absint( get_option( 'large_size_w' ) );
var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>,
wpUploaderInit = <?php echo wp_json_encode( $plupload_init ); ?>;
<div id="plupload-upload-ui" class="hide-if-no-js">
* Fires before the upload interface loads.
* @since 2.6.0 As 'pre-flash-upload-ui'
do_action( 'pre-plupload-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
<div id="drag-drop-area">
<div class="drag-drop-inside">
<p class="drag-drop-info"><?php _e( 'Drop files to upload' ); ?></p>
<p><?php _ex( 'or', 'Uploader: Drop files here - or - Select Files' ); ?></p>
<p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e( 'Select Files' ); ?>" class="button" /></p>
* Fires after the upload interface loads.
* @since 2.6.0 As 'post-flash-upload-ui'
do_action( 'post-plupload-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
<div id="html-upload-ui" class="hide-if-js">
* Fires before the upload button in the media upload interface.
do_action( 'pre-html-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
<p id="async-upload-wrap">
<label class="screen-reader-text" for="async-upload"><?php _e( 'Upload' ); ?></label>
<input type="file" name="async-upload" id="async-upload" />
<?php submit_button( __( 'Upload' ), 'primary', 'html-upload', false ); ?>
<a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e( 'Cancel' ); ?></a>
<div class="clear"></div>
* Fires after the upload button in the media upload interface.
do_action( 'post-html-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
<p class="max-upload-size">
/* translators: %s: Maximum allowed file size. */
printf( __( 'Maximum upload file size: %s.' ), esc_html( size_format( $max_upload_size ) ) );
* Fires on the post upload UI screen.
* Legacy (pre-3.5.0) media workflow hook.
do_action( 'post-upload-ui' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
* Outputs the legacy media upload form for a given media type.
* @param int|WP_Error $id
function media_upload_type_form( $type = 'file', $errors = null, $id = null ) {
$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
$form_action_url = admin_url( "media-upload.php?type=$type&tab=type&post_id=$post_id" );
* Filters the media upload form action URL.
* @param string $form_action_url The media upload form action URL.
* @param string $type The type of media. Default 'file'.
$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
$form_class = 'media-upload-form type-form validate';
if ( get_user_setting( 'uploader' ) ) {
$form_class .= ' html-uploader';
<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
<?php submit_button( '', 'hidden', 'save', false ); ?>
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
<?php wp_nonce_field( 'media-form' ); ?>
<h3 class="media-title"><?php _e( 'Add media files from your computer' ); ?></h3>
<?php media_upload_form( $errors ); ?>
<script type="text/javascript">
var preloaded = $(".media-item.preloaded");
if ( preloaded.length > 0 ) {
preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
if ( ! is_wp_error( $id ) ) {
add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 );
echo get_media_items( $id, $errors );
echo '<div id="media-upload-error">' . esc_html( $id->get_error_message() ) . '</div></div>';
<p class="savebutton ml-submit">
<?php submit_button( __( 'Save all changes' ), '', 'save', false ); ?>
* Outputs the legacy media upload form for external media.
function media_upload_type_url_form( $type = null, $errors = null, $id = null ) {
$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
$form_action_url = admin_url( "media-upload.php?type=$type&tab=type&post_id=$post_id" );
/** This filter is documented in wp-admin/includes/media.php */
$form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type );
$form_class = 'media-upload-form type-form validate';
if ( get_user_setting( 'uploader' ) ) {
$form_class .= ' html-uploader';
<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
<?php wp_nonce_field( 'media-form' ); ?>
<h3 class="media-title"><?php _e( 'Insert media from another website' ); ?></h3>
<script type="text/javascript">
var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = '';
if ( '' === f.src.value || '' === t.width )
alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
/** This filter is documented in wp-admin/includes/media.php */
if ( ! apply_filters( 'disable_captions', '' ) ) {
caption = f.caption.value.replace(/\r\n|\r/g, '\n');
caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){
return a.replace(/[\r\n\t]+/, ' ');
caption = caption.replace(/\s*\n\s*/g, '<br />');
cls = caption ? '' : ' class="'+t.align+'"';
html = '<img alt="'+alt+'" src="'+f.src.value+'"'+cls+' width="'+t.width+'" height="'+t.height+'" />';
url = f.url.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
html = '<a href="'+url+'">'+html+'</a>';
html = '[caption id="" align="'+t.align+'" width="'+t.width+'"]'+html+caption+'[/caption]';
var win = window.dialogArguments || opener || parent || top;
win.send_to_editor(html);
resetImageData : function() {
document.getElementById('go_button').style.color = '#bbb';
if ( ! document.forms[0].src.value )
document.getElementById('status_img').innerHTML = '';
else document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/no.png' ) ); ?>" alt="" />';
updateImageData : function() {
t.width = t.preloadImg.width;
t.height = t.preloadImg.height;
document.getElementById('go_button').style.color = '#333';
document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/yes.png' ) ); ?>" alt="" />';
getImageData : function() {
if ( jQuery('table.describe').hasClass('not-image') )
var t = addExtImage, src = document.forms[0].src.value;
document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/spinner-2x.gif' ) ); ?>" alt="" width="16" height="16" />';
t.preloadImg = new Image();
t.preloadImg.onload = t.updateImageData;
t.preloadImg.onerror = t.resetImageData;
jQuery(document).ready( function($) {
$('.media-types input').click( function() {
$('table.describe').toggleClass('not-image', $('#not-image').prop('checked') );
<div class="media-item media-blank">