media_upload_type_url_form

函式
media_upload_type_url_form ( $type = null, $errors = null, $id = null )
引數
  • (string) $type
    Required:
    Default: null
  • (object) $errors
    Required:
    Default: null
  • (int) $id
    Required:
    Default: null
定義位置
相關方法
media_upload_type_formmedia_upload_formmedia_upload_gallery_formmedia_upload_library_formmedia_upload_text_after
引入
2.7.0
棄用
-

media_upload_type_url_form – 這個函式用來顯示從一個URL上傳媒體檔案的表單。

輸出外部媒體的傳統媒體上傳表格。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function media_upload_type_url_form( $type = null, $errors = null, $id = null ) {
if ( null === $type ) {
$type = 'image';
}
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=type&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 type-form validate';
if ( get_user_setting( 'uploader' ) ) {
$form_class .= ' html-uploader';
}
?>
<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">
<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
<?php wp_nonce_field( 'media-form' ); ?>
<h3 class="media-title"><?php _e( 'Insert media from another website' ); ?></h3>
<script type="text/javascript">
var addExtImage = {
width : '',
height : '',
align : 'alignnone',
insert : function() {
var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = '';
if ( '' === f.src.value || '' === t.width )
return false;
if ( f.alt.value )
alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
<?php
/** This filter is documented in wp-admin/includes/media.php */
if ( ! apply_filters( 'disable_captions', '' ) ) {
?>
if ( f.caption.value ) {
caption = f.caption.value.replace(/rn|r/g, 'n');
caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){
return a.replace(/[rnt]+/, ' ');
});
caption = caption.replace(/s*ns*/g, '<br />');
}
<?php
}
?>
cls = caption ? '' : ' class="'+t.align+'"';
html = '<img alt="'+alt+'" src="'+f.src.value+'"'+cls+' width="'+t.width+'" height="'+t.height+'" />';
if ( f.url.value ) {
url = f.url.value.replace(/'/g, ''').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
html = '<a href="'+url+'">'+html+'</a>';
}
if ( caption )
html = ''+html+caption+'';
var win = window.dialogArguments || opener || parent || top;
win.send_to_editor(html);
return false;
},
resetImageData : function() {
var t = addExtImage;
t.width = t.height = '';
document.getElementById('go_button').style.color = '#bbb';
if ( ! document.forms[0].src.value )
document.getElementById('status_img').innerHTML = '';
else document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/no.png' ) ); ?>" alt="" />';
},
updateImageData : function() {
var t = addExtImage;
t.width = t.preloadImg.width;
t.height = t.preloadImg.height;
document.getElementById('go_button').style.color = '#333';
document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/yes.png' ) ); ?>" alt="" />';
},
getImageData : function() {
if ( jQuery('table.describe').hasClass('not-image') )
return;
var t = addExtImage, src = document.forms[0].src.value;
if ( ! src ) {
t.resetImageData();
return false;
}
document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/spinner-2x.gif' ) ); ?>" alt="" width="16" height="16" />';
t.preloadImg = new Image();
t.preloadImg.onload = t.updateImageData;
t.preloadImg.onerror = t.resetImageData;
t.preloadImg.src = src;
}
};
jQuery( function($) {
$('.media-types input').click( function() {
$('table.describe').toggleClass('not-image', $('#not-image').prop('checked') );
});
} );
</script>
<div id="media-items">
<div class="media-item media-blank">
<?php
/**
* Filters the insert media from URL form HTML.
*
* @since 3.3.0
*
* @param string $form_html The insert from URL form HTML.
*/
echo apply_filters( 'type_url_form_media', wp_media_insert_url_form( $type ) );
?>
</div>
</div>
</form>
<?php
}
function media_upload_type_url_form( $type = null, $errors = null, $id = null ) { if ( null === $type ) { $type = 'image'; } 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=type&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 type-form validate'; if ( get_user_setting( 'uploader' ) ) { $form_class .= ' html-uploader'; } ?> <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"> <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" /> <?php wp_nonce_field( 'media-form' ); ?> <h3 class="media-title"><?php _e( 'Insert media from another website' ); ?></h3> <script type="text/javascript"> var addExtImage = { width : '', height : '', align : 'alignnone', insert : function() { var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = ''; if ( '' === f.src.value || '' === t.width ) return false; if ( f.alt.value ) alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); <?php /** This filter is documented in wp-admin/includes/media.php */ if ( ! apply_filters( 'disable_captions', '' ) ) { ?> if ( f.caption.value ) { caption = f.caption.value.replace(/rn|r/g, 'n'); caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){ return a.replace(/[rnt]+/, ' '); }); caption = caption.replace(/s*ns*/g, '<br />'); } <?php } ?> cls = caption ? '' : ' class="'+t.align+'"'; html = '<img alt="'+alt+'" src="'+f.src.value+'"'+cls+' width="'+t.width+'" height="'+t.height+'" />'; if ( f.url.value ) { url = f.url.value.replace(/'/g, ''').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;'); html = '<a href="'+url+'">'+html+'</a>'; } if ( caption ) html = ''+html+caption+''; var win = window.dialogArguments || opener || parent || top; win.send_to_editor(html); return false; }, resetImageData : function() { var t = addExtImage; t.width = t.height = ''; document.getElementById('go_button').style.color = '#bbb'; if ( ! document.forms[0].src.value ) document.getElementById('status_img').innerHTML = ''; else document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/no.png' ) ); ?>" alt="" />'; }, updateImageData : function() { var t = addExtImage; t.width = t.preloadImg.width; t.height = t.preloadImg.height; document.getElementById('go_button').style.color = '#333'; document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/yes.png' ) ); ?>" alt="" />'; }, getImageData : function() { if ( jQuery('table.describe').hasClass('not-image') ) return; var t = addExtImage, src = document.forms[0].src.value; if ( ! src ) { t.resetImageData(); return false; } document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/spinner-2x.gif' ) ); ?>" alt="" width="16" height="16" />'; t.preloadImg = new Image(); t.preloadImg.onload = t.updateImageData; t.preloadImg.onerror = t.resetImageData; t.preloadImg.src = src; } }; jQuery( function($) { $('.media-types input').click( function() { $('table.describe').toggleClass('not-image', $('#not-image').prop('checked') ); }); } ); </script> <div id="media-items"> <div class="media-item media-blank"> <?php /** * Filters the insert media from URL form HTML. * * @since 3.3.0 * * @param string $form_html The insert from URL form HTML. */ echo apply_filters( 'type_url_form_media', wp_media_insert_url_form( $type ) ); ?> </div> </div> </form> <?php }
function media_upload_type_url_form( $type = null, $errors = null, $id = null ) {
	if ( null === $type ) {
		$type = 'image';
	}

	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=type&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 type-form validate';

	if ( get_user_setting( 'uploader' ) ) {
		$form_class .= ' html-uploader';
	}

	?>
	<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">
	<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
		<?php wp_nonce_field( 'media-form' ); ?>

	<h3 class="media-title"><?php _e( 'Insert media from another website' ); ?></h3>

	<script type="text/javascript">
	var addExtImage = {

	width : '',
	height : '',
	align : 'alignnone',

	insert : function() {
		var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = '';

		if ( '' === f.src.value || '' === t.width )
			return false;

		if ( f.alt.value )
			alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');

		<?php
		/** This filter is documented in wp-admin/includes/media.php */
		if ( ! apply_filters( 'disable_captions', '' ) ) {
			?>
			if ( f.caption.value ) {
				caption = f.caption.value.replace(/rn|r/g, 'n');
				caption = caption.replace(/<[a-zA-Z0-9]+( [^<>]+)?>/g, function(a){
					return a.replace(/[rnt]+/, ' ');
				});

				caption = caption.replace(/s*ns*/g, '<br />');
			}
			<?php
		}

		?>
		cls = caption ? '' : ' class="'+t.align+'"';

		html = '<img alt="'+alt+'" src="'+f.src.value+'"'+cls+' width="'+t.width+'" height="'+t.height+'" />';

		if ( f.url.value ) {
			url = f.url.value.replace(/'/g, ''').replace(/"/g, '&quot;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
			html = '<a href="'+url+'">'+html+'</a>';
		}

		if ( caption )
			html = ''+html+caption+'';

		var win = window.dialogArguments || opener || parent || top;
		win.send_to_editor(html);
		return false;
	},

	resetImageData : function() {
		var t = addExtImage;

		t.width = t.height = '';
		document.getElementById('go_button').style.color = '#bbb';
		if ( ! document.forms[0].src.value )
			document.getElementById('status_img').innerHTML = '';
		else document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/no.png' ) ); ?>" alt="" />';
	},

	updateImageData : function() {
		var t = addExtImage;

		t.width = t.preloadImg.width;
		t.height = t.preloadImg.height;
		document.getElementById('go_button').style.color = '#333';
		document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/yes.png' ) ); ?>" alt="" />';
	},

	getImageData : function() {
		if ( jQuery('table.describe').hasClass('not-image') )
			return;

		var t = addExtImage, src = document.forms[0].src.value;

		if ( ! src ) {
			t.resetImageData();
			return false;
		}

		document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/spinner-2x.gif' ) ); ?>" alt="" width="16" height="16" />';
		t.preloadImg = new Image();
		t.preloadImg.onload = t.updateImageData;
		t.preloadImg.onerror = t.resetImageData;
		t.preloadImg.src = src;
	}
	};

	jQuery( function($) {
		$('.media-types input').click( function() {
			$('table.describe').toggleClass('not-image', $('#not-image').prop('checked') );
		});
	} );
	</script>

	<div id="media-items">
	<div class="media-item media-blank">
	<?php
	/**
	 * Filters the insert media from URL form HTML.
	 *
	 * @since 3.3.0
	 *
	 * @param string $form_html The insert from URL form HTML.
	 */
	echo apply_filters( 'type_url_form_media', wp_media_insert_url_form( $type ) );

	?>
	</div>
	</div>
	</form>
	<?php
}

常見問題

FAQs
檢視更多 >