media_upload_type_form

Definition:
function media_upload_type_form($type = 'file', $errors = null, $id = null) {}

Parameters

  • unknown_type $type
  • unknown_type $errors
  • unknown_type $id

Defined filters

  • media_upload_form_url
    apply_filters('media_upload_form_url', $form_action_url, $type)

Source code

function media_upload_type_form($type = 'file', $errors = null, $id = null) {

	media_upload_header();



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



	$form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");

	$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);

?>



<form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form type-form validate" id="<?php echo $type; ?>-form">

<?php submit_button( '', 'hidden', 'save', false ); ?>

<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('Add media files from your computer'); ?></h3>



<?php media_upload_form( $errors ); ?>



<script type="text/javascript">

//<![CDATA[

jQuery(function($){

	var preloaded = $(".media-item.preloaded");

	if ( preloaded.length > 0 ) {

		preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});

	}

	updateMediaForm();

});

//]]>

</script>

<div id="media-items">

<?php

if ( $id ) {

	if ( !is_wp_error($id) ) {

		add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2);

		echo get_media_items( $id, $errors );

	} else {

		echo '<div id="media-upload-error">'.esc_html($id->get_error_message()).'</div>';

		exit;

	}

}

?>

</div>

<p class="savebutton ml-submit">

<?php submit_button( __( 'Save all changes' ), 'button', 'save', false ); ?>

</p>

</form>

<?php

}

2389

media_upload_tabs

Definition:
function media_upload_tabs() {}

Defined filters

  • media_upload_tabs
    apply_filters('media_upload_tabs', $_default_tabs)

Source code

function media_upload_tabs() {

	$_default_tabs = array(

		'type' => __('From Computer'), // handler action suffix => tab text

		'type_url' => __('From URL'),

		'gallery' => __('Gallery'),

		'library' => __('Media Library')

	);



	return apply_filters('media_upload_tabs', $_default_tabs);

}

2387

media_upload_library_form

Definition:
function media_upload_library_form($errors) {}

Parameters

  • unknown_type $errors

Defined filters

  • media_upload_form_url
    apply_filters('media_upload_form_url', $form_action_url, $type)
  • media_upload_mime_type_links
    apply_filters( 'media_upload_mime_type_links', $type_links )

Source code

function media_upload_library_form($errors) {

	global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;



	media_upload_header();



	$post_id = intval($_REQUEST['post_id']);



	$form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id");

	$form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);



	$_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0;

	if ( $_GET['paged'] < 1 )

		$_GET['paged'] = 1;

	$start = ( $_GET['paged'] - 1 ) * 10;

	if ( $start < 1 )

		$start = 0;

	add_filter( 'post_limits', create_function( '$a', "return 'LIMIT $start, 10';" ) );



	list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();



?>



<form id="filter" action="" method="get">

<input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" />

<input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" />

<input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />

<input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" />



<p id="media-search" class="search-box">

	<label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label>

	<input type="text" id="media-search-input" name="s" value="<?php the_search_query(); ?>" />

	<?php submit_button( __( 'Search Media' ), 'button', '', false ); ?>

</p>



<ul class="subsubsub">

<?php

$type_links = array();

$_num_posts = (array) wp_count_attachments();

$matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));

foreach ( $matches as $_type => $reals )

	foreach ( $reals as $real )

		if ( isset($num_posts[$_type]) )

			$num_posts[$_type] += $_num_posts[$real];

		else

			$num_posts[$_type] = $_num_posts[$real];

// If available type specified by media button clicked, filter by that type

if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) {

	$_GET['post_mime_type'] = $type;

	list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();

}

if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' )

	$class = ' class="current"';

else

	$class = '';

$type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>";

foreach ( $post_mime_types as $mime_type => $label ) {

	$class = '';



	if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )

		continue;



	if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )

		$class = ' class="current"';



	$type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . "'$class>" . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>';

}

echo implode(' | </li>', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '</li>';

unset($type_links);

?>

</ul>



<div class="tablenav">



<?php

$page_links = paginate_links( array(

	'base' => add_query_arg( 'paged', '%#%' ),

	'format' => '',

	'prev_text' => __('&laquo;'),

	'next_text' => __('&raquo;'),

	'total' => ceil($wp_query->found_posts / 10),

	'current' => $_GET['paged']

));



if ( $page_links )

	echo "<div class='tablenav-pages'>$page_links</div>";

?>



<div class="alignleft actions">

<?php



$arc_query = "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = 'attachment' ORDER BY post_date DESC";



$arc_result = $wpdb->get_results( $arc_query );



$month_count = count($arc_result);



if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>

<select name='m'>

<option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>

<?php

foreach ($arc_result as $arc_row) {

	if ( $arc_row->yyear == 0 )

		continue;

	$arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );



	if ( isset($_GET['m']) && ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] ) )

		$default = ' selected="selected"';

	else

		$default = '';



	echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>";

	echo esc_html( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" );

	echo "</option>\n";

}

?>

</select>

<?php } ?>



<?php submit_button( __( 'Filter »' ), 'secondary', 'post-query-submit', false ); ?>



</div>



<br class="clear" />

</div>

</form>



<form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form validate" id="library-form">



<?php wp_nonce_field('media-form'); ?>

<?php //media_upload_form( $errors ); ?>



<script type="text/javascript">

<!--

jQuery(function($){

	var preloaded = $(".media-item.preloaded");

	if ( preloaded.length > 0 ) {

		preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});

		updateMediaForm();

	}

});

-->

</script>



<div id="media-items">

<?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>

<?php echo get_media_items(null, $errors); ?>

</div>

<p class="ml-submit">

<?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false ); ?>

<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />

</p>

</form>

<?php

}

2385

media_upload_library

Definition:
function media_upload_library() {}

Source code

function media_upload_library() {

	$errors = array();

	if ( !empty($_POST) ) {

		$return = media_upload_form_handler();



		if ( is_string($return) )

			return $return;

		if ( is_array($return) )

			$errors = $return;

	}



	return wp_iframe( 'media_upload_library_form', $errors );

}

2383

media_upload_image

Definition:
function media_upload_image() {}

Defined filters

  • image_send_to_editor_url
    apply_filters('image_send_to_editor_url', $html, esc_url_raw($src)

Source code

function media_upload_image() {

	$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']) ) {

		$alt = $align = '';



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

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

			$src = "http://$src";

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

		if ( isset($_POST['insertonly']['align']) ) {

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

			$class = " class='align$align'";

		}

		if ( !empty($src) )

			$html = "<img src='" . esc_url($src) . "' alt='$alt'$class />";



		$html = apply_filters('image_send_to_editor_url', $html, esc_url_raw($src), $alt, $align);

		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', 'image', $errors, $id );



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

}

2381