3 * Manage media uploaded file.
5 * There are many filters in here for media. Plugins can extend functionality
6 * by hooking into the filters.
9 * @subpackage Administration
12 if ( ! isset( $_GET['inline'] ) )
13 define( 'IFRAME_REQUEST' , true );
15 /** Load WordPress Administration Bootstrap */
16 require_once('./admin.php');
18 if (!current_user_can('upload_files'))
19 wp_die(__('You do not have permission to upload files.'));
21 wp_enqueue_script('plupload-handlers');
22 wp_enqueue_script('image-edit');
23 wp_enqueue_script('set-post-thumbnail' );
24 wp_enqueue_style('imgareaselect');
26 @header('Content-Type: ' . get_option('html_type') . '; charset=' . get_option('blog_charset'));
28 // IDs should be integers
29 $ID = isset($ID) ? (int) $ID : 0;
30 $post_id = isset($post_id)? (int) $post_id : 0;
32 // Require an ID for the edit screen
33 if ( isset($action) && $action == 'edit' && !$ID )
34 wp_die(__("You are not allowed to be here"));
36 if ( isset($_GET['inline']) ) {
39 if ( isset($_POST['html-upload']) && !empty($_FILES) ) {
40 check_admin_referer('media-form');
41 // Upload File button was clicked
42 $id = media_handle_upload('async-upload', $_REQUEST['post_id']);
44 if ( is_wp_error($id) ) {
45 $errors['upload_error'] = $id;
50 if ( isset($_GET['upload-page-form']) ) {
51 $errors = array_merge($errors, (array) media_upload_form_handler());
53 $location = 'upload.php';
55 $location .= '?message=3';
57 wp_redirect( admin_url($location) );
61 $title = __('Upload New Media');
62 $parent_file = 'upload.php';
63 get_current_screen()->add_help_tab( array(
65 'title' => __('Overview'),
67 '<p>' . __('You can upload media files here without creating a post first. This allows you to upload files to use with posts and pages later and/or to get a web link for a particular file that you can share. There are three options for uploading files:') . '</p>' .
69 '<li>' . __('<strong>Drag and drop</strong> your files into the area below. Multiple files are allowed.') . '</li>' .
70 '<li>' . __('<strong>Select Files</strong> will open the multi-file uploader, or you can use the <strong>Browser Uploader</strong>.') . '</li>' .
71 '<li>' . __('Clicking <strong>Select Files</strong> opens a navigation window showing you files in your operating system. Selecting <strong>Open</strong> after clicking on the file you want activates a progress bar on the uploader screen.') . '</li>' .
73 '<p>' . __('Basic image editing is available after upload is complete. Make sure you click Save before leaving this screen.') . '</p>'
75 get_current_screen()->set_help_sidebar(
76 '<p><strong>' . __('For more information:') . '</strong></p>' .
77 '<p>' . __('<a href="http://codex.wordpress.org/Media_Add_New_Screen" target="_blank">Documentation on Uploading Media Files</a>') . '</p>' .
78 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
81 require_once('./admin-header.php');
83 $form_class = 'media-upload-form type-form validate';
85 if ( get_user_setting('uploader') )
86 $form_class .= ' html-uploader';
89 <?php screen_icon(); ?>
90 <h2><?php echo esc_html( $title ); ?></h2>
92 <form enctype="multipart/form-data" method="post" action="<?php echo admin_url('media-upload.php?inline=&upload-page-form='); ?>" class="<?php echo $form_class; ?>" id="file-form">
94 <?php media_upload_form(); ?>
96 <script type="text/javascript">
98 var preloaded = $(".media-item.preloaded");
99 if ( preloaded.length > 0 ) {
100 preloaded.each(function(){prepareMediaItem({id:this.id.replace(/[^0-9]/g, '')},'');});
107 <input type="hidden" name="post_id" id="post_id" value="0" />
108 <?php wp_nonce_field('media-form'); ?>
109 <div id="media-items" class="hide-if-no-js"></div>
110 <?php submit_button( __( 'Save all changes' ), 'button savebutton hidden', 'save' ); ?>
115 include('./admin-footer.php');
119 // upload type: image, video, file, ..?
120 if ( isset($_GET['type']) )
121 $type = strval($_GET['type']);
123 $type = apply_filters('media_upload_default_type', 'file');
125 // tab: gallery, library, or type-specific
126 if ( isset($_GET['tab']) )
127 $tab = strval($_GET['tab']);
129 $tab = apply_filters('media_upload_default_tab', 'type');
131 $body_id = 'media-upload';
133 // let the action code decide how to handle the request
134 if ( $tab == 'type' || $tab == 'type_url' || ! array_key_exists( $tab , media_upload_tabs() ) )
135 do_action("media_upload_$type");
137 do_action("media_upload_$tab");