media_upload_form

Definition:
function media_upload_form( $errors = null ) {}

Parameters

  • unknown_type $errors

Defined filters

  • flash_uploader
    apply_filters('flash_uploader', $flash)
  • swfupload_post_params
    apply_filters( 'swfupload_post_params', $post_params )
  • upload_file_glob
    apply_filters('upload_file_glob', '*.*')
  • swfupload_success_handler
    apply_filters( 'swfupload_success_handler', 'uploadSuccess' )

Defined actions

  • pre-upload-ui
    do_action('pre-upload-ui');
  • pre-flash-upload-ui
    do_action('pre-flash-upload-ui');
  • post-flash-upload-ui
    do_action('post-flash-upload-ui');
  • pre-html-upload-ui
    do_action('pre-html-upload-ui');
  • post-html-upload-ui
    do_action('post-html-upload-ui', $flash);
  • post-upload-ui
    do_action('post-upload-ui');

Source code

function media_upload_form( $errors = null ) {

	global $type, $tab, $pagenow;



	$flash_action_url = admin_url('async-upload.php');



	// If Mac and mod_security, no Flash. 😦

	$flash = true;

	if ( false !== stripos($_SERVER['HTTP_USER_AGENT'], 'mac') && apache_mod_loaded('mod_security') )

		$flash = false;



	$flash = apply_filters('flash_uploader', $flash);

	$post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;



	$upload_size_unit = $max_upload_size =  wp_max_upload_size();

	$sizes = array( 'KB', 'MB', 'GB' );

	for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ )

		$upload_size_unit /= 1024;

	if ( $u < 0 ) {

		$upload_size_unit = 0;

		$u = 0;

	} else {

		$upload_size_unit = (int) $upload_size_unit;

	}

?>

<script type="text/javascript">

//<![CDATA[

var uploaderMode = 0;

jQuery(document).ready(function($){

	uploaderMode = getUserSetting('uploader');

	$('.upload-html-bypass a').click(function(){deleteUserSetting('uploader');uploaderMode=0;swfuploadPreLoad();return false;});

	$('.upload-flash-bypass a').click(function(){setUserSetting('uploader', '1');uploaderMode=1;swfuploadPreLoad();return false;});

});

//]]>

</script>

<div id="media-upload-notice">

<?php if (isset($errors['upload_notice']) ) { ?>

	<?php echo $errors['upload_notice']; ?>

<?php } ?>

</div>

<div id="media-upload-error">

<?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?>

	<?php echo $errors['upload_error']->get_error_message(); ?>

<?php } ?>

</div>

<?php

// Check quota for this blog if multisite

if ( is_multisite() && !is_upload_space_available() ) {

	echo '<p>' . sprintf( __( 'Sorry, you have filled your storage quota (%s MB).' ), get_space_allowed() ) . '</p>';

	return;

}



do_action('pre-upload-ui');



if ( $flash ) :



// Set the post params, which SWFUpload will post back with the file, and pass

// them through a filter.

$post_params = array(

		"post_id" => $post_id,

		"auth_cookie" => (is_ssl() ? $_COOKIE[SECURE_AUTH_COOKIE] : $_COOKIE[AUTH_COOKIE]),

		"logged_in_cookie" => $_COOKIE[LOGGED_IN_COOKIE],

		"_wpnonce" => wp_create_nonce('media-form'),

		"type" => $type,

		"tab" => $tab,

		"short" => "1",

);

$post_params = apply_filters( 'swfupload_post_params', $post_params );

$p = array();

foreach ( $post_params as $param => $val )

	$p[] = "\t\t'$param' : '$val'";

$post_params_str = implode( ", \n", $p );



// #8545. wmode=transparent cannot be used with SWFUpload

if ( 'media-new.php' == $pagenow ) {

	$upload_image_path = get_user_option( 'admin_color' );

	if ( 'classic' != $upload_image_path )

		$upload_image_path = 'fresh';

	$upload_image_path = admin_url( 'images/upload-' . $upload_image_path . '.png?ver=20101205' );

} else {

	$upload_image_path = includes_url( 'images/upload.png?ver=20100531' );

}



?>

<script type="text/javascript">

//<![CDATA[

var swfu;

SWFUpload.onload = function() {

	var settings = {

			button_text: '<span class="button"><?php _e('Select Files'); ?><\/span>',

			button_text_style: '.button { text-align: center; font-weight: bold; font-family:"Lucida Grande",Verdana,Arial,"Bitstream Vera Sans",sans-serif; font-size: 11px; text-shadow: 0 1px 0 #FFFFFF; color:#464646; }',

			button_height: "23",

			button_width: "132",

			button_text_top_padding: 3,

			button_image_url: '<?php echo $upload_image_path; ?>',

			button_placeholder_id: "flash-browse-button",

			upload_url : "<?php echo esc_attr( $flash_action_url ); ?>",

			flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>",

			file_post_name: "async-upload",

			file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>",

			post_params : {

				<?php echo $post_params_str; ?>

			},

			file_size_limit : "<?php echo $max_upload_size; ?>b",

			file_dialog_start_handler : fileDialogStart,

			file_queued_handler : fileQueued,

			upload_start_handler : uploadStart,

			upload_progress_handler : uploadProgress,

			upload_error_handler : uploadError,

			upload_success_handler : <?php echo apply_filters( 'swfupload_success_handler', 'uploadSuccess' ); ?>,

			upload_complete_handler : uploadComplete,

			file_queue_error_handler : fileQueueError,

			file_dialog_complete_handler : fileDialogComplete,

			swfupload_pre_load_handler: swfuploadPreLoad,

			swfupload_load_failed_handler: swfuploadLoadFailed,

			custom_settings : {

				degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable

				swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available

			},

			debug: false

		};

		swfu = new SWFUpload(settings);

};

