media_upload_form

Outputs the legacy media upload form.

Description

media_upload_form( (null) $errors = null ); 

Parameters (1)

0. $errors — Optional. (null) => null
The errors.

Usage

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

Defined (1)

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

/wp-admin/includes/media.php  
  1. function media_upload_form( $errors = null ) { 
  2. global $type, $tab, $is_IE, $is_opera; 
  3.  
  4. if ( ! _device_can_upload() ) { 
  5. echo '<p>' . sprintf( __('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/' ) . '</p>'; 
  6. return; 
  7.  
  8. $upload_action_url = admin_url('async-upload.php'); 
  9. $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0; 
  10. $_type = isset($type) ? $type : ''; 
  11. $_tab = isset($tab) ? $tab : ''; 
  12.  
  13. $max_upload_size = wp_max_upload_size(); 
  14. if ( ! $max_upload_size ) { 
  15. $max_upload_size = 0; 
  16. ?> 
  17.  
  18. <div id="media-upload-notice"><?php 
  19.  
  20. if (isset($errors['upload_notice']) ) 
  21. echo $errors['upload_notice']; 
  22.  
  23. ?></div> 
  24. <div id="media-upload-error"><?php 
  25.  
  26. if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) 
  27. echo $errors['upload_error']->get_error_message(); 
  28.  
  29. ?></div> 
  30. <?php 
  31. if ( is_multisite() && !is_upload_space_available() ) { 
  32. /** 
  33. * Fires when an upload will exceed the defined upload space quota for a network site. 
  34. * @since 3.5.0 
  35. */ 
  36. return; 
  37.  
  38. /** 
  39. * Fires just before the legacy (pre-3.5.0) upload interface is loaded. 
  40. * @since 2.6.0 
  41. */ 
  42. do_action( 'pre-upload-ui' ); 
  43.  
  44. $post_params = array( 
  45. "post_id" => $post_id,  
  46. "_wpnonce" => wp_create_nonce('media-form'),  
  47. "type" => $_type,  
  48. "tab" => $_tab,  
  49. "short" => "1",  
  50. ); 
  51.  
  52. /** 
  53. * Filters the media upload post parameters. 
  54. * @since 3.1.0 As 'swfupload_post_params' 
  55. * @since 3.3.0 
  56. * @param array $post_params An array of media upload parameters used by Plupload. 
  57. */ 
  58. $post_params = apply_filters( 'upload_post_params', $post_params ); 
  59.  
  60. $plupload_init = array( 
  61. 'runtimes' => 'html5, flash, silverlight, html4',  
  62. 'browse_button' => 'plupload-browse-button',  
  63. 'container' => 'plupload-upload-ui',  
  64. 'drop_element' => 'drag-drop-area',  
  65. 'file_data_name' => 'async-upload',  
  66. 'url' => $upload_action_url,  
  67. 'flash_swf_url' => includes_url( 'js/plupload/plupload.flash.swf' ),  
  68. 'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),  
  69. 'filters' => array( 
  70. 'max_file_size' => $max_upload_size . 'b',  
  71. ),  
  72. 'multipart_params' => $post_params,  
  73. ); 
  74.  
  75. // Currently only iOS Safari supports multiple files uploading but iOS 7.x has a bug that prevents uploading of videos 
  76. // when enabled. See #29602. 
  77. if ( wp_is_mobile() && strpos( $_SERVER['HTTP_USER_AGENT'], 'OS 7_' ) !== false && 
  78. strpos( $_SERVER['HTTP_USER_AGENT'], 'like Mac OS X' ) !== false ) { 
  79.  
  80. $plupload_init['multi_selection'] = false; 
  81.  
  82. /** 
  83. * Filters the default Plupload settings. 
  84. * @since 3.3.0 
  85. * @param array $plupload_init An array of default settings used by Plupload. 
  86. */ 
  87. $plupload_init = apply_filters( 'plupload_init', $plupload_init ); 
  88.  
  89. ?> 
  90.  
  91. <script type="text/javascript"> 
  92. <?php 
  93. // Verify size is an int. If not return default value. 
  94. $large_size_h = absint( get_option('large_size_h') ); 
  95. if( !$large_size_h ) 
  96. $large_size_h = 1024; 
  97. $large_size_w = absint( get_option('large_size_w') ); 
  98. if( !$large_size_w ) 
  99. $large_size_w = 1024; 
  100. ?> 
  101. var resize_height = <?php echo $large_size_h; ?>, resize_width = <?php echo $large_size_w; ?>,  
  102. wpUploaderInit = <?php echo wp_json_encode( $plupload_init ); ?>; 
  103. </script> 
  104.  
  105. <div id="plupload-upload-ui" class="hide-if-no-js"> 
  106. <?php 
  107. /** 
  108. * Fires before the upload interface loads. 
  109. * @since 2.6.0 As 'pre-flash-upload-ui' 
  110. * @since 3.3.0 
  111. */ 
  112. do_action( 'pre-plupload-upload-ui' ); ?> 
  113. <div id="drag-drop-area"> 
  114. <div class="drag-drop-inside"> 
  115. <p class="drag-drop-info"><?php _e('Drop files here'); ?></p> 
  116. <p><?php _ex('or', 'Uploader: Drop files here - or - Select Files'); ?></p> 
  117. <p class="drag-drop-buttons"><input id="plupload-browse-button" type="button" value="<?php esc_attr_e('Select Files'); ?>" class="button" /></p> 
  118. </div> 
  119. </div> 
  120. <?php 
  121. /** 
  122. * Fires after the upload interface loads. 
  123. * @since 2.6.0 As 'post-flash-upload-ui' 
  124. * @since 3.3.0 
  125. */ 
  126. do_action( 'post-plupload-upload-ui' ); ?> 
  127. </div> 
  128.  
  129. <div id="html-upload-ui" class="hide-if-js"> 
  130. <?php 
  131. /** 
  132. * Fires before the upload button in the media upload interface. 
  133. * @since 2.6.0 
  134. */ 
  135. ?> 
  136. <p id="async-upload-wrap"> 
  137. <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label> 
  138. <input type="file" name="async-upload" id="async-upload" /> 
  139. <?php submit_button( __( 'Upload' ), 'primary', 'html-upload', false ); ?> 
  140. <a href="#" onclick="try{top.tb_remove();}catch(e) {}; return false;"><?php _e('Cancel'); ?></a> 
  141. </p> 
  142. <div class="clear"></div> 
  143. <?php 
  144. /** 
  145. * Fires after the upload button in the media upload interface. 
  146. * @since 2.6.0 
  147. */ 
  148. do_action( 'post-html-upload-ui' ); 
  149. ?> 
  150. </div> 
  151.  
  152. <p class="max-upload-size"><?php printf( __( 'Maximum upload file size: %s.' ), esc_html( size_format( $max_upload_size ) ) ); ?></p> 
  153. <?php 
  154.  
  155. /** 
  156. * Fires on the post upload UI screen. 
  157. * Legacy (pre-3.5.0) media workflow hook. 
  158. * @since 2.6.0 
  159. */