* Filters the insert media from URL form HTML.
* @param string $form_html The insert from URL form HTML.
echo apply_filters( 'type_url_form_media', wp_media_insert_url_form( $type ) );
* Adds gallery form to upload iframe
* @global string $redir_tab
function media_upload_gallery_form( $errors ) {
global $redir_tab, $type;
$post_id = (int) $_REQUEST['post_id'];
$form_action_url = admin_url( "media-upload.php?type=$type&tab=gallery&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 validate';
if ( get_user_setting( 'uploader' ) ) {
$form_class .= ' html-uploader';
<script type="text/javascript">
var preloaded = $(".media-item.preloaded");
if ( preloaded.length > 0 ) {
preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
<div id="sort-buttons" class="hide-if-no-js">
<?php _e( 'All Tabs:' ); ?>
<a href="#" id="showall"><?php _e( 'Show' ); ?></a>
<a href="#" id="hideall" style="display:none;"><?php _e( 'Hide' ); ?></a>
<?php _e( 'Sort Order:' ); ?>
<a href="#" id="asc"><?php _e( 'Ascending' ); ?></a> |
<a href="#" id="desc"><?php _e( 'Descending' ); ?></a> |
<a href="#" id="clear"><?php _ex( 'Clear', 'verb' ); ?></a>
<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="gallery-form">
<?php wp_nonce_field( 'media-form' ); ?>
<?php // media_upload_form( $errors ); ?>
<th><?php _e( 'Media' ); ?></th>
<th class="order-head"><?php _e( 'Order' ); ?></th>
<th class="actions-head"><?php _e( 'Actions' ); ?></th>
<?php add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); ?>
<?php echo get_media_items( $post_id, $errors ); ?>
__( 'Save all changes' ),
'style' => 'display: none;',
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
<input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" />
<input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" />
<div id="gallery-settings" style="display:none;">
<div class="title"><?php _e( 'Gallery Settings' ); ?></div>
<table id="basic" class="describe"><tbody>
<th scope="row" class="label">
<span class="alignleft"><?php _e( 'Link thumbnails to:' ); ?></span>
<input type="radio" name="linkto" id="linkto-file" value="file" />
<label for="linkto-file" class="radio"><?php _e( 'Image File' ); ?></label>
<input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" />
<label for="linkto-post" class="radio"><?php _e( 'Attachment Page' ); ?></label>
<th scope="row" class="label">
<span class="alignleft"><?php _e( 'Order images by:' ); ?></span>
<select id="orderby" name="orderby">
<option value="menu_order" selected="selected"><?php _e( 'Menu order' ); ?></option>
<option value="title"><?php _e( 'Title' ); ?></option>
<option value="post_date"><?php _e( 'Date/Time' ); ?></option>
<option value="rand"><?php _e( 'Random' ); ?></option>
<th scope="row" class="label">
<span class="alignleft"><?php _e( 'Order:' ); ?></span>
<input type="radio" checked="checked" name="order" id="order-asc" value="asc" />
<label for="order-asc" class="radio"><?php _e( 'Ascending' ); ?></label>
<input type="radio" name="order" id="order-desc" value="desc" />
<label for="order-desc" class="radio"><?php _e( 'Descending' ); ?></label>
<th scope="row" class="label">
<span class="alignleft"><?php _e( 'Gallery columns:' ); ?></span>
<select id="columns" name="columns">
<option value="1">1</option>
<option value="2">2</option>
<option value="3" selected="selected">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" />
<input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php esc_attr_e( 'Update gallery settings' ); ?>" />
* Outputs the legacy media upload form for the media library.
* @global wpdb $wpdb WordPress database abstraction object.
* @global WP_Query $wp_query WordPress Query object.
* @global WP_Locale $wp_locale WordPress date and time locale object.
* @global array $post_mime_types
function media_upload_library_form( $errors ) {
global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
$post_id = isset( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
$form_action_url = admin_url( "media-upload.php?type=$type&tab=library&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 validate';
if ( get_user_setting( 'uploader' ) ) {
$form_class .= ' html-uploader';
$q['posts_per_page'] = 10;
$q['paged'] = isset( $q['paged'] ) ? (int) $q['paged'] : 0;
$q['offset'] = ( $q['paged'] - 1 ) * 10;
if ( $q['offset'] < 1 ) {
list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q );
<form id="filter" method="get">
<input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" />
<input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" />
<input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
<input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" />
<input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" />
<p id="media-search" class="search-box">
<label class="screen-reader-text" for="media-search-input"><?php _e( 'Search Media' ); ?>:</label>
<input type="search" id="media-search-input" name="s" value="<?php the_search_query(); ?>" />
<?php submit_button( __( 'Search Media' ), '', '', false ); ?>
$_num_posts = (array) wp_count_attachments();
$matches = wp_match_mime_types( array_keys( $post_mime_types ), array_keys( $_num_posts ) );
foreach ( $matches as $_type => $reals ) {
foreach ( $reals as $real ) {
if ( isset( $num_posts[ $_type ] ) ) {
$num_posts[ $_type ] += $_num_posts[ $real ];
$num_posts[ $_type ] = $_num_posts[ $real ];
// If available type specified by media button clicked, filter by that type.
if ( empty( $_GET['post_mime_type'] ) && ! empty( $num_posts[ $type ] ) ) {
$_GET['post_mime_type'] = $type;
list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
if ( empty( $_GET['post_mime_type'] ) || 'all' === $_GET['post_mime_type'] ) {
$class = ' class="current"';
$type_links[] = '<li><a href="' . esc_url(
'post_mime_type' => 'all',
) . '"' . $class . '>' . __( 'All Types' ) . '</a>';
foreach ( $post_mime_types as $mime_type => $label ) {
if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) {
if ( isset( $_GET['post_mime_type'] ) && wp_match_mime_types( $mime_type, $_GET['post_mime_type'] ) ) {
$class = ' class="current"';
$type_links[] = '<li><a href="' . esc_url(
'post_mime_type' => $mime_type,
) . '"' . $class . '>' . sprintf( translate_nooped_plural( $label[2], $num_posts[ $mime_type ] ), '<span id="' . $mime_type . '-counter">' . number_format_i18n( $num_posts[ $mime_type ] ) . '</span>' ) . '</a>';
* Filters the media upload mime type list items.
* Returned values should begin with an `<li>` tag.
* @param string[] $type_links An array of list items containing mime type link HTML.
echo implode( ' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>';
$page_links = paginate_links(
'base' => add_query_arg( 'paged', '%#%' ),
'prev_text' => __( '«' ),
'next_text' => __( '»' ),
'total' => ceil( $wp_query->found_posts / 10 ),
'current' => $q['paged'],
echo "<div class='tablenav-pages'>$page_links</div>";
<div class="alignleft actions">
$arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC";
$arc_result = $wpdb->get_results( $arc_query );
$month_count = count( $arc_result );
$selected_month = isset( $_GET['m'] ) ? $_GET['m'] : 0;
if ( $month_count && ! ( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) {
<option<?php selected( $selected_month, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option>
foreach ( $arc_result as $arc_row ) {
if ( 0 == $arc_row->yyear ) {
$arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
if ( $arc_row->yyear . $arc_row->mmonth == $selected_month ) {
$default = ' selected="selected"';
echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>";
echo esc_html( $wp_locale->get_month( $arc_row->mmonth ) . " $arc_row->yyear" );
<?php submit_button( __( 'Filter »' ), '', 'post-query-submit', false ); ?>
<form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="library-form">
<?php wp_nonce_field( 'media-form' ); ?>
<?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, '')},'');});
<?php add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); ?>
<?php echo get_media_items( null, $errors ); ?>
<?php submit_button( __( 'Save all changes' ), 'savebutton', 'save', false ); ?>
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
* Creates the form for external url
* @param string $default_view
* @return string the form html
function wp_media_insert_url_form( $default_view = 'image' ) {
/** This filter is documented in wp-admin/includes/media.php */
if ( ! apply_filters( 'disable_captions', '' ) ) {
<th scope="row" class="label">
<label for="caption"><span class="alignleft">' . __( 'Image Caption' ) . '</span></label>
<td class="field"><textarea id="caption" name="caption"></textarea></td>
$default_align = get_option( 'image_default_align' );
if ( empty( $default_align ) ) {
if ( 'image' === $default_view ) {
<p class="media-types"><label><input type="radio" name="media_type" value="image" id="image-only"' . checked( 'image-only', $view, false ) . ' /> ' . __( 'Image' ) . '</label> <label><input type="radio" name="media_type" value="generic" id="not-image"' . checked( 'not-image', $view, false ) . ' /> ' . __( 'Audio, Video, or Other File' ) . '</label></p>
<p class="media-types media-types-required-info">' .
/* translators: %s: Asterisk symbol (*). */
sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) .
<table class="describe ' . $table_class . '"><tbody>
<th scope="row" class="label" style="width:130px;">
<label for="src"><span class="alignleft">' . __( 'URL' ) . '</span> <span class="required">*</span></label>
<span class="alignright" id="status_img"></span>
<td class="field"><input id="src" name="src" value="" type="text" required onblur="addExtImage.getImageData()" /></td>
<th scope="row" class="label">
<label for="title"><span class="alignleft">' . __( 'Title' ) . '</span> <span class="required">*</span></label>
<td class="field"><input id="title" name="title" value="" type="text" required /></td>
<tr class="not-image"><td></td><td><p class="help">' . __( 'Link text, e.g. “Ransom Demands (PDF)”' ) . '</p></td></tr>
<th scope="row" class="label">
<label for="alt"><span class="alignleft">' . __( 'Alternative Text' ) . '</span></label>
<td class="field"><input id="alt" name="alt" value="" type="text" required />
<p class="help">' . __( 'Alt text for the image, e.g. “The Mona Lisa”' ) . '</p></td>
<tr class="align image-only">
<th scope="row" class="label"><p><label for="align">' . __( 'Alignment' ) . '</label></p></th>
<input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( 'none' === $default_align ? ' checked="checked"' : '' ) . ' />
<label for="align-none" class="align image-align-none-label">' . __( 'None' ) . '</label>
<input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( 'left' === $default_align ? ' checked="checked"' : '' ) . ' />
<label for="align-left" class="align image-align-left-label">' . __( 'Left' ) . '</label>
<input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( 'center' === $default_align ? ' checked="checked"' : '' ) . ' />
<label for="align-center" class="align image-align-center-label">' . __( 'Center' ) . '</label>
<input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ( 'right' === $default_align ? ' checked="checked"' : '' ) . ' />
<label for="align-right" class="align image-align-right-label">' . __( 'Right' ) . '</label>
<th scope="row" class="label">
<label for="url"><span class="alignleft">' . __( 'Link Image To:' ) . '</span></label>
<td class="field"><input id="url" name="url" value="" type="text" /><br />
<button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __( 'None' ) . '</button>
<button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __( 'Link to image' ) . '</button>
<p class="help">' . __( 'Enter a link URL or click above for presets.' ) . '</p></td>
<input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__( 'Insert into Post' ) . '" />
' . get_submit_button( __( 'Insert into Post' ), '', 'insertonlybutton', false ) . '
* Displays the multi-file uploader message.