3 function media_upload_tabs() {
4 $_default_tabs = array(
5 'type' => __('Choose File'), // handler action suffix => tab text
6 'gallery' => __('Gallery'),
7 'library' => __('Media Library'),
10 return apply_filters('media_upload_tabs', $_default_tabs);
13 function update_gallery_tab($tabs) {
15 if ( !isset($_REQUEST['post_id']) ) {
16 unset($tabs['gallery']);
19 if ( intval($_REQUEST['post_id']) )
20 $attachments = intval($wpdb->get_var($wpdb->prepare("SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_parent = %d", $_REQUEST['post_id'])));
22 $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");
26 add_filter('media_upload_tabs', 'update_gallery_tab');
28 function the_media_upload_tabs() {
30 $tabs = media_upload_tabs();
32 if ( !empty($tabs) ) {
33 echo "<ul id='sidemenu'>\n";
34 if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) )
35 $current = $redir_tab;
36 elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) )
37 $current = $_GET['tab'];
39 $keys = array_keys($tabs);
40 $current = array_shift($keys);
42 foreach ( $tabs as $callback => $text ) {
44 if ( $current == $callback )
45 $class = " class='current'";
46 $href = add_query_arg(array('tab'=>$callback, 's'=>false, 'paged'=>false, 'post_mime_type'=>false, 'm'=>false));
47 $link = "<a href='" . clean_url($href) . "'$class>$text</a>";
48 echo "\t<li id='" . attribute_escape("tab-$callback") . "'>$link</li>\n";
54 function get_image_send_to_editor($id, $alt, $title, $align, $url='', $rel = false, $size='medium') {
56 $html = get_image_tag($id, $alt, $title, $align, $size);
58 $rel = $rel ? ' rel="attachment wp-att-'.attribute_escape($id).'"' : '';
61 $html = '<a href="' . clean_url($url) . "\"$rel>$html</a>";
63 $html = apply_filters( 'image_send_to_editor', $html, $id, $alt, $title, $align, $url, $size );
68 function image_add_caption( $html, $id, $alt, $title, $align, $url, $size ) {
70 if ( empty($alt) || apply_filters( 'disable_captions', '' ) ) return $html;
71 $id = ( 0 < (int) $id ) ? 'attachment_' . $id : '';
73 preg_match( '/width="([0-9]+)/', $html, $matches );
74 if ( ! isset($matches[1]) ) return $html;
77 $html = preg_replace( '/align[^\s\'"]+\s?/', '', $html );
78 if ( empty($align) ) $align = 'none';
80 $shcode = '[caption id="' . $id . '" align="align' . $align
81 . '" width="' . $width . '" caption="' . $alt . '"]' . $html . '[/caption]';
83 return apply_filters( 'image_add_caption_shortcode', $shcode, $html );
85 add_filter( 'image_send_to_editor', 'image_add_caption', 20, 7 );
87 function media_send_to_editor($html) {
89 <script type="text/javascript">
91 var win = window.dialogArguments || opener || parent || top;
92 win.send_to_editor('<?php echo addslashes($html); ?>');
99 // this handles the file upload POST itself, creating the attachment post
100 function media_handle_upload($file_id, $post_id, $post_data = array()) {
101 $overrides = array('test_form'=>false);
102 $file = wp_handle_upload($_FILES[$file_id], $overrides);
104 if ( isset($file['error']) )
105 return new WP_Error( 'upload_error', $file['error'] );
108 $type = $file['type'];
109 $file = $file['file'];
110 $title = preg_replace('/\.[^.]+$/', '', basename($file));
113 // use image exif/iptc data for title and caption defaults if possible
114 if ( $image_meta = @wp_read_image_metadata($file) ) {
115 if ( trim($image_meta['title']) )
116 $title = $image_meta['title'];
117 if ( trim($image_meta['caption']) )
118 $content = $image_meta['caption'];
121 // Construct the attachment array
122 $attachment = array_merge( array(
123 'post_mime_type' => $type,
125 'post_parent' => $post_id,
126 'post_title' => $title,
127 'post_content' => $content,
131 $id = wp_insert_attachment($attachment, $file, $post_parent);
132 if ( !is_wp_error($id) ) {
133 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
140 function media_handle_sideload($file_array, $post_id, $desc = null, $post_data = array()) {
141 $overrides = array('test_form'=>false);
142 $file = wp_handle_sideload($file_array, $overrides);
144 if ( isset($file['error']) )
145 return new WP_Error( 'upload_error', $file['error'] );
148 $type = $file['type'];
149 $file = $file['file'];
150 $title = preg_replace('/\.[^.]+$/', '', basename($file));
153 // use image exif/iptc data for title and caption defaults if possible
154 if ( $image_meta = @wp_read_image_metadata($file) ) {
155 if ( trim($image_meta['title']) )
156 $title = $image_meta['title'];
157 if ( trim($image_meta['caption']) )
158 $content = $image_meta['caption'];
163 // Construct the attachment array
164 $attachment = array_merge( array(
165 'post_mime_type' => $type,
167 'post_parent' => $post_id,
168 'post_title' => $title,
169 'post_content' => $content,
173 $id = wp_insert_attachment($attachment, $file, $post_parent);
174 if ( !is_wp_error($id) ) {
175 wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) );
182 // wrap iframe content (produced by $content_func) in a doctype, html head/body etc
183 // any additional function args will be passed to content_func
184 function wp_iframe($content_func /* ... */) {
186 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
187 <html xmlns="http://www.w3.org/1999/xhtml" <?php do_action('admin_xml_ns'); ?> <?php language_attributes(); ?>>
189 <meta http-equiv="Content-Type" content="<?php bloginfo('html_type'); ?>; charset=<?php echo get_option('blog_charset'); ?>" />
190 <title><?php bloginfo('name') ?> › <?php _e('Uploads'); ?> — <?php _e('WordPress'); ?></title>
192 wp_enqueue_style( 'global' );
193 wp_enqueue_style( 'wp-admin' );
194 wp_enqueue_style( 'colors' );
195 if ( 0 === strpos( $content_func, 'media' ) )
196 wp_enqueue_style( 'media' );
199 <script type="text/javascript">
201 function addLoadEvent(func) {if ( typeof wpOnload!='function'){wpOnload=func;}else{ var oldonload=wpOnload;wpOnload=function(){oldonload();func();}}}
205 do_action('admin_print_styles');
206 do_action('admin_print_scripts');
207 do_action('admin_head');
208 if ( is_string($content_func) )
209 do_action( "admin_head_{$content_func}" );
212 <body<?php if ( isset($GLOBALS['body_id']) ) echo ' id="' . $GLOBALS['body_id'] . '"'; ?>>
214 $args = func_get_args();
215 $args = array_slice($args, 1);
216 call_user_func_array($content_func, $args);
223 function media_buttons() {
224 global $post_ID, $temp_ID;
225 $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
226 $context = apply_filters('media_buttons_context', __('Add media: %s'));
227 $media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
228 $media_title = __('Add Media');
229 $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&type=image");
230 $image_title = __('Add an Image');
231 $video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src&type=video");
232 $video_title = __('Add Video');
233 $audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src&type=audio");
234 $audio_title = __('Add Audio');
237 <a href="{$image_upload_iframe_src}&TB_iframe=true" id="add_image" class="thickbox" title='$image_title'><img src='images/media-button-image.gif' alt='$image_title' /></a>
238 <a href="{$video_upload_iframe_src}&TB_iframe=true" id="add_video" class="thickbox" title='$video_title'><img src='images/media-button-video.gif' alt='$video_title' /></a>
239 <a href="{$audio_upload_iframe_src}&TB_iframe=true" id="add_audio" class="thickbox" title='$audio_title'><img src='images/media-button-music.gif' alt='$audio_title' /></a>
240 <a href="{$media_upload_iframe_src}&TB_iframe=true" id="add_media" class="thickbox" title='$media_title'><img src='images/media-button-other.gif' alt='$media_title' /></a>
243 printf($context, $out);
245 add_action( 'media_buttons', 'media_buttons' );
246 add_action('media_upload_media', 'media_upload_handler');
248 function media_upload_form_handler() {
249 check_admin_referer('media-form');
251 if ( !empty($_POST['attachments']) ) foreach ( $_POST['attachments'] as $attachment_id => $attachment ) {
252 $post = $_post = get_post($attachment_id, ARRAY_A);
253 if ( isset($attachment['post_content']) )
254 $post['post_content'] = $attachment['post_content'];
255 if ( isset($attachment['post_title']) )
256 $post['post_title'] = $attachment['post_title'];
257 if ( isset($attachment['post_excerpt']) )
258 $post['post_excerpt'] = $attachment['post_excerpt'];
259 if ( isset($attachment['menu_order']) )
260 $post['menu_order'] = $attachment['menu_order'];
262 $post = apply_filters('attachment_fields_to_save', $post, $attachment);
264 if ( isset($post['errors']) ) {
265 $errors[$attachment_id] = $post['errors'];
266 unset($post['errors']);
269 if ( $post != $_post )
270 wp_update_post($post);
272 foreach ( get_attachment_taxonomies($post) as $t )
273 if ( isset($attachment[$t]) )
274 wp_set_object_terms($attachment_id, array_map('trim', preg_split('/,+/', $attachment[$t])), $t, false);
277 if ( isset($_POST['insert-gallery']) )
278 return media_send_to_editor('[gallery]');
280 if ( isset($_POST['send']) ) {
281 $keys = array_keys($_POST['send']);
282 $send_id = (int) array_shift($keys);
283 $attachment = stripslashes_deep( $_POST['attachments'][$send_id] );
284 $html = $attachment['post_title'];
285 if ( !empty($attachment['url']) ) {
286 if ( strpos($attachment['url'], 'attachment_id') || false !== strpos($attachment['url'], get_permalink($_POST['post_id'])) )
287 $rel = " rel='attachment wp-att-".attribute_escape($send_id)."'";
288 $html = "<a href='{$attachment['url']}'$rel>$html</a>";
290 $html = apply_filters('media_send_to_editor', $html, $send_id, $attachment);
291 return media_send_to_editor($html);
297 function media_upload_image() {
298 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
299 // Upload File button was clicked
300 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
302 if ( is_wp_error($id) ) {
303 $errors['upload_error'] = $id;
308 if ( !empty($_POST['insertonlybutton']) ) {
309 $src = $_POST['insertonly']['src'];
310 if ( !empty($src) && !strpos($src, '://') )
311 $src = "http://$src";
312 $alt = attribute_escape($_POST['insertonly']['alt']);
313 if ( isset($_POST['insertonly']['align']) ) {
314 $align = attribute_escape($_POST['insertonly']['align']);
315 $class = " class='align$align'";
318 $html = "<img src='$src' alt='$alt'$class />";
319 return media_send_to_editor($html);
322 if ( !empty($_POST) ) {
323 $return = media_upload_form_handler();
325 if ( is_string($return) )
327 if ( is_array($return) )
331 if ( isset($_POST['save']) ) {
332 $errors['upload_notice'] = __('Saved.');
333 return media_upload_gallery();
336 return wp_iframe( 'media_upload_type_form', 'image', $errors, $id );
339 function media_sideload_image($file, $post_id, $desc = null) {
340 if (!empty($file) ) {
341 $file_array['name'] = basename($file);
342 $file_array['tmp_name'] = download_url($file);
345 $id = media_handle_sideload($file_array, $post_id, $desc);
348 if ( is_wp_error($id) ) {
349 @unlink($file_array['tmp_name']);
354 if ( !empty($src) ) {
356 $html = "<img src='$src' alt='$alt' />";
361 function media_upload_audio() {
362 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
363 // Upload File button was clicked
364 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
366 if ( is_wp_error($id) ) {
367 $errors['upload_error'] = $id;
372 if ( !empty($_POST['insertonlybutton']) ) {
373 $href = $_POST['insertonly']['href'];
374 if ( !empty($href) && !strpos($href, '://') )
375 $href = "http://$href";
376 $title = attribute_escape($_POST['insertonly']['title']);
378 $title = basename($href);
379 if ( !empty($title) && !empty($href) )
380 $html = "<a href='$href' >$title</a>";
381 return media_send_to_editor($html);
384 if ( !empty($_POST) ) {
385 $return = media_upload_form_handler();
387 if ( is_string($return) )
389 if ( is_array($return) )
393 if ( isset($_POST['save']) ) {
394 $errors['upload_notice'] = __('Saved.');
395 return media_upload_gallery();
398 return wp_iframe( 'media_upload_type_form', 'audio', $errors, $id );
401 function media_upload_video() {
402 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
403 // Upload File button was clicked
404 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
406 if ( is_wp_error($id) ) {
407 $errors['upload_error'] = $id;
412 if ( !empty($_POST['insertonlybutton']) ) {
413 $href = $_POST['insertonly']['href'];
414 if ( !empty($href) && !strpos($href, '://') )
415 $href = "http://$href";
416 $title = attribute_escape($_POST['insertonly']['title']);
418 $title = basename($href);
419 if ( !empty($title) && !empty($href) )
420 $html = "<a href='$href' >$title</a>";
421 return media_send_to_editor($html);
424 if ( !empty($_POST) ) {
425 $return = media_upload_form_handler();
427 if ( is_string($return) )
429 if ( is_array($return) )
433 if ( isset($_POST['save']) ) {
434 $errors['upload_notice'] = __('Saved.');
435 return media_upload_gallery();
438 return wp_iframe( 'media_upload_type_form', 'video', $errors, $id );
441 function media_upload_file() {
442 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
443 // Upload File button was clicked
444 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
446 if ( is_wp_error($id) ) {
447 $errors['upload_error'] = $id;
452 if ( !empty($_POST['insertonlybutton']) ) {
453 $href = $_POST['insertonly']['href'];
454 if ( !empty($href) && !strpos($href, '://') )
455 $href = "http://$href";
456 $title = attribute_escape($_POST['insertonly']['title']);
458 $title = basename($href);
459 if ( !empty($title) && !empty($href) )
460 $html = "<a href='$href' >$title</a>";
461 return media_send_to_editor($html);
464 if ( !empty($_POST) ) {
465 $return = media_upload_form_handler();
467 if ( is_string($return) )
469 if ( is_array($return) )
473 if ( isset($_POST['save']) ) {
474 $errors['upload_notice'] = __('Saved.');
475 return media_upload_gallery();
478 return wp_iframe( 'media_upload_type_form', 'file', $errors, $id );
481 function media_upload_gallery() {
482 if ( !empty($_POST) ) {
483 $return = media_upload_form_handler();
485 if ( is_string($return) )
487 if ( is_array($return) )
491 wp_enqueue_script('admin-gallery');
492 return wp_iframe( 'media_upload_gallery_form', $errors );
495 function media_upload_library() {
496 if ( !empty($_POST) ) {
497 $return = media_upload_form_handler();
499 if ( is_string($return) )
501 if ( is_array($return) )
505 return wp_iframe( 'media_upload_library_form', $errors );
508 function image_attachment_fields_to_edit($form_fields, $post) {
509 if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
510 $form_fields['post_title']['required'] = true;
512 $form_fields['post_excerpt']['label'] = __('Caption');
513 $form_fields['post_excerpt']['helps'][] = __('Also used as alternate text for the image');
515 $form_fields['post_content']['label'] = __('Description');
517 $thumb = wp_get_attachment_thumb_url($post->ID);
519 $form_fields['align'] = array(
520 'label' => __('Alignment'),
523 <input type='radio' name='attachments[$post->ID][align]' id='image-align-none-$post->ID' value='none' checked='checked' />
524 <label for='image-align-none-$post->ID' class='align image-align-none-label'>" . __('None') . "</label>
525 <input type='radio' name='attachments[$post->ID][align]' id='image-align-left-$post->ID' value='left' />
526 <label for='image-align-left-$post->ID' class='align image-align-left-label'>" . __('Left') . "</label>
527 <input type='radio' name='attachments[$post->ID][align]' id='image-align-center-$post->ID' value='center' />
528 <label for='image-align-center-$post->ID' class='align image-align-center-label'>" . __('Center') . "</label>
529 <input type='radio' name='attachments[$post->ID][align]' id='image-align-right-$post->ID' value='right' />
530 <label for='image-align-right-$post->ID' class='align image-align-right-label'>" . __('Right') . "</label>\n",
532 $form_fields['image-size'] = array(
533 'label' => __('Size'),
536 " . ( $thumb ? "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-thumb-$post->ID' value='thumbnail' />
537 <label for='image-size-thumb-$post->ID'>" . __('Thumbnail') . "</label>
538 " : '' ) . "<input type='radio' name='attachments[$post->ID][image-size]' id='image-size-medium-$post->ID' value='medium' checked='checked' />
539 <label for='image-size-medium-$post->ID'>" . __('Medium') . "</label>
540 <input type='radio' name='attachments[$post->ID][image-size]' id='image-size-full-$post->ID' value='full' />
541 <label for='image-size-full-$post->ID'>" . __('Full size') . "</label>",
547 add_filter('attachment_fields_to_edit', 'image_attachment_fields_to_edit', 10, 2);
549 function media_single_attachment_fields_to_edit( $form_fields, $post ) {
550 unset($form_fields['url'], $form_fields['align'], $form_fields['image-size']);
554 function image_attachment_fields_to_save($post, $attachment) {
555 if ( substr($post['post_mime_type'], 0, 5) == 'image' ) {
556 if ( strlen(trim($post['post_title'])) == 0 ) {
557 $post['post_title'] = preg_replace('/\.\w+$/', '', basename($post['guid']));
558 $post['errors']['post_title']['errors'][] = __('Empty Title filled from filename.');
565 add_filter('attachment_fields_to_save', 'image_attachment_fields_to_save', 10, 2);
567 function image_media_send_to_editor($html, $attachment_id, $attachment) {
568 $post =& get_post($attachment_id);
569 if ( substr($post->post_mime_type, 0, 5) == 'image' ) {
570 $url = $attachment['url'];
572 if ( isset($attachment['align']) )
573 $align = $attachment['align'];
577 if ( !empty($attachment['image-size']) )
578 $size = $attachment['image-size'];
582 $rel = ( $url == get_attachment_link($attachment_id) );
584 return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size);
590 add_filter('media_send_to_editor', 'image_media_send_to_editor', 10, 3);
592 function get_attachment_fields_to_edit($post, $errors = null) {
594 $post =& get_post($post);
595 if ( is_array($post) )
596 $post = (object) $post;
598 $edit_post = sanitize_post($post, 'edit');
599 $file = wp_get_attachment_url($post->ID);
600 $link = get_attachment_link($post->ID);
602 $form_fields = array(
603 'post_title' => array(
604 'label' => __('Title'),
605 'value' => $edit_post->post_title,
607 'post_excerpt' => array(
608 'label' => __('Caption'),
609 'value' => $edit_post->post_excerpt,
611 'post_content' => array(
612 'label' => __('Description'),
613 'value' => $edit_post->post_content,
614 'input' => 'textarea',
617 'label' => __('Link URL'),
620 <input type='text' name='attachments[$post->ID][url]' value='" . attribute_escape($file) . "' /><br />
621 <button type='button' class='button url-$post->ID' value=''>" . __('None') . "</button>
622 <button type='button' class='button url-$post->ID' value='" . attribute_escape($file) . "'>" . __('File URL') . "</button>
623 <button type='button' class='button url-$post->ID' value='" . attribute_escape($link) . "'>" . __('Post URL') . "</button>
624 <script type='text/javascript'>
625 jQuery('button.url-$post->ID').bind('click', function(){jQuery(this).siblings('input').val(this.value);});
627 'helps' => __('Enter a link URL or click above for presets.'),
629 'menu_order' => array(
630 'label' => __('Order'),
631 'value' => $edit_post->menu_order
635 foreach ( get_attachment_taxonomies($post) as $taxonomy ) {
636 $t = (array) get_taxonomy($taxonomy);
637 if ( empty($t['label']) )
638 $t['label'] = $taxonomy;
639 if ( empty($t['args']) )
640 $t['args'] = array();
642 $terms = get_object_term_cache($post->ID, $taxonomy);
644 $terms = wp_get_object_terms($post->ID, $taxonomy, $t['args']);
648 foreach ( $terms as $term )
649 $values[] = $term->name;
650 $t['value'] = join(', ', $values);
652 $form_fields[$taxonomy] = $t;
655 // Merge default fields with their errors, so any key passed with the error (e.g. 'error', 'helps', 'value') will replace the default
656 // The recursive merge is easily traversed with array casting: foreach( (array) $things as $thing )
657 $form_fields = array_merge_recursive($form_fields, (array) $errors);
659 $form_fields = apply_filters('attachment_fields_to_edit', $form_fields, $post);
664 function get_media_items( $post_id, $errors ) {
666 $post = get_post($post_id);
667 if ( $post && $post->post_type == 'attachment' )
668 $attachments = array($post->ID => $post);
670 $attachments = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'orderby' => 'menu_order ASC, ID', 'order' => 'DESC') );
672 if ( is_array($GLOBALS['wp_the_query']->posts) )
673 foreach ( $GLOBALS['wp_the_query']->posts as $attachment )
674 $attachments[$attachment->ID] = $attachment;
677 if ( empty($attachments) )
680 foreach ( $attachments as $id => $attachment )
681 if ( $item = get_media_item( $id, array( 'errors' => isset($errors[$id]) ? $errors[$id] : null) ) )
682 $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>";
687 function get_media_item( $attachment_id, $args = null ) {
690 $default_args = array( 'errors' => null, 'send' => true, 'delete' => true, 'toggle' => true );
691 $args = wp_parse_args( $args, $default_args );
692 extract( $args, EXTR_SKIP );
694 global $post_mime_types;
695 if ( ( $attachment_id = intval($attachment_id) ) && $thumb_url = get_attachment_icon_src( $attachment_id ) )
696 $thumb_url = $thumb_url[0];
700 $title_label = __('Title');
701 $description_label = __('Description');
702 $tags_label = __('Tags');
704 $toggle_on = __('Show');
705 $toggle_off = __('Hide');
707 $post = get_post($attachment_id);
709 $filename = basename($post->guid);
710 $title = attribute_escape($post->post_title);
711 $description = attribute_escape($post->post_content);
712 if ( $_tags = get_the_tags($attachment_id) ) {
713 foreach ( $_tags as $tag )
714 $tags[] = $tag->name;
715 $tags = attribute_escape(join(', ', $tags));
718 if ( isset($post_mime_types) ) {
719 $keys = array_keys(wp_match_mime_types(array_keys($post_mime_types), $post->post_mime_type));
720 $type = array_shift($keys);
721 $type = "<input type='hidden' id='type-of-$attachment_id' value='" . attribute_escape( $type ) . "' />";
724 $form_fields = get_attachment_fields_to_edit($post, $errors);
727 $class = empty($errors) ? 'startclosed' : 'startopen';
729 <a class='toggle describe-toggle-on' href='#'>$toggle_on</a>
730 <a class='toggle describe-toggle-off' href='#'>$toggle_off</a>";
732 $class = 'form-table';
736 $display_title = ( !empty( $title ) ) ? $title : $filename; // $title shouldn't ever be empty, but just in case
737 $display_title = wp_html_excerpt($display_title, 60);
739 $gallery = ( (isset($_REQUEST['tab']) && 'gallery' == $_REQUEST['tab']) || (isset($redir_tab) && 'gallery' == $redir_tab) ) ? true : false;
742 foreach ( $form_fields as $key => $val ) {
743 if ( 'menu_order' == $key ) {
745 $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="'.$val['value'].'" /></div>';
747 $order = '<input type="hidden" name="attachments['.$attachment_id.'][menu_order]" value="'.$val['value'].'" />';
749 unset($form_fields['menu_order']);
758 <div class='filename new'>$display_title</div>
759 <table class='slidetoggle describe $class'>
760 <thead class='media-item-info'>
762 <td class='A1B1' rowspan='4'><img class='thumbnail' src='$thumb_url' alt='' /></td>
765 <tr><td>$post->post_mime_type</td></tr>
766 <tr><td>" . mysql2date($post->post_date, get_option('time_format')) . "</td></tr>
767 <tr><td>" . apply_filters('media_meta', '', $post) . "</td></tr>
775 'extra_rows' => array(),
778 $delete_href = wp_nonce_url("post.php?action=delete-post&post=$attachment_id", 'delete-post_' . $attachment_id);
780 $send = "<input type='submit' class='button' name='send[$attachment_id]' value='" . attribute_escape( __( 'Insert into Post' ) ) . "' />";
782 $delete = "<a href=\"#\" class=\"del-link\" onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __('Delete') . "</a>";
783 if ( ( $send || $delete ) && !isset($form_fields['buttons']) )
784 $form_fields['buttons'] = array('tr' => "\t\t<tr class='submit'><td></td><td class='savesend'>$send $delete
785 <div id=\"del_attachment_$attachment_id\" class=\"del-attachment\" style=\"display:none;\">" . sprintf(__("You are about to delete <strong>%s</strong>."), $filename) . " <a href=\"$delete_href\" id=\"del[$attachment_id]\" class=\"delete\">" . __('Continue') . "</a>
786 <a href=\"#\" class=\"del-link\" onclick=\"this.parentNode.style.display='none';return false;\">" . __('Cancel') . "</a></div></td></tr>\n");
788 $hidden_fields = array();
790 foreach ( $form_fields as $id => $field ) {
794 if ( !empty($field['tr']) ) {
795 $item .= $field['tr'];
799 $field = array_merge($defaults, $field);
800 $name = "attachments[$attachment_id][$id]";
802 if ( $field['input'] == 'hidden' ) {
803 $hidden_fields[$name] = $field['value'];
807 $required = $field['required'] ? '<abbr title="required" class="required">*</abbr>' : '';
808 $aria_required = $field['required'] ? " aria-required='true' " : '';
810 $class .= $field['required'] ? ' form-required' : '';
812 $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><span class='alignright'>$required</span><br class='clear' /></label></th>\n\t\t\t<td class='field'>";
813 if ( !empty($field[$field['input']]) )
814 $item .= $field[$field['input']];
815 elseif ( $field['input'] == 'textarea' ) {
816 $item .= "<textarea type='text' id='$name' name='$name'>" . attribute_escape( $field['value'] ) . $aria_required . "</textarea>";
818 $item .= "<input type='text' id='$name' name='$name' value='" . attribute_escape( $field['value'] ) . "'" . $aria_required . "/>";
820 if ( !empty($field['helps']) )
821 $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique((array) $field['helps']) ) . '</p>';
822 $item .= "</td>\n\t\t</tr>\n";
824 $extra_rows = array();
826 if ( !empty($field['errors']) )
827 foreach ( array_unique((array) $field['errors']) as $error )
828 $extra_rows['error'][] = $error;
830 if ( !empty($field['extra_rows']) )
831 foreach ( $field['extra_rows'] as $class => $rows )
832 foreach ( (array) $rows as $html )
833 $extra_rows[$class][] = $html;
835 foreach ( $extra_rows as $class => $rows )
836 foreach ( $rows as $html )
837 $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n";
840 if ( !empty($form_fields['_final']) )
841 $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n";
842 $item .= "\t</tbody>\n";
843 $item .= "\t</table>\n";
845 foreach ( $hidden_fields as $name => $value )
846 $item .= "\t<input type='hidden' name='$name' id='$name' value='" . attribute_escape( $value ) . "' />\n";
851 function media_upload_header() {
853 <script type="text/javascript">post_id = <?php echo intval($_REQUEST['post_id']); ?>;</script>
854 <div id="media-upload-header">
855 <?php the_media_upload_tabs(); ?>
860 function media_upload_form( $errors = null ) {
863 $flash_action_url = admin_url('async-upload.php');
865 // If Mac and mod_security, no Flash. :(
867 if ( false !== strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mac') && apache_mod_loaded('mod_security') )
870 $flash = apply_filters('flash_uploader', $flash);
871 $post_id = intval($_REQUEST['post_id']);
874 <div id="media-upload-notice">
875 <?php if (isset($errors['upload_notice']) ) { ?>
876 <?php echo $errors['upload_notice']; ?>
879 <div id="media-upload-error">
880 <?php if (isset($errors['upload_error']) && is_wp_error($errors['upload_error'])) { ?>
881 <?php echo $errors['upload_error']->get_error_message(); ?>
885 <?php do_action('pre-upload-ui'); ?>
887 <?php if ( $flash ) : ?>
888 <script type="text/javascript">
891 swfu = new SWFUpload({
892 upload_url : "<?php echo attribute_escape( $flash_action_url ); ?>",
893 flash_url : "<?php echo includes_url('js/swfupload/swfupload_f9.swf'); ?>",
894 file_post_name: "async-upload",
895 file_types: "<?php echo apply_filters('upload_file_glob', '*.*'); ?>",
897 "post_id" : "<?php echo $post_id; ?>",
898 "auth_cookie" : "<?php if ( is_ssl() ) echo $_COOKIE[SECURE_AUTH_COOKIE]; else echo $_COOKIE[AUTH_COOKIE]; ?>",
899 "_wpnonce" : "<?php echo wp_create_nonce('media-form'); ?>",
900 "type" : "<?php echo $type; ?>",
901 "tab" : "<?php echo $tab; ?>",
904 file_size_limit : "<?php echo wp_max_upload_size(); ?>b",
905 swfupload_element_id : "flash-upload-ui", // id of the element displayed when swfupload is available
906 degraded_element_id : "html-upload-ui", // when swfupload is unavailable
907 file_dialog_start_handler : fileDialogStart,
908 file_queued_handler : fileQueued,
909 upload_start_handler : uploadStart,
910 upload_progress_handler : uploadProgress,
911 upload_error_handler : uploadError,
912 upload_success_handler : uploadSuccess,
913 upload_complete_handler : uploadComplete,
914 file_queue_error_handler : fileQueueError,
915 file_dialog_complete_handler : fileDialogComplete,
919 $("#flash-browse-button").bind( "click", function(){swfu.selectFiles();});
924 <div id="flash-upload-ui">
925 <?php do_action('pre-flash-upload-ui'); ?>
926 <p><input id="flash-browse-button" type="button" value="<?php echo attribute_escape( __( 'Choose files to upload' ) ); ?>" class="button" /></p>
927 <?php do_action('post-flash-upload-ui'); ?>
928 <p class="howto"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></p>
931 <?php endif; // $flash ?>
933 <div id="html-upload-ui">
934 <?php do_action('pre-html-upload-ui'); ?>
936 <input type="file" name="async-upload" id="async-upload" /> <input type="submit" class="button" name="html-upload" value="<?php echo attribute_escape(__('Upload')); ?>" /> <a href="#" onclick="return top.tb_remove();"><?php _e('Cancel'); ?></a>
939 <?php if ( is_lighttpd_before_150() ): ?>
940 <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>
942 <?php do_action('post-html-upload-ui'); ?>
944 <?php do_action('post-upload-ui'); ?>
948 function media_upload_type_form($type = 'file', $errors = null, $id = null) {
949 media_upload_header();
951 $post_id = intval($_REQUEST['post_id']);
953 $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
954 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
956 $callback = "type_form_$type";
959 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form type-form validate" id="<?php echo $type; ?>-form">
960 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
961 <?php wp_nonce_field('media-form'); ?>
962 <h3><?php _e('From Computer'); ?></h3>
963 <?php media_upload_form( $errors ); ?>
965 <script type="text/javascript">
968 var preloaded = $(".media-item.preloaded");
969 if ( preloaded.length > 0 ) {
970 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
976 <?php if ( $id && !is_wp_error($id) ) : ?>
977 <div id="media-items">
978 <?php echo get_media_items( $id, $errors ); ?>
980 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
982 <?php elseif ( is_callable($callback) ) : ?>
984 <div class="media-blank">
985 <p style="text-align:center"><?php _e('— OR —'); ?></p>
986 <h3><?php _e('From URL'); ?></h3>
989 <script type="text/javascript">
997 insert : function() {
998 var t = this, html, f = document.forms[0], cls, title = '', alt = '', caption = null;
1000 if ( '' == f.src.value || '' == t.width ) return false;
1002 if ( f.title.value ) {
1003 title = f.title.value.replace(/['"<>]+/g, '');
1004 title = ' title="'+title+'"';
1007 if ( f.alt.value ) {
1008 alt = f.alt.value.replace(/['"<>]+/g, '');
1009 <?php if ( ! apply_filters( 'disable_captions', '' ) ) { ?>
1010 caption = f.alt.value.replace(/'/g, ''').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
1014 cls = caption ? '' : ' class="'+t.align+'"';
1016 html = '<img alt="'+alt+'" src="'+f.src.value+'"'+title+cls+' width="'+t.width+'" height="'+t.height+'" />';
1019 html = '<a href="'+f.url.value+'">'+html+'</a>';
1022 html = '[caption id="" align="'+t.align+'" width="'+t.width+'" caption="'+caption+'"]'+html+'[/caption]';
1024 var win = window.dialogArguments || opener || parent || top;
1025 win.send_to_editor(html);
1028 resetImageData : function() {
1029 var t = addExtImage;
1031 t.width = t.height = '';
1032 document.getElementById('go_button').style.color = '#bbb';
1033 if ( ! document.forms[0].src.value )
1034 document.getElementById('status_img').src = 'images/required.gif';
1035 else document.getElementById('status_img').src = 'images/no.png';
1038 updateImageData : function() {
1039 var t = addExtImage;
1041 t.width = t.preloadImg.width;
1042 t.height = t.preloadImg.height;
1043 document.getElementById('go_button').style.color = '#333';
1044 document.getElementById('status_img').src = 'images/yes.png';
1047 getImageData : function() {
1048 var t = addExtImage, src = document.forms[0].src.value;
1054 document.getElementById('status_img').src = 'images/loading.gif';
1055 t.preloadImg = new Image();
1056 t.preloadImg.onload = t.updateImageData;
1057 t.preloadImg.onerror = t.resetImageData;
1058 t.preloadImg.src = src;
1064 <div id="media-items">
1065 <div class="media-item media-blank">
1066 <?php echo call_user_func($callback); ?>
1069 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
1075 function media_upload_gallery_form($errors) {
1078 $redir_tab = 'gallery';
1079 media_upload_header();
1081 $post_id = intval($_REQUEST['post_id']);
1082 $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=gallery&post_id=$post_id");
1085 <script type="text/javascript">
1088 var preloaded = $(".media-item.preloaded");
1089 if ( preloaded.length > 0 ) {
1090 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1097 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="gallery-form">
1098 <?php wp_nonce_field('media-form'); ?>
1099 <?php //media_upload_form( $errors ); ?>
1100 <table class="widefat">
1102 <th><?php _e('Media'); ?></th>
1103 <th class="order-head"><?php _e('Order'); ?></th>
1106 <div id="media-items">
1107 <?php echo get_media_items($post_id, $errors); ?>
1109 <p class="ml-submit">
1110 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
1111 <input type="submit" class="button insert-gallery" name="insert-gallery" value="<?php echo attribute_escape( __( 'Insert gallery into post' ) ); ?>" />
1112 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1113 <input type="hidden" name="type" value="<?php echo attribute_escape( $GLOBALS['type'] ); ?>" />
1114 <input type="hidden" name="tab" value="<?php echo attribute_escape( $GLOBALS['tab'] ); ?>" />
1120 function media_upload_library_form($errors) {
1121 global $wpdb, $wp_query, $wp_locale, $type, $tab, $post_mime_types;
1123 media_upload_header();
1125 $post_id = intval($_REQUEST['post_id']);
1127 $form_action_url = admin_url("media-upload.php?type={$GLOBALS['type']}&tab=library&post_id=$post_id");
1129 $_GET['paged'] = intval($_GET['paged']);
1130 if ( $_GET['paged'] < 1 )
1132 $start = ( $_GET['paged'] - 1 ) * 10;
1135 add_filter( 'post_limits', $limit_filter = create_function( '$a', "return 'LIMIT $start, 10';" ) );
1137 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
1141 <form id="filter" action="" method="get">
1142 <input type="hidden" name="type" value="<?php echo attribute_escape( $type ); ?>" />
1143 <input type="hidden" name="tab" value="<?php echo attribute_escape( $tab ); ?>" />
1144 <input type="hidden" name="post_id" value="<?php echo (int) $post_id; ?>" />
1145 <input type="hidden" name="post_mime_type" value="<?php echo attribute_escape( $_GET['post_mime_type'] ); ?>" />
1147 <div id="search-filter">
1148 <label class="hidden" for="post-search-input"><?php _e('Search Media');?>:</label>
1149 <input type="text" id="post-search-input" name="s" value="<?php the_search_query(); ?>" />
1150 <input type="submit" value="<?php echo attribute_escape( __( 'Search Media' ) ); ?>" class="button" />
1153 <ul class="subsubsub">
1155 $type_links = array();
1156 $_num_posts = (array) wp_count_attachments();
1157 $matches = wp_match_mime_types(array_keys($post_mime_types), array_keys($_num_posts));
1158 foreach ( $matches as $_type => $reals )
1159 foreach ( $reals as $real )
1160 $num_posts[$_type] += $_num_posts[$real];
1161 // If available type specified by media button clicked, filter by that type
1162 if ( empty($_GET['post_mime_type']) && !empty($num_posts[$type]) ) {
1163 $_GET['post_mime_type'] = $type;
1164 list($post_mime_types, $avail_post_mime_types) = wp_edit_attachments_query();
1166 if ( empty($_GET['post_mime_type']) || $_GET['post_mime_type'] == 'all' )
1167 $class = ' class="current"';
1168 $type_links[] = "<li><a href='" . clean_url(add_query_arg(array('post_mime_type'=>'all', 'paged'=>false, 'm'=>false))) . "'$class>".__('All Types')."</a>";
1169 foreach ( $post_mime_types as $mime_type => $label ) {
1172 if ( !wp_match_mime_types($mime_type, $avail_post_mime_types) )
1175 if ( wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
1176 $class = ' class="current"';
1178 $type_links[] = "<li><a href='" . clean_url(add_query_arg(array('post_mime_type'=>$mime_type, 'paged'=>false))) . "'$class>" . sprintf(__ngettext($label[2][0], $label[2][1], $num_posts[$mime_type]), "<span id='$mime_type-counter'>" . number_format_i18n( $num_posts[$mime_type] ) . '</span>') . '</a>';
1180 echo implode(' | </li>', $type_links) . '</li>';
1185 <div class="tablenav">
1188 $page_links = paginate_links( array(
1189 'base' => add_query_arg( 'paged', '%#%' ),
1191 'total' => ceil($wp_query->found_posts / 10),
1192 'current' => $_GET['paged']
1196 echo "<div class='tablenav-pages'>$page_links</div>";
1199 <div class="alignleft">
1202 $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";
1204 $arc_result = $wpdb->get_results( $arc_query );
1206 $month_count = count($arc_result);
1208 if ( $month_count && !( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) { ?>
1210 <option<?php selected( @$_GET['m'], 0 ); ?> value='0'><?php _e('Show all dates'); ?></option>
1212 foreach ($arc_result as $arc_row) {
1213 if ( $arc_row->yyear == 0 )
1215 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
1217 if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] )
1218 $default = ' selected="selected"';
1222 echo "<option$default value='" . attribute_escape( $arc_row->yyear . $arc_row->mmonth ) . "'>";
1223 echo wp_specialchars( $wp_locale->get_month($arc_row->mmonth) . " $arc_row->yyear" );
1230 <input type="submit" id="post-query-submit" value="<?php echo attribute_escape( __( 'Filter »' ) ); ?>" class="button-secondary" />
1234 <br class="clear" />
1238 <form enctype="multipart/form-data" method="post" action="<?php echo attribute_escape($form_action_url); ?>" class="media-upload-form validate" id="library-form">
1240 <?php wp_nonce_field('media-form'); ?>
1241 <?php //media_upload_form( $errors ); ?>
1243 <script type="text/javascript">
1246 var preloaded = $(".media-item.preloaded");
1247 if ( preloaded.length > 0 ) {
1248 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
1255 <div id="media-items">
1256 <?php echo get_media_items(null, $errors); ?>
1258 <p class="ml-submit">
1259 <input type="submit" class="button savebutton" name="save" value="<?php echo attribute_escape( __( 'Save all changes' ) ); ?>" />
1260 <input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
1266 function type_form_image() {
1268 if ( apply_filters( 'disable_captions', '' ) ) {
1269 $alt = __('Alternate Text');
1270 $alt_help = __('Alt text for the image, e.g. "The Mona Lisa"');
1272 $alt = __('Image Caption');
1273 $alt_help = __('Also used as alternate text for the image');
1277 <table class="describe"><tbody>
1279 <th valign="top" scope="row" class="label" style="width:120px;">
1280 <span class="alignleft"><label for="src">' . __('Source') . '</label></span>
1281 <span class="alignright"><img id="status_img" src="images/required.gif" title="required" alt="required" /></span>
1283 <td class="field"><input id="src" name="src" value="" type="text" aria-required="true" onblur="addExtImage.getImageData()" /></td>
1287 <th valign="top" scope="row" class="label">
1288 <span class="alignleft"><label for="title">' . __('Image Title') . '</label></span>
1289 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1291 <td class="field"><p><input id="title" name="title" value="" type="text" aria-required="true" /></p></td>
1295 <th valign="top" scope="row" class="label">
1296 <span class="alignleft"><label for="alt">' . $alt . '</label></span>
1298 <td class="field"><input id="alt" name="alt" value="" type="text" aria-required="true" />
1299 <p class="help">' . $alt_help . '</p></td>
1303 <th valign="top" scope="row" class="label"><p><label for="align">' . __('Alignment') . '</label></p></th>
1305 <input name="align" id="align-none" value="alignnone" onclick="addExtImage.align=this.value" type="radio" checked="checked" />
1306 <label for="align-none" class="align image-align-none-label">' . __('None') . '</label>
1307 <input name="align" id="align-left" value="alignleft" onclick="addExtImage.align=this.value" type="radio" />
1308 <label for="align-left" class="align image-align-left-label">' . __('Left') . '</label>
1309 <input name="align" id="align-center" value="aligncenter" onclick="addExtImage.align=this.value" type="radio" />
1310 <label for="align-center" class="align image-align-center-label">' . __('Center') . '</label>
1311 <input name="align" id="align-right" value="alignright" onclick="addExtImage.align=this.value" type="radio" />
1312 <label for="align-right" class="align image-align-right-label">' . __('Right') . '</label>
1317 <th valign="top" scope="row" class="label">
1318 <span class="alignleft"><label for="url">' . __('Link URL') . '</label></span>
1320 <td class="field"><input id="url" name="url" value="" type="text" /><br />
1322 <button type="button" class="button" value="" onclick="document.forms[0].url.value=null">' . __('None') . '</button>
1323 <button type="button" class="button" value="" onclick="document.forms[0].url.value=document.forms[0].src.value">' . __('Link to image') . '</button>
1324 <p class="help">' . __('Enter a link URL or click above for presets.') . '</p></td>
1330 <input type="button" class="button" id="go_button" style="color:#bbb;" onclick="addExtImage.insert()" value="' . attribute_escape(__('Insert into Post')) . '" />
1338 function type_form_audio() {
1340 <table class="describe"><tbody>
1342 <th valign="top" scope="row" class="label">
1343 <span class="alignleft"><label for="insertonly[href]">' . __('Audio File URL') . '</label></span>
1344 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1346 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
1349 <th valign="top" scope="row" class="label">
1350 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
1351 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1353 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
1355 <tr><td></td><td class="help">' . __('Link text, e.g. "Still Alive by Jonathan Coulton"') . '</td></tr>
1359 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
1366 function type_form_video() {
1368 <table class="describe"><tbody>
1370 <th valign="top" scope="row" class="label">
1371 <span class="alignleft"><label for="insertonly[href]">' . __('Video URL') . '</label></span>
1372 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1374 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
1377 <th valign="top" scope="row" class="label">
1378 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
1379 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1381 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
1383 <tr><td></td><td class="help">' . __('Link text, e.g. "Lucy on YouTube"') . '</td></tr>
1387 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
1394 function type_form_file() {
1396 <table class="describe"><tbody>
1398 <th valign="top" scope="row" class="label">
1399 <span class="alignleft"><label for="insertonly[href]">' . __('URL') . '</label></span>
1400 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1402 <td class="field"><input id="insertonly[href]" name="insertonly[href]" value="" type="text" aria-required="true"></td>
1405 <th valign="top" scope="row" class="label">
1406 <span class="alignleft"><label for="insertonly[title]">' . __('Title') . '</label></span>
1407 <span class="alignright"><abbr title="required" class="required">*</abbr></span>
1409 <td class="field"><input id="insertonly[title]" name="insertonly[title]" value="" type="text" aria-required="true"></td>
1411 <tr><td></td><td class="help">' . __('Link text, e.g. "Ransom Demands (PDF)"') . '</td></tr>
1415 <input type="submit" class="button" name="insertonlybutton" value="' . attribute_escape(__('Insert into Post')) . '" />
1422 // support a GET parameter for disabling the flash uploader
1423 function media_upload_use_flash($flash) {
1424 if ( array_key_exists('flash', $_REQUEST) )
1425 $flash = !empty($_REQUEST['flash']);
1429 add_filter('flash_uploader', 'media_upload_use_flash');
1431 function media_upload_flash_bypass() {
1432 echo '<p class="upload-flash-bypass">';
1433 printf( __('You are using the Flash uploader. Problems? Try the <a href="%s">Browser uploader</a> instead.'), clean_url(add_query_arg('flash', 0)) );
1437 add_action('post-flash-upload-ui', 'media_upload_flash_bypass');
1439 function media_upload_html_bypass() {
1440 echo '<p class="upload-html-bypass">';
1441 if ( array_key_exists('flash', $_REQUEST) )
1442 // the user manually selected the browser uploader, so let them switch back to Flash
1443 printf( __('You are using the Browser uploader. Try the <a href="%s">Flash uploader</a> instead.'), clean_url(add_query_arg('flash', 1)) );
1445 // the user probably doesn't have Flash
1446 printf( __('You are using the Browser uploader.') );
1451 add_action('post-flash-upload-ui', 'media_upload_flash_bypass');
1452 add_action('post-html-upload-ui', 'media_upload_html_bypass');
1454 // make sure the GET parameter sticks when we submit a form
1455 function media_upload_bypass_url($url) {
1456 if ( array_key_exists('flash', $_REQUEST) )
1457 $url = add_query_arg('flash', intval($_REQUEST['flash']));
1461 add_filter('media_upload_form_url', 'media_upload_bypass_url');
1465 add_filter('async_upload_image', 'get_media_item', 10, 2);
1466 add_filter('async_upload_audio', 'get_media_item', 10, 2);
1467 add_filter('async_upload_video', 'get_media_item', 10, 2);
1468 add_filter('async_upload_file', 'get_media_item', 10, 2);
1470 add_action('media_upload_image', 'media_upload_image');
1471 add_action('media_upload_audio', 'media_upload_audio');
1472 add_action('media_upload_video', 'media_upload_video');
1473 add_action('media_upload_file', 'media_upload_file');
1475 add_filter('media_upload_gallery', 'media_upload_gallery');
1477 add_filter('media_upload_library', 'media_upload_library');