3 * WordPress Administration Media API.
6 * @subpackage Administration
10 * {@internal Missing Short Description}}
16 function media_upload_tabs() {
17 $_default_tabs = array(
18 'type' => __('From Computer'), // handler action suffix => tab text
19 'type_url' => __('From URL'),
20 'gallery' => __('Gallery'),
21 'library' => __('Media Library')
24 return apply_filters('media_upload_tabs', $_default_tabs);
28 * {@internal Missing Short Description}}
32 * @param unknown_type $tabs
35 function update_gallery_tab($tabs) {
38 if ( !isset($_REQUEST['post_id']) ) {
39 unset($tabs['gallery']);
43 $post_id = intval($_REQUEST['post_id']);
46 $attachments = intval( $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ) );
48 if ( empty($attachments) ) {
49 unset($tabs['gallery']);
53 $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");
57 add_filter('media_upload_tabs', 'update_gallery_tab');
60 * {@internal Missing Short Description}}
64 function the_media_upload_tabs() {
66 $tabs = media_upload_tabs();
68 if ( !empty($tabs) ) {
69 echo "<ul id='sidemenu'>\n";
70 if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) )
71 $current = $redir_tab;
72 elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) )
73 $current = $_GET['tab'];
75 $current = apply_filters('media_upload_default_tab', 'type');
77 foreach ( $tabs as $callback => $text ) {
79 if ( $current == $callback )
80 $class = " class='current'";
81 $href = add_query_arg(array('tab'=>$callback, 's'=>false, 'paged'=>false, 'post_mime_type'=>false, 'm'=>false));
82 $link = "<a href='" . esc_url($href) . "'$class>$text</a>";
83 echo "\t<li id='" . esc_attr("tab-$callback") . "'>$link</li>\n";
90 * {@internal Missing Short Description}}
94 * @param unknown_type $id
95 * @param unknown_type $alt
96 * @param unknown_type $title
97 * @param unknown_type $align
98 * @param unknown_type $url
99 * @param unknown_type $rel
100 * @param unknown_type $size
103 function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') {
105 $html = get_image_tag($id, $alt, $title, $align, $size);
107 $rel = $rel ? ' rel="attachment wp-att-' . esc_attr($id).'"' : '';
110 $html = '<a href="' . esc_attr($url) . "\"$rel>$html</a>";
112 $html = apply_filters( 'image_send_to_editor', $html, $id, $caption, $title, $align, $url, $size, $alt );
118 * {@internal Missing Short Description}}
122 * @param unknown_type $html
123 * @param unknown_type $id
124 * @param unknown_type $alt
125 * @param unknown_type $title
126 * @param unknown_type $align
127 * @param unknown_type $url
128 * @param unknown_type $size
131 function image_add_caption( $html, $id, $caption, $title, $align, $url, $size, $alt = '' ) {
133 if ( empty($caption) || apply_filters( 'disable_captions', '' ) )
136 $id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
138 if ( ! preg_match( '/width="([0-9]+)/', $html, $matches ) )
141 $width = $matches[1];
143 $html = preg_replace( '/(class=["\'][^\'"]*)align(none|left|right|center)\s?/', '$1', $html );
147 $shcode = '[caption id="' . $id . '" align="align' . $align
148 . '" width="' . $width . '" caption="' . addslashes($caption) . '"]' . $html . '[/caption]';
150 return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
152 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 8 );
155 * {@internal Missing Short Description}}
159 * @param unknown_type $html
161 function media_send_to_editor($html) {
163 <script type="text/javascript">
165 var win = window.dialogArguments || opener || parent || top;
166 win.send_to_editor('<?php echo addslashes($html); ?>');
174 * {@internal Missing Short Description}}
176 * This handles the file upload POST itself, creating the attachment post.
180 * @param string $file_id Index into the {@link $_FILES} array of the upload
181 * @param int $post_id The post ID the media is associated with
182 * @param array $post_data allows you to overwrite some of the attachment
183 * @param array $overrides allows you to override the {@link wp_handle_upload()} behavior
184 * @return int the ID of the attachment
186 function media_handle_upload($file_id, $post_id, $post_data = array(), $overrides = array( 'test_form' => false )) {
188 $time = current_time('mysql');
189 if ( $post = get_post($post_id) ) {
190 if ( substr( $post->post_date, 0, 4 ) > 0 )
191 $time = $post->post_date;
194 $name = $_FILES[$file_id]['name'];
195 $file = wp_handle_upload($_FILES[$file_id], $overrides, $time);
197 if ( isset($file['error']) )
198 return new WP_Error( 'upload_error', $file['error'] );
200 $name_parts = pathinfo($name);
201 $name = trim( substr( $name, 0, -(1 + strlen($name_parts['extension'])) ) );
204 $type = $file['type'];
205 $file = $file['file'];
209 // use image exif/iptc data for title and caption defaults if possible
210 if ( $image_meta = @wp_read_image_metadata($file) ) {
211 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
212 $title = $image_meta['title'];
213 if ( trim( $image_meta['caption'] ) )
214 $content = $image_meta['caption'];
217 // Construct the attachment array
218 $attachment = array_merge( array(
219 'post_mime_type' => $type,
221 'post_parent' => $post_id,
222 'post_title' => $title,
223 'post_content' => $content,
227 $id = wp_insert_attachment($attachment, $file, $post_id);
228 if ( !is_wp_error($id) ) {
229 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
237 * {@internal Missing Short Description}}
241 * @param unknown_type $file_array
242 * @param unknown_type $post_id
243 * @param unknown_type $desc
244 * @param unknown_type $post_data
247 function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
248 $overrides = array('test_form'=>false);
250 $file = wp_handle_sideload($file_array, $overrides);
251 if ( isset($file['error']) )
252 return new WP_Error( 'upload_error', $file['error'] );
255 $type = $file['type'];
256 $file = $file['file'];
257 $title = preg_replace('/\.[^.]+$/', '', basename($file));
260 // use image exif/iptc data for title and caption defaults if possible
261 if ( $image_meta = @wp_read_image_metadata($file) ) {
262 if ( trim( $image_meta['title'] ) && ! is_numeric( sanitize_title( $image_meta['title'] ) ) )
263 $title = $image_meta['title'];
264 if ( trim( $image_meta['caption'] ) )
265 $content = $image_meta['caption'];
270 // Construct the attachment array
271 $attachment = array_merge( array(
272 'post_mime_type' => $type,
274 'post_parent' => $post_id,
275 'post_title' => $title,
276 'post_content' => $content,
279 // Save the attachment metadata
280 $id = wp_insert_attachment($attachment, $file, $post_id);
281 if ( !is_wp_error($id) ) {
282 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
289 * {@internal Missing Short Description}}
291 * Wrap iframe content (produced by $content_func) in a doctype, html head/body
292 * etc any additional function args will be passed to content_func.
296 * @param unknown_type $content_func
298 function wp_iframe($content_func /* ... */) {
300 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
301 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
303 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
304 <title><?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — <?php _e('WordPress'); ?></title>
306 wp_enqueue_style( 'global' );
307 wp_enqueue_style( 'wp-admin' );
308 wp_enqueue_style( 'colors' );
309 // Check callback name for 'media'
310 if ( ( is_array( $content_func ) && ! empty( $content_func[1] ) && 0 === strpos( (string) $content_func[1], 'media' ) ) || 0 === strpos( $content_func, 'media' ) )
311 wp_enqueue_style( 'media' );
312 wp_enqueue_style( 'ie' );
314 <script type="text/javascript">
316 addLoadEvent = function(func){if(typeof jQuery!="undefined")jQuery(document).ready(func);else if(typeof wpOnload!='function'){wpOnload=func;}else{var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}};
317 var userSettings = {'url':'<?php echo SITECOOKIEPATH; ?>','uid':'<?php if ( ! isset($current_user) ) $current_user = wp_get_current_user(); echo $current_user->ID; ?>','time':'<?php echo time(); ?>'};
318 var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>', pagenow = 'media-upload-popup', adminpage = 'media-upload-popup';
322 do_action('admin_enqueue_scripts', 'media-upload-popup');
323 do_action('admin_print_styles-media-upload-popup');
324 do_action('admin_print_styles');
325 do_action('admin_print_scripts-media-upload-popup');
326 do_action('admin_print_scripts');
327 do_action('admin_head-media-upload-popup');
328 do_action('admin_head');
330 if ( is_string($content_func) )
331 do_action( "admin_head_{$content_func}" );
334 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>>
336 $args = func_get_args();
337 $args = array_slice($args, 1);
338 call_user_func_array($content_func, $args);
340 do_action('admin_print_footer_scripts');
342 <script type="text/javascript">if(typeof wpOnload=='function')wpOnload();</script>
349 * {@internal Missing Short Description}}
353 function media_buttons() {
354 $do_image = $do_audio = $do_video = true;
355 if ( is_multisite() ) {
356 $media_buttons = get_site_option( 'mu_media_buttons' );
357 if ( empty($media_buttons['image']) )
359 if ( empty($media_buttons['audio']) )
361 if ( empty($media_buttons['video']) )
367 $out .= _media_button(__('Add an Image'), 'images/media-button-image.gif?ver=20100531', 'image');
369 $out .= _media_button(__('Add Video'), 'images/media-button-video.gif?ver=20100531', 'video');
371 $out .= _media_button(__('Add Audio'), 'images/media-button-music.gif?ver=20100531', 'audio');
373 $out .= _media_button(__('Add Media'), 'images/media-button-other.gif?ver=20100531', 'media');
375 $context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
377 printf($context, $out);
379 add_action( 'media_buttons', 'media_buttons' );
381 function _media_button($title, $icon, $type) {
382 return "<a href='" . esc_url( get_upload_iframe_src($type) ) . "' id='add_$type' class='thickbox' title='$title'><img src='" . esc_url( admin_url( $icon ) ) . "' alt='$title' /></a>";
385 function get_upload_iframe_src($type) {
386 global $post_ID, $temp_ID;
387 $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
388 $upload_iframe_src = add_query_arg('post_id', $uploading_iframe_ID, 'media-upload.php');
390 if ( 'media' != $type )
391 $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src);
392 $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src);
394 return add_query_arg('TB_iframe', true, $upload_iframe_src);
398 * {@internal Missing Short Description}}
404 function media_upload_form_handler() {
405 check_admin_referer('media-form');
409 if ( isset($_POST['send']) ) {
410 $keys = array_keys($_POST['send']);
411 $send_id = (int) array_shift($keys);
414 if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
415 $post = $_post = get_post($attachment_id, ARRAY_A);
416 if ( isset($attachment['post_content']) )
417 $post['post_content'] = $attachment['post_content'];
418 if ( isset($attachment['post_title']) )
419 $post['post_title'] = $attachment['post_title'];
420 if ( isset($attachment['post_excerpt']) )
421 $post['post_excerpt'] = $attachment['post_excerpt'];
422 if ( isset($attachment['menu_order']) )
423 $post['menu_order'] = $attachment['menu_order'];
425 if ( isset($send_id) && $attachment_id == $send_id ) {
426 if ( isset($attachment['post_parent']) )
427 $post['post_parent'] = $attachment['post_parent'];
430 $post = apply_filters('attachment_fields_to_save', $post, $attachment);
432 if ( isset($attachment['image_alt']) ) {
433 $image_alt = get_post_meta($attachment_id, '_wp_attachment_image_alt', true);
434 if ( $image_alt != stripslashes($attachment['image_alt']) ) {
435 $image_alt = wp_strip_all_tags( stripslashes($attachment['image_alt']), true );
436 // update_meta expects slashed
437 update_post_meta( $attachment_id, '_wp_attachment_image_alt', addslashes($image_alt) );
441 if ( isset($post['errors']) ) {
442 $errors[$attachment_id] = $post['errors'];
443 unset($post['errors']);
446 if ( $post != $_post )
447 wp_update_post($post);
449 foreach ( get_attachment_taxonomies($post) as $t ) {
450 if ( isset($attachment[$t]) )
451 wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
455 if ( isset($_POST['insert-gallery']) || isset($_POST['update-gallery']) ) { ?>
456 <script type="text/javascript">
458 var win = window.dialogArguments || opener || parent || top;
466 if ( isset($send_id) ) {
467 $attachment = stripslashes_deep( $_POST['attachments'][$send_id] );
469 $html = $attachment['post_title'];
470 if ( !empty($attachment['url']) ) {
472 if ( strpos($attachment['url'], 'attachment_id') || get_attachment_link($send_id) == $attachment['url'] )
473 $rel = " rel='attachment wp-att-" . esc_attr($send_id) . "'";
474 $html = "<a href='{$attachment['url']}'$rel>$html</a>";
477 $html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
478 return media_send_to_editor($html);
485 * {@internal Missing Short Description}}
491 function media_upload_image() {
495 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
496 check_admin_referer('media-form');
497 // Upload File button was clicked
498 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
500 if ( is_wp_error($id) ) {
501 $errors['upload_error'] = $id;
506 if ( !empty($_POST['insertonlybutton']) ) {
509 $src = $_POST['insertonly']['src'];
510 if ( !empty($src) && !strpos($src, '://') )
511 $src = "http://$src";
512 $alt = esc_attr($_POST['insertonly']['alt']);
513 if ( isset($_POST['insertonly']['align']) ) {
514 $align = esc_attr($_POST['insertonly']['align']);
515 $class = " class='align$align'";
518 $html = "<img src='" . esc_url($src) . "' alt='$alt'$class />";
520 $html = apply_filters('image_send_to_editor_url', $html, esc_url_raw($src), $alt, $align);
521 return media_send_to_editor($html);
524 if ( !empty($_POST) ) {
525 $return = media_upload_form_handler();
527 if ( is_string($return) )
529 if ( is_array($return) )
533 if ( isset($_POST['save']) ) {
534 $errors['upload_notice'] = __('Saved.');
535 return media_upload_gallery();
538 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
539 return wp_iframe( 'media_upload_type_url_form', 'image', $errors, $id );
541 return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
545 * {@internal Missing Short Description}}
549 * @param unknown_type $file
550 * @param unknown_type $post_id
551 * @param unknown_type $desc
554 function media_sideload_image($file, $post_id, $desc = null) {
555 if (!empty($file) ) {
556 // Download file to temp location
557 $tmp = download_url($file);
559 // Set variables for storage
560 // fix file filename for query strings
561 preg_match('/[^\?]+\.(jpg|JPG|jpe|JPE|jpeg|JPEG|gif|GIF|png|PNG)/', $file, $matches);
562 $file_array['name'] = basename($matches[0]);
563 $file_array['tmp_name'] = $tmp;
565 // If error storing temporarily, unlink
566 if ( is_wp_error($tmp) ) {
567 @unlink($file_array['tmp_name']);
568 $file_array['tmp_name'] = '';
571 // do the validation and storage stuff
572 $id = media_handle_sideload($file_array, $post_id, @$desc);
575 // If error storing permanently, unlink
576 if ( is_wp_error($id) ) {
577 @unlink($file_array['tmp_name']);
582 // Finally check to make sure the file has been saved, then return the html
583 if ( !empty($src) ) {
585 $html = "<img src='$src' alt='$alt' />";
591 * {@internal Missing Short Description}}
597 function media_upload_audio() {
601 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
602 check_admin_referer('media-form');
603 // Upload File button was clicked
604 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
606 if ( is_wp_error($id) ) {
607 $errors['upload_error'] = $id;
612 if ( !empty($_POST['insertonlybutton']) ) {
613 $href = $_POST['insertonly']['href'];
614 if ( !empty($href) && !strpos($href, '://') )
615 $href = "http://$href";
617 $title = esc_attr($_POST['insertonly']['title']);
619 $title = esc_attr( basename($href) );
621 if ( !empty($title) && !empty($href) )
622 $html = "<a href='" . esc_url($href) . "' >$title</a>";
624 $html = apply_filters('audio_send_to_editor_url', $html, $href, $title);
626 return media_send_to_editor($html);
629 if ( !empty($_POST) ) {
630 $return = media_upload_form_handler();
632 if ( is_string($return) )
634 if ( is_array($return) )
638 if ( isset($_POST['save']) ) {
639 $errors['upload_notice'] = __('Saved.');
640 return media_upload_gallery();
643 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
644 return wp_iframe( 'media_upload_type_url_form', 'audio', $errors, $id );
646 return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
650 * {@internal Missing Short Description}}
656 function media_upload_video() {
660 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
661 check_admin_referer('media-form');
662 // Upload File button was clicked
663 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
665 if ( is_wp_error($id) ) {
666 $errors['upload_error'] = $id;
671 if ( !empty($_POST['insertonlybutton']) ) {
672 $href = $_POST['insertonly']['href'];
673 if ( !empty($href) && !strpos($href, '://') )
674 $href = "http://$href";
676 $title = esc_attr($_POST['insertonly']['title']);
678 $title = esc_attr( basename($href) );
680 if ( !empty($title) && !empty($href) )
681 $html = "<a href='" . esc_url($href) . "' >$title</a>";
683 $html = apply_filters('video_send_to_editor_url', $html, $href, $title);
685 return media_send_to_editor($html);
688 if ( !empty($_POST) ) {
689 $return = media_upload_form_handler();
691 if ( is_string($return) )
693 if ( is_array($return) )
697 if ( isset($_POST['save']) ) {
698 $errors['upload_notice'] = __('Saved.');
699 return media_upload_gallery();
702 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
703 return wp_iframe( 'media_upload_type_url_form', 'video', $errors, $id );
705 return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
709 * {@internal Missing Short Description}}
715 function media_upload_file() {
719 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
720 check_admin_referer('media-form');
721 // Upload File button was clicked
722 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
724 if ( is_wp_error($id) ) {
725 $errors['upload_error'] = $id;
730 if ( !empty($_POST['insertonlybutton']) ) {
731 $href = $_POST['insertonly']['href'];
732 if ( !empty($href) && !strpos($href, '://') )
733 $href = "http://$href";
735 $title = esc_attr($_POST['insertonly']['title']);
737 $title = basename($href);
738 if ( !empty($title) && !empty($href) )
739 $html = "<a href='" . esc_url($href) . "' >$title</a>";
740 $html = apply_filters('file_send_to_editor_url', $html, esc_url_raw($href), $title);
741 return media_send_to_editor($html);
744 if ( !empty($_POST) ) {
745 $return = media_upload_form_handler();
747 if ( is_string($return) )
749 if ( is_array($return) )
753 if ( isset($_POST['save']) ) {
754 $errors['upload_notice'] = __('Saved.');
755 return media_upload_gallery();
758 if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' )
759 return wp_iframe( 'media_upload_type_url_form', 'file', $errors, $id );
761 return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
765 * {@internal Missing Short Description}}
771 function media_upload_gallery() {
774 if ( !empty($_POST) ) {
775 $return = media_upload_form_handler();
777 if ( is_string($return) )
779 if ( is_array($return) )
783 wp_enqueue_script('admin-gallery');
784 return wp_iframe( 'media_upload_gallery_form', $errors );
788 * {@internal Missing Short Description}}
794 function media_upload_library() {
796 if ( !empty($_POST) ) {
797 $return = media_upload_form_handler();
799 if ( is_string($return) )
801 if ( is_array($return) )
805 return wp_iframe( 'media_upload_library_form', $errors );
809 * Retrieve HTML for the image alignment radio buttons with the specified one checked.
813 * @param unknown_type $post
814 * @param unknown_type $checked
817 function image_align_input_fields( $post, $checked = '' ) {
819 if ( empty($checked) )
820 $checked = get_user_setting('align', 'none');
822 $alignments = array('none' => __('None'), 'left' => __('Left'), 'center' => __('Center'), 'right' => __('Right'));
823 if ( !array_key_exists( (string) $checked, $alignments ) )
827 foreach ( $alignments as $name => $label ) {
828 $name = esc_attr($name);
829 $out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'".
830 ( $checked == $name ? " checked='checked'" : "" ) .
831 " /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>";
833 return join("\n", $out);
837 * Retrieve HTML for the size radio buttons with the specified one checked.
841 * @param unknown_type $post
842 * @param unknown_type $checked
845 function image_size_input_fields( $post, $check = '' ) {
847 // get a list of the actual pixel dimensions of each possible intermediate version of this image
848 $size_names = array('thumbnail' => __('Thumbnail'), 'medium' => __('Medium'), 'large' => __('Large'), 'full' => __('Full Size'));
851 $check = get_user_setting('imgsize', 'medium');
853 foreach ( $size_names as $size => $label ) {
854 $downsize = image_downsize($post->ID, $size);
857 // is this size selectable?
858 $enabled = ( $downsize[3] || 'full' == $size );
859 $css_id = "image-size-{$size}-{$post->ID}";
860 // if this size is the default but that's not available, don't select it
861 if ( $size == $check ) {
863 $checked = " checked='checked'";
866 } elseif ( !$check && $enabled && 'thumbnail' != $size ) {
867 // if $check is not enabled, default to the first available size that's bigger than a thumbnail
869 $checked = " checked='checked'";
872 $html = "<div class='image-size-item'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
874 $html .= "<label for='{$css_id}'>$label</label>";
875 // only show the dimensions if that choice is available
877 $html .= " <label for='{$css_id}' class='help'>" . sprintf( "(%d × %d)", $downsize[1], $downsize[2] ). "</label>";
885 'label' => __('Size'),
887 'html' => join("\n", $out),
892 * Retrieve HTML for the Link URL buttons with the default link type as specified.
896 * @param unknown_type $post
897 * @param unknown_type $url_type
900 function image_link_input_fields($post, $url_type = '') {
902 $file = wp_get_attachment_url($post->ID);
903 $link = get_attachment_link($post->ID);
905 if ( empty($url_type) )
906 $url_type = get_user_setting('urlbutton', 'post');
909 if ( $url_type == 'file' )
911 elseif ( $url_type == 'post' )
915 <input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr($url) . "' /><br />
916 <button type='button' class='button urlnone' title=''>" . __('None') . "</button>
917 <button type='button' class='button urlfile' title='" . esc_attr($file) . "'>" . __('File URL') . "</button>
918 <button type='button' class='button urlpost' title='" . esc_attr($link) . "'>" . __('Post URL') . "</button>
923 * {@internal Missing Short Description}}
927 * @param unknown_type $form_fields
928 * @param unknown_type $post
931 function image_attachment_fields_to_edit($form_fields, $post) {
932 if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
933 $alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true);
937 $form_fields['post_title']['required'] = true;
939 $form_fields['image_alt'] = array(
941 'label' => __('Alternate Text'),
942 'helps' => __('Alt text for the image, e.g. “The Mona Lisa”')
945 $form_fields['align'] = array(
946 'label' => __('Alignment'),
948 'html' => image_align_input_fields($post, get_option('image_default_align')),
951 $form_fields['image-size'] = image_size_input_fields( $post, get_option('image_default_size', 'medium') );
954 unset( $form_fields['image_alt'] );
959 add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2);
962 * {@internal Missing Short Description}}
966 * @param unknown_type $form_fields
967 * @param unknown_type $post
970 function media_single_attachment_fields_to_edit( $form_fields, $post ) {
971 unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
975 function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
976 unset($form_fields['image_url']);
981 * {@internal Missing Short Description}}
985 * @param unknown_type $post
986 * @param unknown_type $attachment
989 function image_attachment_fields_to_save($post, $attachment) {
990 if ( substr($post['post_mime_type'], 0, 5) == 'image' ) {
991 if ( strlen(trim($post['post_title'])) == 0 ) {
992 $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid']));
993 $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.');
1000 add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2);
1003 * {@internal Missing Short Description}}
1007 * @param unknown_type $html
1008 * @param unknown_type $attachment_id
1009 * @param unknown_type $attachment
1012 function image_media_send_to_editor($html, $attachment_id, $attachment) {
1013 $post =& get_post($attachment_id);
1014 if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
1015 $url = $attachment['url'];
1016 $align = !empty($attachment['align']) ? $attachment['align'] : 'none';
1017 $size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium';
1018 $alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : '';
1019 $rel = ( $url == get_attachment_link($attachment_id) );
1021 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt);
1027 add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3);
1030 * {@internal Missing Short Description}}
1034 * @param unknown_type $post
1035 * @param unknown_type $errors
1038 function get_attachment_fields_to_edit($post, $errors = null) {
1039 if ( is_int($post) )
1040 $post =& get_post($post);
1041 if ( is_array($post) )
1042 $post = (object) $post;
1044 $image_url = wp_get_attachment_url($post->ID);
1046 $edit_post = sanitize_post($post, 'edit');
1050 $form_fields = array(
1051 'post_title' => array(
1052 'label' => __('Title'),
1053 'value' => $edit_post->post_title
1055 'image_alt' => array(),
1056 'post_excerpt' => array(
1057 'label' => __('Caption'),
1058 'value' => $edit_post->post_excerpt
1060 'post_content' => array(
1061 'label' => __('Description'),
1062 'value' => $edit_post->post_content,
1063 'input' => 'textarea'
1066 'label' => __('Link URL'),
1068 'html' => image_link_input_fields($post, get_option('image_default_link_type')),
1069 'helps' => __('Enter a link URL or click above for presets.')
1071 'menu_order' => array(
1072 'label' => __('Order'),
1073 'value' => $edit_post->menu_order
1075 'image_url' => array(
1076 'label' => __('File URL'),
1078 'html' => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr($image_url) . "' /><br />",
1079 'value' => wp_get_attachment_url($post->ID),
1080 'helps' => __('Location of the uploaded file.')
1084 foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
1085 $t = (array) get_taxonomy($taxonomy);
1086 if ( empty($t['label']) )
1087 $t['label'] = $taxonomy;
1088 if ( empty($t['args']) )
1089 $t['args'] = array();
1091 $terms = get_object_term_cache($post->ID, $taxonomy);
1092 if ( empty($terms) )
1093 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
1097 foreach ( $terms as $term )
1098 $values[] = $term->name;
1099 $t['value'] = join(', ', $values);
1101 $form_fields[$taxonomy] = $t;
1104 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
1105 // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
1106 $form_fields = array_merge_recursive($form_fields, (array) $errors);
1108 $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
1110 return $form_fields;
1114 * Retrieve HTML for media items of post gallery.
1116 * The HTML markup retrieved will be created for the progress of SWF Upload
1117 * component. Will also create link for showing and hiding the form to modify
1118 * the image attachment.
1122 * @param int $post_id Optional. Post ID.
1123 * @param array $errors Errors for attachment, if any.
1126 function get_media_items( $post_id, $errors ) {
1127 $attachments = array();
1129 $post = get_post($post_id);
1130 if ( $post && $post->post_type == 'attachment' )
1131 $attachments = array($post->ID => $post);
1133 $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
1135 if ( is_array($GLOBALS['wp_the_query']->posts) )
1136 foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
1137 $attachments[$attachment->ID] = $attachment;
1141 foreach ( (array) $attachments as $id => $attachment ) {
1142 if ( $attachment->post_status == 'trash' )
1144 if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
1145 $output .= "\n<div id='media-item-$id' class='media-item child-of-$attachment->post_parent preloaded'><div class='progress'><div class='bar'></div></div><div id='media-upload-error-$id'></div><div class='filename'></div>$item\n</div>";
1152 * Retrieve HTML form for modifying the image attachment.
1156 * @param int $attachment_id Attachment ID for modification.
1157 * @param string|array $args Optional. Override defaults.
1158 * @return string HTML form for attachment.
1160 function get_media_item( $attachment_id, $args = null ) {
1163 if ( ( $attachment_id = intval( $attachment_id ) ) && $thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ) )
1164 $thumb_url = $thumb_url[0];
1168 $post = get_post( $attachment_id );
1170 $default_args = array( 'errors' => null, 'send' => post_type_supports(get_post_type($post->post_parent), 'editor'), 'delete' => true, 'toggle' => true, 'show_title' => true );
1171 $args = wp_parse_args( $args, $default_args );
1172 extract( $args, EXTR_SKIP );
1174 $toggle_on = __( 'Show' );
1175 $toggle_off = __( 'Hide' );
1177 $filename = basename( $post->guid );
1178 $title = esc_attr( $post->post_title );
1180 if ( $_tags = get_the_tags( $attachment_id ) ) {
1181 foreach ( $_tags as $tag )
1182 $tags[] = $tag->name;
1183 $tags = esc_attr( join( ', ', $tags ) );
1186 $post_mime_types = get_post_mime_types();
1187 $keys = array_keys( wp_match_mime_types( array_keys( $post_mime_types ), $post->post_mime_type ) );
1188 $type = array_shift( $keys );
1189 $type_html = "<input type='hidden' id='type-of-$attachment_id' value='" . esc_attr( $type ) . "' />";
1191 $form_fields = get_attachment_fields_to_edit( $post, $errors );
1194 $class = empty( $errors ) ? 'startclosed' : 'startopen';
1196 <a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
1197 <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
1199 $class = 'form-table';
1203 $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
1204 $display_title = $show_title ? "<div class='filename new'><span class='title'>" . wp_html_excerpt( $display_title, 60 ) . "</span></div>" : '';
1206 $gallery = ( ( isset( $_REQUEST['tab'] ) && 'gallery' == $_REQUEST['tab'] ) || ( isset( $redir_tab ) && 'gallery' == $redir_tab ) );
1209 foreach ( $form_fields as $key => $val ) {
1210 if ( 'menu_order' == $key ) {
1212 $order = "<div class='menu_order'> <input class='menu_order_input' type='text' id='attachments[$attachment_id][menu_order]' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ). "' /></div>";
1214 $order = "<input type='hidden' name='attachments[$attachment_id][menu_order]' value='" . esc_attr( $val['value'] ) . "' />";
1216 unset( $form_fields['menu_order'] );
1222 $meta = wp_get_attachment_metadata( $post->ID );
1223 if ( is_array( $meta ) && array_key_exists( 'width', $meta ) && array_key_exists( 'height', $meta ) )
1224 $media_dims .= "<span id='media-dims-$post->ID'>{$meta['width']} × {$meta['height']}</span> ";
1225 $media_dims = apply_filters( 'media_meta', $media_dims, $post );
1227 $image_edit_button = '';
1228 if ( gd_edit_image_support( $post->post_mime_type ) ) {
1229 $nonce = wp_create_nonce( "image_editor-$post->ID" );
1230 $image_edit_button = "<input type='button' id='imgedit-open-btn-$post->ID' onclick='imageEdit.open( $post->ID, \"$nonce\" )' class='button' value='" . esc_attr__( 'Edit Image' ) . "' /> <img src='" . esc_url( admin_url( 'images/wpspin_light.gif' ) ) . "' class='imgedit-wait-spin' alt='' />";
1233 $attachment_url = get_permalink( $attachment_id );
1240 <table class='slidetoggle describe $class'>
1241 <thead class='media-item-info' id='media-head-$post->ID'>
1243 <td class='A1B1' id='thumbnail-head-$post->ID'>
1244 <p><a href='$attachment_url' target='_blank'><img class='thumbnail' src='$thumb_url' alt='' style='margin-top: 3px' /></a></p>
1245 <p>$image_edit_button</p>
1248 <p><strong>" . __('File name:') . "</strong> $filename</p>
1249 <p><strong>" . __('File type:') . "</strong> $post->post_mime_type</p>
1250 <p><strong>" . __('Upload date:') . "</strong> " . mysql2date( get_option('date_format'), $post->post_date ). '</p>';
1251 if ( !empty( $media_dims ) )
1252 $item .= "<p><strong>" . __('Dimensions:') . "</strong> $media_dims</p>\n";
1254 $item .= "</td></tr>\n";
1261 <tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>
1262 <tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n";
1266 'required' => false,
1268 'extra_rows' => array(),
1272 $send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . esc_attr__( 'Insert into Post' ) . "' />";
1273 if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) {
1274 if ( !EMPTY_TRASH_DAYS ) {
1275 $delete = "<a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Delete Permanently' ) . '</a>';
1276 } elseif ( !MEDIA_TRASH ) {
1277 $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a>
1278 <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" . sprintf( __( 'You are about to delete <strong>%s</strong>.' ), $filename ) . "
1279 <a href='" . wp_nonce_url( "post.php?action=delete&post=$attachment_id", 'delete-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a>
1280 <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a>
1283 $delete = "<a href='" . wp_nonce_url( "post.php?action=trash&post=$attachment_id", 'trash-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a>
1284 <a href='" . wp_nonce_url( "post.php?action=untrash&post=$attachment_id", 'untrash-attachment_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo' ) . "</a>";
1291 $calling_post_id = 0;
1292 if ( isset( $_GET['post_id'] ) )
1293 $calling_post_id = absint( $_GET['post_id'] );
1294 elseif ( isset( $_POST ) && count( $_POST ) ) // Like for async-upload where $_GET['post_id'] isn't set
1295 $calling_post_id = $post->post_parent;
1296 if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) {
1297 $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" );
1298 $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html__( "Use as featured image" ) . "</a>";
1301 if ( ( $send || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) )
1302 $form_fields['buttons'] = array( 'tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $thumbnail $delete</td></tr>\n" );
1304 $hidden_fields = array();
1306 foreach ( $form_fields as $id => $field ) {
1307 if ( $id{0} == '_' )
1310 if ( !empty( $field['tr'] ) ) {
1311 $item .= $field['tr'];
1315 $field = array_merge( $defaults, $field );
1316 $name = "attachments[$attachment_id][$id]";
1318 if ( $field['input'] == 'hidden' ) {
1319 $hidden_fields[$name] = $field['value'];
1323 $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : '';
1324 $aria_required = $field['required'] ? " aria-required='true' " : '';
1326 $class .= $field['required'] ? ' form-required' : '';
1328 $item .= "\t\t<tr class='$class'>\n\t\t\t<th valign='top' scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label></th>\n\t\t\t<td class='field'>";
1329 if ( !empty( $field[ $field['input'] ] ) )
1330 $item .= $field[ $field['input'] ];
1331 elseif ( $field['input'] == 'textarea' ) {
1332 $item .= "<textarea type='text' id='$name' name='$name' $aria_required>" . esc_html( $field['value'] ) . '</textarea>';
1334 $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />";
1336 if ( !empty( $field['helps'] ) )
1337 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>';
1338 $item .= "</td>\n\t\t</tr>\n";
1340 $extra_rows = array();
1342 if ( !empty( $field['errors'] ) )
1343 foreach ( array_unique( (array) $field['errors'] ) as $error )
1344 $extra_rows['error'][] = $error;
1346 if ( !empty( $field['extra_rows'] ) )
1347 foreach ( $field['extra_rows'] as $class => $rows )
1348 foreach ( (array) $rows as $html )
1349 $extra_rows[$class][] = $html;
1351 foreach ( $extra_rows as $class => $rows )
1352 foreach ( $rows as $html )
1353 $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
1356 if ( !empty( $form_fields['_final'] ) )
1357 $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
1358 $item .= "\t</tbody>\n";
1359 $item .= "\t</table>\n";
1361 foreach ( $hidden_fields as $name => $value )
1362 $item .= "\t<input type='hidden' name='$name' id='$name' value='" . esc_attr( $value ) . "' />\n";
1364 if ( $post->post_parent < 1 && isset( $_REQUEST['post_id'] ) ) {
1365 $parent = (int) $_REQUEST['post_id'];
1366 $parent_name = "attachments[$attachment_id][post_parent]";
1367 $item .= "\t<input type='hidden' name='$parent_name' id='$parent_name' value='$parent' />\n";
1374 * {@internal Missing Short Description}}
1378 function media_upload_header() {
1380 <script type="text/javascript">post_id = <?php echo intval($_REQUEST['post_id']); ?>;</script>
1381 <div id="media-upload-header">
1382 <?php the_media_upload_tabs(); ?>
1388 * {@internal Missing Short Description}}
1392 * @param unknown_type $errors
1394 function media_upload_form( $errors = null ) {
1397 $flash_action_url = admin_url('async-upload.php');
1399 // If Mac and mod_security, no Flash. :(
1401 if ( false !== stripos($_SERVER['HTTP_USER_AGENT'], 'mac') && apache_mod_loaded('mod_security') )
1404 $flash = apply_filters('flash_uploader', $flash);
1405 $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
1407 $upload_size_unit = $max_upload_size = wp_max_upload_size();
1408 $sizes = array( 'KB', 'MB', 'GB' );
1409 for ( $u = -1; $upload_size_unit > 1024 && $u < count( $sizes ) - 1; $u++ )
1410 $upload_size_unit /= 1024;
1412 $upload_size_unit = 0;
1415 $upload_size_unit = (int) $upload_size_unit;
1418 <script type="text/javascript">
1420 var uploaderMode = 0;
1421 jQuery(document).ready(function($){
1422 uploaderMode = getUserSetting('uploader');
1423 $('.upload-html-bypass a').click(function(){deleteUserSetting('uploader');uploaderMode=0;swfuploadPreLoad();return false;});
1424 $('.upload-flash-bypass a').click(function(){setUserSetting('uploader', '1');uploaderMode=1;swfuploadPreLoad();return false;});
1428 <div id="media-upload-notice">
1429 <?php if (isset($errors['upload_notice']) ) { ?>
1430 <?php echo $errors['upload_notice']; ?>
1433 <div id="media-upload-error">
1434 <?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?>
1435 <?php echo $errors['upload_error']->get_error_message(); ?>
1439 // Check quota for this blog if multisite
1440 if ( is_multisite() && !is_upload_space_available() ) {
1441 echo '<p>' . sprintf( __( 'Sorry, you have filled your storage quota (%s MB).' ), get_space_allowed() ) . '</p>';
1445 do_action('pre-upload-ui');
1448 <script type="text/javascript">
1451 SWFUpload.onload = function() {
1453 button_text: '<span class="button"><?php _e('Select Files'); ?><\/span>',
1454 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; }',
1455 button_height: "23",
1456 button_width: "132",
1457 button_text_top_padding: 3,
1458 button_image_url: '<?php echo includes_url('images/upload.png?ver=20100531'); ?>',
1459 button_placeholder_id: "flash-browse-button",
1460 upload_url : "<?php echo esc_attr( $flash_action_url ); ?>",
1461 flash_url : "<?php echo includes_url('js/swfupload/swfupload.swf'); ?>",
1462 file_post_name: "async-upload",
1463 file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>",
1465 "post_id" : "<?php echo $post_id; ?>",
1466 "auth_cookie" : "<?php echo (is_ssl() ? $_COOKIE[SECURE_AUTH_COOKIE] : $_COOKIE[AUTH_COOKIE]); ?>",
1467 "logged_in_cookie": "<?php echo $_COOKIE[LOGGED_IN_COOKIE]; ?>",
1468 "_wpnonce" : "<?php echo wp_create_nonce('media-form'); ?>",
1469 "type" : "<?php echo $type; ?>",
1470 "tab" : "<?php echo $tab; ?>",
1473 file_size_limit : "<?php echo $max_upload_size; ?>b",
1474 file_dialog_start_handler : fileDialogStart,
1475 file_queued_handler : fileQueued,
1476 upload_start_handler : uploadStart,
1477 upload_progress_handler : uploadProgress,
1478 upload_error_handler : uploadError,
1479 upload_success_handler : uploadSuccess,
1480 upload_complete_handler : uploadComplete,
1481 file_queue_error_handler : fileQueueError,
1482 file_dialog_complete_handler : fileDialogComplete,
1483 swfupload_pre_load_handler: swfuploadPreLoad,
1484 swfupload_load_failed_handler: swfuploadLoadFailed,
1486 degraded_element_id : "html-upload-ui", // id of the element displayed when swfupload is unavailable
1487 swfupload_element_id : "flash-upload-ui" // id of the element displayed when swfupload is available
1491 swfu = new SWFUpload(settings);
1496 <div id="flash-upload-ui" class="hide-if-no-js">
1497 <?php do_action('pre-flash-upload-ui'); ?>
1500 <?php _e( 'Choose files to upload' ); ?>
1501 <div id="flash-browse-button"></div>
1502 <span><input id="cancel-upload" disabled="disabled" onclick="cancelUpload()" type="button" value="<?php esc_attr_e('Cancel Upload'); ?>" class="button" /></span>
1504 <p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p>
1505 <?php do_action('post-flash-upload-ui'); ?>
1506 <p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
1508 <?php endif; // $flash ?>
1510 <div id="html-upload-ui">
1511 <?php do_action('pre-html-upload-ui'); ?>
1512 <p id="async-upload-wrap">
1513 <label class="screen-reader-text" for="async-upload"><?php _e('Upload'); ?></label>
1514 <input type="file" name="async-upload" id="async-upload" /> <input type="submit" class="button" name="html-upload" value="<?php esc_attr_e('Upload'); ?>" /> <a href="#" onclick="try{top.tb_remove();}catch(e){}; return false;"><?php _e('Cancel'); ?></a>
1516 <div class="clear"></div>
1517 <p class="media-upload-size"><?php printf( __( 'Maximum upload file size: %d%s' ), $upload_size_unit, $sizes[$u] ); ?></p>
1518 <?php if ( is_lighttpd_before_150() ): ?>
1519 <p><?php _e('If you want to use all capabilities of the uploader, like uploading multiple files at once, please upgrade to lighttpd 1.5.'); ?></p>
1521 <?php do_action('post-html-upload-ui', $flash); ?>
1523 <?php do_action('post-upload-ui'); ?>
1528 * {@internal Missing Short Description}}
1532 * @param unknown_type $type
1533 * @param unknown_type $errors
1534 * @param unknown_type $id
1536 function media_upload_type_form($type = 'file', $errors = null, $id = null) {
1537 media_upload_header();
1539 $post_id = isset( $_REQUEST['post_id'] )? intval( $_REQUEST['post_id'] ) : 0;
1541 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
1542 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
1545 <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">
1546 <input type="submit" class="hidden" name="save" value="" />
1547 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1548 <?php wp_nonce_field('media-form'); ?>
1550 <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3>
1552 <?php media_upload_form( $errors ); ?>
1554 <script type="text/javascript">
1557 var preloaded = $(".media-item.preloaded");
1558 if ( preloaded.length > 0 ) {
1559 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1565 <div id="media-items">
1568 if ( !is_wp_error($id) ) {
1569 add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2);
1570 echo get_media_items( $id, $errors );
1572 echo '<div id="media-upload-error">'.esc_html($id->get_error_message()).'</div>';
1578 <p class="savebutton ml-submit">
1579 <input type="submit" class="button" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
1586 * {@internal Missing Short Description}}
1590 * @param unknown_type $type
1591 * @param unknown_type $errors
1592 * @param unknown_type $id
1594 function media_upload_type_url_form($type = 'file', $errors = null, $id = null) {
1595 media_upload_header();
1597 $post_id = intval($_REQUEST['post_id']);
1599 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
1600 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
1602 $callback = "type_url_form_$type";
1605 <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">
1606 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1607 <?php wp_nonce_field('media-form'); ?>
1609 <?php if ( is_callable($callback) ) { ?>
1611 <h3 class="media-title"><?php _e('Add media file from URL'); ?></h3>
1613 <script type="text/javascript">
1619 align : 'alignnone',
1621 insert : function() {
1622 var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = '';
1624 if ( '' == f.src.value || '' == t.width )
1627 if ( f.title.value ) {
1628 title = f.title.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
1629 title = ' title="'+title+'"';
1633 alt = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
1635 <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
1636 if ( f.caption.value )
1637 caption = f.caption.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
1640 cls = caption ? '' : ' class="'+t.align+'"';
1642 html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />';
1645 html = '<a href="'+f.url.value+'">'+html+'</a>';
1648 html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]';
1650 var win = window.dialogArguments || opener || parent || top;
1651 win.send_to_editor(html);
1655 resetImageData : function() {
1656 var t = addExtImage;
1658 t.width = t.height = '';
1659 document.getElementById('go_button').style.color = '#bbb';
1660 if ( ! document.forms[0].src.value )
1661 document.getElementById('status_img').innerHTML = '*';
1662 else document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/no.png' ) ); ?>" alt="" />';
1665 updateImageData : function() {
1666 var t = addExtImage;
1668 t.width = t.preloadImg.width;
1669 t.height = t.preloadImg.height;
1670 document.getElementById('go_button').style.color = '#333';
1671 document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/yes.png' ) ); ?>" alt="" />';
1674 getImageData : function() {
1675 var t = addExtImage, src = document.forms[0].src.value;
1681 document.getElementById('status_img').innerHTML = '<img src="<?php echo esc_url( admin_url( 'images/wpspin_light.gif' ) ); ?>" alt="" />';
1682 t.preloadImg = new Image();
1683 t.preloadImg.onload = t.updateImageData;
1684 t.preloadImg.onerror = t.resetImageData;
1685 t.preloadImg.src = src;
1691 <div id="media-items">
1692 <div class="media-item media-blank">
1693 <?php echo apply_filters($callback, call_user_func($callback)); ?>
1699 wp_die( __('Unknown action.') );
1704 * {@internal Missing Short Description}}
1708 * @param unknown_type $errors
1710 function media_upload_gallery_form($errors) {
1711 global $redir_tab, $type;
1713 $redir_tab = 'gallery';
1714 media_upload_header();
1716 $post_id = intval($_REQUEST['post_id']);
1717 $form_action_url = admin_url("media-upload.php?type=$type&tab=gallery&post_id=$post_id");
1718 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
1721 <script type="text/javascript">
1724 var preloaded = $(".media-item.preloaded");
1725 if ( preloaded.length > 0 ) {
1726 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1732 <div id="sort-buttons" class="hide-if-no-js">
1734 <?php _e('All Tabs:'); ?>
1735 <a href="#" id="showall"><?php _e('Show'); ?></a>
1736 <a href="#" id="hideall" style="display:none;"><?php _e('Hide'); ?></a>
1738 <?php _e('Sort Order:'); ?>
1739 <a href="#" id="asc"><?php _e('Ascending'); ?></a> |
1740 <a href="#" id="desc"><?php _e('Descending'); ?></a> |
1741 <a href="#" id="clear"><?php _ex('Clear', 'verb'); ?></a>
1743 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form validate" id="gallery-form">
1744 <?php wp_nonce_field('media-form'); ?>
1745 <?php //media_upload_form( $errors ); ?>
1746 <table class="widefat" cellspacing="0">
1748 <th><?php _e('Media'); ?></th>
1749 <th class="order-head"><?php _e('Order'); ?></th>
1750 <th class="actions-head"><?php _e('Actions'); ?></th>
1753 <div id="media-items">
1754 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
1755 <?php echo get_media_items($post_id, $errors); ?>
1758 <p class="ml-submit">
1759 <input type="submit" class="button savebutton" style="display:none;" name="save" id="save-all" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
1760 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1761 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" />
1762 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" />
1765 <div id="gallery-settings" style="display:none;">
1766 <div class="title"><?php _e('Gallery Settings'); ?></div>
1767 <table id="basic" class="describe"><tbody>
1769 <th scope="row" class="label">
1771 <span class="alignleft"><?php _e('Link thumbnails to:'); ?></span>
1775 <input type="radio" name="linkto" id="linkto-file" value="file" />
1776 <label for="linkto-file" class="radio"><?php _e('Image File'); ?></label>
1778 <input type="radio" checked="checked" name="linkto" id="linkto-post" value="post" />
1779 <label for="linkto-post" class="radio"><?php _e('Attachment Page'); ?></label>
1784 <th scope="row" class="label">
1786 <span class="alignleft"><?php _e('Order images by:'); ?></span>
1790 <select id="orderby" name="orderby">
1791 <option value="menu_order" selected="selected"><?php _e('Menu order'); ?></option>
1792 <option value="title"><?php _e('Title'); ?></option>
1793 <option value="ID"><?php _e('Date/Time'); ?></option>
1794 <option value="rand"><?php _e('Random'); ?></option>
1800 <th scope="row" class="label">
1802 <span class="alignleft"><?php _e('Order:'); ?></span>
1806 <input type="radio" checked="checked" name="order" id="order-asc" value="asc" />
1807 <label for="order-asc" class="radio"><?php _e('Ascending'); ?></label>
1809 <input type="radio" name="order" id="order-desc" value="desc" />
1810 <label for="order-desc" class="radio"><?php _e('Descending'); ?></label>
1815 <th scope="row" class="label">
1817 <span class="alignleft"><?php _e('Gallery columns:'); ?></span>
1821 <select id="columns" name="columns">
1822 <option value="2">2</option>
1823 <option value="3" selected="selected">3</option>
1824 <option value="4">4</option>
1825 <option value="5">5</option>
1826 <option value="6">6</option>
1827 <option value="7">7</option>
1828 <option value="8">8</option>
1829 <option value="9">9</option>
1835 <p class="ml-submit">
1836 <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="insert-gallery" id="insert-gallery" value="<?php esc_attr_e( 'Insert gallery' ); ?>" />
1837 <input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php esc_attr_e( 'Update gallery settings' ); ?>" />
1845 * {@internal Missing Short Description}}
1849 * @param unknown_type $errors
1851 function media_upload_library_form($errors) {
1852 global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
1854 media_upload_header();
1856 $post_id = intval($_REQUEST['post_id']);
1858 $form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id");
1859 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
1861 $_GET['paged'] = isset( $_GET['paged'] ) ? intval($_GET['paged']) : 0;
1862 if ( $_GET['paged'] < 1 )
1864 $start = ( $_GET['paged'] - 1 ) * 10;
1867 add_filter( 'post_limits', create_function( '$a', "return 'LIMIT $start, 10';" ) );
1869 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
1873 <form id="filter" action="" method="get">
1874 <input type="hidden" name="type" value="<?php echo esc_attr( $type ); ?>" />
1875 <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" />
1876 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
1877 <input type="hidden" name="post_mime_type" value="<?php echo isset( $_GET['post_mime_type'] ) ? esc_attr( $_GET['post_mime_type'] ) : ''; ?>" />
1879 <p id="media-search" class="search-box">
1880 <label class="screen-reader-text" for="media-search-input"><?php _e('Search Media');?>:</label>
1881 <input type="text" id="media-search-input" name="s" value="<?php the_search_query(); ?>" />
1882 <input type="submit" value="<?php esc_attr_e( 'Search Media' ); ?>" class="button" />
1885 <ul class="subsubsub">
1887 $type_links = array();
1888 $_num_posts = (array) wp_count_attachments();
1889 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
1890 foreach ( $matches as $_type => $reals )
1891 foreach ( $reals as $real )
1892 if ( isset($num_posts[$_type]) )
1893 $num_posts[$_type] += $_num_posts[$real];
1895 $num_posts[$_type] = $_num_posts[$real];
1896 // If available type specified by media button clicked, filter by that type
1897 if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) {
1898 $_GET['post_mime_type'] = $type;
1899 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
1901 if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' )
1902 $class = ' class="current"';
1905 $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>";
1906 foreach ( $post_mime_types as $mime_type => $label ) {
1909 if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
1912 if ( isset($_GET['post_mime_type']) && wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
1913 $class = ' class="current"';
1915 $type_links[] = "<li><a href='" . esc_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . "'$class>" . sprintf(_n($label[2][0], $label[2][1], $num_posts[$mime_type]), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>';
1917 echo implode(' | </li>', $type_links) . '</li>';
1922 <div class="tablenav">
1925 $page_links = paginate_links( array(
1926 'base' => add_query_arg( 'paged', '%#%' ),
1928 'prev_text' => __('«'),
1929 'next_text' => __('»'),
1930 'total' => ceil($wp_query->found_posts / 10),
1931 'current' => $_GET['paged']
1935 echo "<div class='tablenav-pages'>$page_links</div>";
1938 <div class="alignleft actions">
1941 $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";
1943 $arc_result = $wpdb->get_results( $arc_query );
1945 $month_count = count($arc_result);
1947 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
1949 <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
1951 foreach ($arc_result as $arc_row) {
1952 if ( $arc_row->yyear == 0 )
1954 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
1956 if ( isset($_GET['m']) && ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] ) )
1957 $default = ' selected="selected"';
1961 echo "<option$default value='" . esc_attr( $arc_row->yyear . $arc_row->mmonth ) . "'>";
1962 echo esc_html( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" );
1969 <input type="submit" id="post-query-submit" value="<?php echo esc_attr( __( 'Filter »' ) ); ?>" class="button-secondary" />
1973 <br class="clear" />
1977 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="media-upload-form validate" id="library-form">
1979 <?php wp_nonce_field('media-form'); ?>
1980 <?php //media_upload_form( $errors ); ?>
1982 <script type="text/javascript">
1985 var preloaded = $(".media-item.preloaded");
1986 if ( preloaded.length > 0 ) {
1987 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1994 <div id="media-items">
1995 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
1996 <?php echo get_media_items(null, $errors); ?>
1998 <p class="ml-submit">
1999 <input type="submit" class="button savebutton" name="save" value="<?php esc_attr_e( 'Save all changes' ); ?>" />
2000 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
2007 * {@internal Missing Short Description}}
2013 function type_url_form_image() {
2014 if ( !apply_filters( 'disable_captions', '' ) ) {
2017 <th valign="top" scope="row" class="label">
2018 <span class="alignleft"><label for="caption">' . __('Image Caption') . '</label></span>
2020 <td class="field"><input id="caption" name="caption" value="" type="text" /></td>
2027 $default_align = get_option('image_default_align');
2028 if ( empty($default_align) )
2029 $default_align = 'none';
2032 <h4 class="media-sub-title">' . __('Insert an image from another web site') . '</h4>
2033 <table class="describe"><tbody>
2035 <th valign="top" scope="row" class="label" style="width:130px;">
2036 <span class="alignleft"><label for="src">' . __('Image URL') . '</label></span>
2037 <span class="alignright"><abbr id="status_img" title="required" class="required">*</abbr></span>
2039 <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td>
2043 <th valign="top" scope="row" class="label">
2044 <span class="alignleft"><label for="title">' . __('Image Title') . '</label></span>
2045 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2047 <td class="field"><input id="title" name="title" value="" type="text" aria-required="true" /></td>
2051 <th valign="top" scope="row" class="label">
2052 <span class="alignleft"><label for="alt">' . __('Alternate Text') . '</label></span>
2054 <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
2055 <p class="help">' . __('Alt text for the image, e.g. “The Mona Lisa”') . '</p></td>
2059 <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
2061 <input name="align" id="align-none" value="none" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'none' ? ' checked="checked"' : '').' />
2062 <label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
2063 <input name="align" id="align-left" value="left" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'left' ? ' checked="checked"' : '').' />
2064 <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label>
2065 <input name="align" id="align-center" value="center" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'center' ? ' checked="checked"' : '').' />
2066 <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label>
2067 <input name="align" id="align-right" value="right" onclick="addExtImage.align=\'align\'+this.value" type="radio"' . ($default_align == 'right' ? ' checked="checked"' : '').' />
2068 <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
2073 <th valign="top" scope="row" class="label">
2074 <span class="alignleft"><label for="url">' . __('Link Image To:') . '</label></span>
2076 <td class="field"><input id="url" name="url" value="" type="text" /><br />
2078 <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
2079 <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
2080 <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
2082 ' . _insert_into_post_button('image') . '
2089 * {@internal Missing Short Description}}
2095 function type_url_form_audio() {
2097 <table class="describe"><tbody>
2099 <th valign="top" scope="row" class="label">
2100 <span class="alignleft"><label for="insertonly[href]">' . __('Audio File URL') . '</label></span>
2101 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2103 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
2106 <th valign="top" scope="row" class="label">
2107 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
2108 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2110 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
2112 <tr><td></td><td class="help">' . __('Link text, e.g. “Still Alive by Jonathan Coulton”') . '</td></tr>
2113 ' . _insert_into_post_button('audio') . '
2119 * {@internal Missing Short Description}}
2125 function type_url_form_video() {
2127 <table class="describe"><tbody>
2129 <th valign="top" scope="row" class="label">
2130 <span class="alignleft"><label for="insertonly[href]">' . __('Video URL') . '</label></span>
2131 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2133 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
2136 <th valign="top" scope="row" class="label">
2137 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
2138 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2140 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
2142 <tr><td></td><td class="help">' . __('Link text, e.g. “Lucy on YouTube”') . '</td></tr>
2143 ' . _insert_into_post_button('video') . '
2149 * {@internal Missing Short Description}}
2155 function type_url_form_file() {
2157 <table class="describe"><tbody>
2159 <th valign="top" scope="row" class="label">
2160 <span class="alignleft"><label for="insertonly[href]">' . __('URL') . '</label></span>
2161 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2163 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
2166 <th valign="top" scope="row" class="label">
2167 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
2168 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
2170 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
2172 <tr><td></td><td class="help">' . __('Link text, e.g. “Ransom Demands (PDF)”') . '</td></tr>
2173 ' . _insert_into_post_button('file') . '
2179 function _insert_into_post_button($type) {
2180 if ( !post_type_supports(get_post_type($_GET['post_id']), 'editor') )
2183 if ( 'image' == $type )
2188 <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . esc_attr__('Insert into Post') . '" />
2197 <input type="submit" class="button" name="insertonlybutton" value="' . esc_attr__('Insert into Post') . '" />
2204 * {@internal Missing Short Description}}
2206 * Support a GET parameter for disabling the flash uploader.
2210 * @param unknown_type $flash
2213 function media_upload_use_flash($flash) {
2214 if ( array_key_exists('flash', $_REQUEST) )
2215 $flash = !empty($_REQUEST['flash']);
2219 add_filter('flash_uploader', 'media_upload_use_flash');
2222 * {@internal Missing Short Description}}
2226 function media_upload_flash_bypass() {
2227 echo '<p class="upload-flash-bypass">';
2228 printf( __('You are using the Flash uploader. Problems? Try the <a href="%s">Browser uploader</a> instead.'), esc_url(add_query_arg('flash', 0)) );
2233 * {@internal Missing Short Description}}
2237 function media_upload_html_bypass($flash = true) {
2238 echo '<p class="upload-html-bypass hide-if-no-js">';
2239 _e('You are using the Browser uploader.');
2241 // the user manually selected the browser uploader, so let them switch back to Flash
2243 printf( __('Try the <a href="%s">Flash uploader</a> instead.'), esc_url(add_query_arg('flash', 1)) );
2248 add_action('post-flash-upload-ui', 'media_upload_flash_bypass');
2249 add_action('post-html-upload-ui', 'media_upload_html_bypass');
2252 * {@internal Missing Short Description}}
2254 * Make sure the GET parameter sticks when we submit a form.
2258 * @param unknown_type $url
2261 function media_upload_bypass_url($url) {
2262 if ( array_key_exists('flash', $_REQUEST) )
2263 $url = add_query_arg('flash', intval($_REQUEST['flash']));
2267 add_filter('media_upload_form_url', 'media_upload_bypass_url');
2269 add_filter('async_upload_image', 'get_media_item', 10, 2);
2270 add_filter('async_upload_audio', 'get_media_item', 10, 2);
2271 add_filter('async_upload_video', 'get_media_item', 10, 2);
2272 add_filter('async_upload_file', 'get_media_item', 10, 2);
2274 add_action('media_upload_image', 'media_upload_image');
2275 add_action('media_upload_audio', 'media_upload_audio');
2276 add_action('media_upload_video', 'media_upload_video');
2277 add_action('media_upload_file', 'media_upload_file');
2279 add_filter('media_upload_gallery', 'media_upload_gallery');
2281 add_filter('media_upload_library', 'media_upload_library');