//]]>

</script>



<div id="flash-upload-ui" class="hide-if-no-js">

<?php do_action('pre-flash-upload-ui'); ?>



	<div>

	<?php _e( 'Choose files to upload' ); ?>

	<div id="flash-browse-button"></div>

	<span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" /></span>

	</div>

	<p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p>

<?php do_action('post-flash-upload-ui'); ?>

	<p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>

</div>

<?php endif; // $flash ?>



<div id="html-upload-ui" <?php if ( $flash ) echo 'class="hide-if-js"'; ?>>

<?php do_action('pre-html-upload-ui'); ?>

	<p id="async-upload-wrap">

		<label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label>

		<input type="file" name="async-upload" id="async-upload" />

		<?php submit_button( __( 'Upload' ), 'button', 'html-upload', false ); ?>

		<a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a>

	</p>

	<div class="clear"></div>

	<p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p>

	<?php if ( is_lighttpd_before_150() ): ?>

	<p><?php _e('If you want to use all capabilities of the uploader, like uploading multiple files at once, please update to lighttpd 1.5.'); ?></p>

	<?php endif;?>

<?php do_action('post-html-upload-ui', $flash); ?>

</div>

<?php do_action('post-upload-ui'); ?>

<?php

}

2369

media_upload_flash_bypass

Definition:
function media_upload_flash_bypass() {}

Source code

function media_upload_flash_bypass() {

	echo '<p class="upload-flash-bypass">';

	printf( __('You are using the Flash uploader.  Problems?  Try the <a href="%s">Browser uploader</a> instead.'), esc_url(add_query_arg('flash', 0)) );

	echo '</p>';

}

2367

media_upload_file

Definition:
function media_upload_file() {}

Defined filters

  • file_send_to_editor_url
    apply_filters('file_send_to_editor_url', $html, esc_url_raw($href)

Source code

function media_upload_file() {

	$errors = array();

	$id = 0;



	if ( isset($_POST['html-upload']) && !empty($_FILES) ) {

		check_admin_referer('media-form');

		// Upload File button was clicked

		$id = media_handle_upload('async-upload', $_REQUEST['post_id']);

		unset($_FILES);

		if ( is_wp_error($id) ) {

			$errors['upload_error'] = $id;

			$id = false;

		}

	}



	if ( !empty($_POST['insertonlybutton']) ) {

		$href = $_POST['insertonly']['href'];

		if ( !empty($href) && !strpos($href, '://') )

			$href = "http://$href";



		$title = esc_attr($_POST['insertonly']['title']);

		if ( empty($title) )

			$title = basename($href);

		if ( !empty($title) && !empty($href) )

			$html = "<a href='" . esc_url($href) . "' >$title</a>";

		$html = apply_filters('file_send_to_editor_url', $html, esc_url_raw($href), $title);

		return media_send_to_editor($html);

	}



	if ( !empty($_POST) ) {

		$return = media_upload_form_handler();



		if ( is_string($return) )

			return $return;

		if ( is_array($return) )

			$errors = $return;

	}



	if ( isset($_POST['save']) ) {

		$errors['upload_notice'] = __('Saved.');

		return media_upload_gallery();

	}



	if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )

		return wp_iframe( 'media_upload_type_url_form', 'file', $errors, $id );



	return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );

}

2365

media_upload_bypass_url

Definition:
function media_upload_bypass_url($url) {}

Make sure the GET parameter sticks when we submit a form.

Parameters

  • unknown_type $url

Source code

function media_upload_bypass_url($url) {

	if ( array_key_exists('flash', $_REQUEST) )

		$url = add_query_arg('flash', intval($_REQUEST['flash']));

	return $url;

}

2363

media_upload_audio

Definition:
function media_upload_audio() {}

Defined filters

  • audio_send_to_editor_url
    apply_filters('audio_send_to_editor_url', $html, $href, $title)

Source code

function media_upload_audio() {

	$errors = array();

	$id = 0;



	if ( isset($_POST['html-upload']) && !empty($_FILES) ) {

		check_admin_referer('media-form');

		// Upload File button was clicked

		$id = media_handle_upload('async-upload', $_REQUEST['post_id']);

		unset($_FILES);

		if ( is_wp_error($id) ) {

			$errors['upload_error'] = $id;

			$id = false;

		}

	}



	if ( !empty($_POST['insertonlybutton']) ) {

		$href = $_POST['insertonly']['href'];

		if ( !empty($href) && !strpos($href, '://') )

			$href = "http://$href";



		$title = esc_attr($_POST['insertonly']['title']);

		if ( empty($title) )

            $title = esc_attr( basename($href) );



		if ( !empty($title) && !empty($href) )

            $html = "<a href='" . esc_url($href) . "' >$title</a>";



		$html = apply_filters('audio_send_to_editor_url', $html, $href, $title);



		return media_send_to_editor($html);

	}



	if ( !empty($_POST) ) {

		$return = media_upload_form_handler();



		if ( is_string($return) )

			return $return;

		if ( is_array($return) )

			$errors = $return;

	}



	if ( isset($_POST['save']) ) {

		$errors['upload_notice'] = __('Saved.');

		return media_upload_gallery();

	}



	if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )

		return wp_iframe( 'media_upload_type_url_form', 'audio', $errors, $id );



	return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );

}

2361