media_upload_type_url_form

Outputs the legacy media upload form for external media.

Description

media_upload_type_url_form( (constant) $type = null, (constant) $errors = null, (constant) $id = null ); 

Parameters (3)

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

Usage

  1. if ( !function_exists( 'media_upload_type_url_form' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/media.php'; 
  3.  
  4. // The type. 
  5. $type = null; 
  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_url_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_url_form($type = null, $errors = null, $id = null) { 
  2. if ( null === $type ) 
  3. $type = 'image'; 
  4.  
  5.  
  6. $post_id = isset( $_REQUEST['post_id'] ) ? intval( $_REQUEST['post_id'] ) : 0; 
  7.  
  8. $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id"); 
  9. /** This filter is documented in wp-admin/includes/media.php */ 
  10. $form_action_url = apply_filters( 'media_upload_form_url', $form_action_url, $type ); 
  11. $form_class = 'media-upload-form type-form validate'; 
  12.  
  13. if ( get_user_setting('uploader') ) 
  14. $form_class .= ' html-uploader'; 
  15. ?> 
  16.  
  17. <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"> 
  18. <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> 
  19. <?php wp_nonce_field('media-form'); ?> 
  20.  
  21. <h3 class="media-title"><?php _e('Insert media from another website'); ?></h3> 
  22.  
  23. <script type="text/javascript"> 
  24. var addExtImage = { 
  25.  
  26. width : '',  
  27. height : '',  
  28. align : 'alignnone',  
  29.  
  30. insert : function() { 
  31. var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = ''; 
  32.  
  33. if ( '' == f.src.value || '' == t.width ) 
  34. return false; 
  35.  
  36. if ( f.alt.value ) 
  37. alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); 
  38.  
  39. <?php 
  40. /** This filter is documented in wp-admin/includes/media.php */ 
  41. if ( ! apply_filters( 'disable_captions', '' ) ) { 
  42. ?> 
  43. if ( f.caption.value ) { 
  44. caption = f.caption.value.replace(/\r\n|\r/g, '\n'); 
  45. caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a) { 
  46. return a.replace(/[\r\n\t]+/, ' '); 
  47. }); 
  48.  
  49. caption = caption.replace(/\s*\n\s*/g, '<br />'); 
  50. <?php } ?> 
  51.  
  52. cls = caption ? '' : ' class="'+t.align+'"'; 
  53.  
  54. html = '<img alt="'+alt+'" src="'+f.src.value+'"'+cls+' width="'+t.width+'" height="'+t.height+'" />'; 
  55.  
  56. if ( f.url.value ) { 
  57. url = f.url.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>'); 
  58. html = '<a href="'+url+'">'+html+'</a>'; 
  59.  
  60. if ( caption ) 
  61. html = '[caption id="" align="'+t.align+'" width="'+t.width+'"]'+html+caption+'[/caption]'; 
  62.  
  63. var win = window.dialogArguments || opener || parent || top; 
  64. win.send_to_editor(html); 
  65. return false; 
  66. },  
  67.  
  68. resetImageData : function() { 
  69. var t = addExtImage; 
  70.  
  71. t.width = t.height = ''; 
  72. document.getElementById('go_button').style.color = '#bbb'; 
  73. if ( ! document.forms[0].src.value ) 
  74. document.getElementById('status_img').innerHTML = ''; 
  75. else document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/no.png' ) ); ?>" alt="" />'; 
  76. },  
  77.  
  78. updateImageData : function() { 
  79. var t = addExtImage; 
  80.  
  81. t.width = t.preloadImg.width; 
  82. t.height = t.preloadImg.height; 
  83. document.getElementById('go_button').style.color = '#333'; 
  84. document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/yes.png' ) ); ?>" alt="" />'; 
  85. },  
  86.  
  87. getImageData : function() { 
  88. if ( jQuery('table.describe').hasClass('not-image') ) 
  89. return; 
  90.  
  91. var t = addExtImage, src = document.forms[0].src.value; 
  92.  
  93. if ( ! src ) { 
  94. t.resetImageData(); 
  95. return false; 
  96.  
  97. document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/spinner-2x.gif' ) ); ?>" alt="" width="16" height="16" />'; 
  98. t.preloadImg = new Image(); 
  99. t.preloadImg.onload = t.updateImageData; 
  100. t.preloadImg.onerror = t.resetImageData; 
  101. t.preloadImg.src = src; 
  102. }; 
  103.  
  104. jQuery(document).ready( function($) { 
  105. $('.media-types input').click( function() { 
  106. $('table.describe').toggleClass('not-image', $('#not-image').prop('checked') ); 
  107. }); 
  108. }); 
  109. </script> 
  110.  
  111. <div id="media-items"> 
  112. <div class="media-item media-blank"> 
  113. <?php 
  114. /** 
  115. * Filters the insert media from URL form HTML. 
  116. * @since 3.3.0 
  117. * @param string $form_html The insert from URL form HTML. 
  118. */ 
  119. ?> 
  120. </div> 
  121. </div> 
  122. </form> 
  123. <?php