media_upload_type_form

Outputs the legacy media upload form for a given media type.

Description

media_upload_type_form( (string) $type = 'file', (constant) $errors = null, (constant) $id = null ); 

Parameters (3)

0. $type — Optional. (string) => 'file'
The type.
1. $errors — Optional. (constant) => null
The errors.
2. $id — Optional. (constant) => null
The id.

Usage

  1. if ( !function_exists( 'media_upload_type_form' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/media.php'; 
  3.  
  4. // The type. 
  5. $type = 'file'; 
  6.  
  7. // The errors. 
  8. $errors = null; 
  9.  
  10. // The id. 
  11. $id = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = media_upload_type_form($type, $errors, $id); 
  15.  

Defined (1)

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

/wp-admin/includes/media.php  
  1. function media_upload_type_form($type = 'file', $errors = null, $id = null) { 
  2.  
  3.  
  4. $post_id = isset( $_REQUEST['post_id'] )? intval( $_REQUEST['post_id'] ) : 0; 
  5.  
  6. $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id"); 
  7.  
  8. /** 
  9. * Filters the media upload form action URL. 
  10. * @since 2.6.0 
  11. * @param string $form_action_url The media upload form action URL. 
  12. * @param string $type The type of media. Default 'file'. 
  13. */ 
  14. $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); 
  15. $form_class = 'media-upload-form type-form validate'; 
  16.  
  17. if ( get_user_setting('uploader') ) 
  18. $form_class .= ' html-uploader'; 
  19. ?> 
  20.  
  21. <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"> 
  22. <?php submit_button( '', 'hidden', 'save', false ); ?> 
  23. <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> 
  24. <?php wp_nonce_field('media-form'); ?> 
  25.  
  26. <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3> 
  27.  
  28. <?php media_upload_form( $errors ); ?> 
  29.  
  30. <script type="text/javascript"> 
  31. jQuery(function($) { 
  32. var preloaded = $(".media-item.preloaded"); 
  33. if ( preloaded.length > 0 ) { 
  34. preloaded.each(function() {prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')}, '');}); 
  35. updateMediaForm(); 
  36. }); 
  37. </script> 
  38. <div id="media-items"><?php 
  39.  
  40. if ( $id ) { 
  41. if ( !is_wp_error($id) ) { 
  42. echo get_media_items( $id, $errors ); 
  43. } else { 
  44. echo '<div id="media-upload-error">'.esc_html($id->get_error_message()).'</div></div>'; 
  45. exit; 
  46. ?></div> 
  47.  
  48. <p class="savebutton ml-submit"> 
  49. <?php submit_button( __( 'Save all changes' ), '', 'save', false ); ?> 
  50. </p> 
  51. </form> 
  52. <?php