media_upload_library_form

Outputs the legacy media upload form for the media library.

Description

media_upload_library_form( (array) $errors ); 

Parameters (1)

0. $errors (array)
The errors.

Usage

  1. if ( !function_exists( 'media_upload_library_form' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/media.php'; 
  3.  
  4. // The errors. 
  5. $errors = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = media_upload_library_form($errors); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/media.php  
  1. function media_upload_library_form($errors) { 
  2. global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types; 
  3.  
  4.  
  5. $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; 
  6.  
  7. $form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id"); 
  8. /** This filter is documented in wp-admin/includes/media.php */ 
  9. $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); 
  10. $form_class = 'media-upload-form validate'; 
  11.  
  12. if ( get_user_setting('uploader') ) 
  13. $form_class .= ' html-uploader'; 
  14.  
  15. $q = $_GET; 
  16. $q['posts_per_page'] = 10; 
  17. $q['paged'] = isset( $q['paged'] ) ? intval( $q['paged'] ) : 0; 
  18. if ( $q['paged'] < 1 ) { 
  19. $q['paged'] = 1; 
  20. $q['offset'] = ( $q['paged'] - 1 ) * 10; 
  21. if ( $q['offset'] < 1 ) { 
  22. $q['offset'] = 0; 
  23.  
  24. list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query( $q ); 
  25.  
  26. ?> 
  27.  
  28. <form id="filter" method="get"> 
  29. <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" /> 
  30. <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" /> 
  31. <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" /> 
  32. <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" /> 
  33. <input type="hidden" name="context" value="<?php echo isset( $_GET['context'] ) ? esc_attr( $_GET['context'] ) : ''; ?>" /> 
  34.  
  35. <p id="media-search" class="search-box"> 
  36. <label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label> 
  37. <input type="search" id="media-search-input" name="s" value="<?php the_search_query(); ?>" /> 
  38. <?php submit_button( __( 'Search Media' ), '', '', false ); ?> 
  39. </p> 
  40.  
  41. <ul class="subsubsub"> 
  42. <?php 
  43. $type_links = array(); 
  44. $_num_posts = (array) wp_count_attachments(); 
  45. $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts)); 
  46. foreach ( $matches as $_type => $reals ) 
  47. foreach ( $reals as $real ) 
  48. if ( isset($num_posts[$_type]) ) 
  49. $num_posts[$_type] += $_num_posts[$real]; 
  50. else 
  51. $num_posts[$_type] = $_num_posts[$real]; 
  52. // If available type specified by media button clicked, filter by that type 
  53. if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) { 
  54. $_GET['post_mime_type'] = $type; 
  55. list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query(); 
  56. if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' ) 
  57. $class = ' class="current"'; 
  58. else 
  59. $class = ''; 
  60. $type_links[] = '<li><a href="' . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . '"' . $class . '>' . __('All Types') . '</a>'; 
  61. foreach ( $post_mime_types as $mime_type => $label ) { 
  62. $class = ''; 
  63.  
  64. if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) ) 
  65. continue; 
  66.  
  67. if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) ) 
  68. $class = ' class="current"'; 
  69.  
  70. $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>'; 
  71. /** 
  72. * Filters the media upload mime type list items. 
  73. * Returned values should begin with an `<li>` tag. 
  74. * @since 3.1.0 
  75. * @param array $type_links An array of list items containing mime type link HTML. 
  76. */ 
  77. echo implode(' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>'; 
  78. unset($type_links); 
  79. ?> 
  80. </ul> 
  81.  
  82. <div class="tablenav"> 
  83.  
  84. <?php 
  85. $page_links = paginate_links( array( 
  86. 'base' => add_query_arg( 'paged', '%#%' ),  
  87. 'format' => '',  
  88. 'prev_text' => __('«'),  
  89. 'next_text' => __('»'),  
  90. 'total' => ceil($wp_query->found_posts / 10),  
  91. 'current' => $q['paged'],  
  92. )); 
  93.  
  94. if ( $page_links ) 
  95. echo "<div class='tablenav-pages'>$page_links</div>"; 
  96. ?> 
  97.  
  98. <div class="alignleft actions"> 
  99. <?php 
  100.  
  101. $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"; 
  102.  
  103. $arc_result = $wpdb->get_results( $arc_query ); 
  104.  
  105. $month_count = count($arc_result); 
  106. $selected_month = isset( $_GET['m'] ) ? $_GET['m'] : 0; 
  107.  
  108. if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?> 
  109. <select name='m'> 
  110. <option<?php selected( $selected_month, 0 ); ?> value='0'><?php _e( 'All dates' ); ?></option> 
  111. <?php 
  112. foreach ($arc_result as $arc_row) { 
  113. if ( $arc_row->yyear == 0 ) 
  114. continue; 
  115. $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 ); 
  116.  
  117. if ( $arc_row->yyear . $arc_row->mmonth == $selected_month ) 
  118. $default = ' selected="selected"'; 
  119. else 
  120. $default = ''; 
  121.  
  122. echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>"; 
  123. echo esc_html( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" ); 
  124. echo "</option>\n"; 
  125. ?> 
  126. </select> 
  127. <?php } ?> 
  128.  
  129. <?php submit_button( __( 'Filter »' ), '', 'post-query-submit', false ); ?> 
  130.  
  131. </div> 
  132.  
  133. <br class="clear" /> 
  134. </div> 
  135. </form> 
  136.  
  137. <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( $form_action_url ); ?>" class="<?php echo $form_class; ?>" id="library-form"> 
  138.  
  139. <?php wp_nonce_field('media-form'); ?> 
  140. <?php //media_upload_form( $errors ); ?> 
  141.  
  142. <script type="text/javascript"> 
  143. <!-- 
  144. jQuery(function($) { 
  145. var preloaded = $(".media-item.preloaded"); 
  146. if ( preloaded.length > 0 ) { 
  147. preloaded.each(function() {prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')}, '');}); 
  148. updateMediaForm(); 
  149. }); 
  150. --> 
  151. </script> 
  152.  
  153. <div id="media-items"> 
  154. <?php echo get_media_items(null, $errors); ?> 
  155. </div> 
  156. <p class="ml-submit"> 
  157. <?php submit_button( __( 'Save all changes' ), 'savebutton', 'save', false ); ?> 
  158. <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> 
  159. </p> 
  160. </form> 
  161. <?php