media_upload_library_form() – Outputs the legacy media upload form for the media library.

You appear to be a bot. Output may be restricted

Description

Outputs the legacy media upload form for the media library.

Usage

media_upload_library_form( $errors );

Parameters

$errors
( array ) required

Returns

void

Source

File name: wordpress/wp-admin/includes/media.php
Lines:

1 to 100 of 199
function media_upload_library_form( $errors ) {
  global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;

  media_upload_header();

  $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                   = $_GET;
  $q['posts_per_page'] = 10;
  $q['paged']          = isset( $q['paged'] ) ? (int) $q['paged'] : 0;
  if ( $q['paged'] < 1 ) {
    $q['paged'] = 1;
  }
  $q['offset'] = ( $q['paged'] - 1 ) * 10;
  if ( $q['offset'] < 1 ) {
    $q['offset'] = 0;
  }

  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 ); ?>
	</p>

	<ul class="subsubsub">
		<?php
    $type_links = array();
    $_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 ];
        } else {
          $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"';
    } else {
      $class = '';
    }
    $type_links[] = '<li><a href="' . esc_url(
      add_query_arg(
        array(
          'post_mime_type' => 'all',
          'paged'          => false,
          'm'              => false,
        )
      )
    ) . '"' . $class . '>' . __( 'All Types' ) . '</a>';
    foreach ( $post_mime_types as $mime_type => $label ) {
      $class = '';

      if ( ! wp_match_mime_types( $mime_type, $avail_post_mime_types ) ) {
        continue;
      }

      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(
        add_query_arg(
          array(
            'post_mime_type' => $mime_type,
            'paged'          => false,
          )
        )
      ) . '"' . $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.
 

 View on GitHub View on Trac