10 */ |
10 */ |
11 |
11 |
12 /** Load WordPress Administration Bootstrap */ |
12 /** Load WordPress Administration Bootstrap */ |
13 require_once( dirname( __FILE__ ) . '/admin.php' ); |
13 require_once( dirname( __FILE__ ) . '/admin.php' ); |
14 |
14 |
15 if (!current_user_can('upload_files')) |
15 if ( ! current_user_can( 'upload_files' ) ) { |
16 wp_die(__('Sorry, you are not allowed to upload files.')); |
16 wp_die( __( 'Sorry, you are not allowed to upload files.' ) ); |
|
17 } |
17 |
18 |
18 wp_enqueue_script('plupload-handlers'); |
19 wp_enqueue_script( 'plupload-handlers' ); |
19 |
20 |
20 $post_id = 0; |
21 $post_id = 0; |
21 if ( isset( $_REQUEST['post_id'] ) ) { |
22 if ( isset( $_REQUEST['post_id'] ) ) { |
22 $post_id = absint( $_REQUEST['post_id'] ); |
23 $post_id = absint( $_REQUEST['post_id'] ); |
23 if ( ! get_post( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) |
24 if ( ! get_post( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) { |
24 $post_id = 0; |
25 $post_id = 0; |
|
26 } |
25 } |
27 } |
26 |
28 |
27 if ( $_POST ) { |
29 if ( $_POST ) { |
28 if ( isset($_POST['html-upload']) && !empty($_FILES) ) { |
30 if ( isset( $_POST['html-upload'] ) && ! empty( $_FILES ) ) { |
29 check_admin_referer('media-form'); |
31 check_admin_referer( 'media-form' ); |
30 // Upload File button was clicked |
32 // Upload File button was clicked |
31 $upload_id = media_handle_upload( 'async-upload', $post_id ); |
33 $upload_id = media_handle_upload( 'async-upload', $post_id ); |
32 if ( is_wp_error( $upload_id ) ) { |
34 if ( is_wp_error( $upload_id ) ) { |
33 wp_die( $upload_id ); |
35 wp_die( $upload_id ); |
34 } |
36 } |
35 } |
37 } |
36 wp_redirect( admin_url( 'upload.php' ) ); |
38 wp_redirect( admin_url( 'upload.php' ) ); |
37 exit; |
39 exit; |
38 } |
40 } |
39 |
41 |
40 $title = __('Upload New Media'); |
42 $title = __( 'Upload New Media' ); |
41 $parent_file = 'upload.php'; |
43 $parent_file = 'upload.php'; |
42 |
44 |
43 get_current_screen()->add_help_tab( array( |
45 get_current_screen()->add_help_tab( |
44 'id' => 'overview', |
46 array( |
45 'title' => __('Overview'), |
47 'id' => 'overview', |
46 'content' => |
48 'title' => __( 'Overview' ), |
47 '<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>' . |
49 'content' => |
48 '<ul>' . |
50 '<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>' . |
49 '<li>' . __('<strong>Drag and drop</strong> your files into the area below. Multiple files are allowed.') . '</li>' . |
51 '<ul>' . |
50 '<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>' . |
52 '<li>' . __( '<strong>Drag and drop</strong> your files into the area below. Multiple files are allowed.' ) . '</li>' . |
51 '<li>' . __('Revert to the <strong>Browser Uploader</strong> by clicking the link below the drag and drop box.') . '</li>' . |
53 '<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>' . |
52 '</ul>' |
54 '<li>' . __( 'Revert to the <strong>Browser Uploader</strong> by clicking the link below the drag and drop box.' ) . '</li>' . |
53 ) ); |
55 '</ul>', |
|
56 ) |
|
57 ); |
54 get_current_screen()->set_help_sidebar( |
58 get_current_screen()->set_help_sidebar( |
55 '<p><strong>' . __('For more information:') . '</strong></p>' . |
59 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . |
56 '<p>' . __('<a href="https://codex.wordpress.org/Media_Add_New_Screen">Documentation on Uploading Media Files</a>') . '</p>' . |
60 '<p>' . __( '<a href="https://codex.wordpress.org/Media_Add_New_Screen">Documentation on Uploading Media Files</a>' ) . '</p>' . |
57 '<p>' . __('<a href="https://wordpress.org/support/">Support Forums</a>') . '</p>' |
61 '<p>' . __( '<a href="https://wordpress.org/support/">Support</a>' ) . '</p>' |
58 ); |
62 ); |
59 |
63 |
60 require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
64 require_once( ABSPATH . 'wp-admin/admin-header.php' ); |
61 |
65 |
62 $form_class = 'media-upload-form type-form validate'; |
66 $form_class = 'media-upload-form type-form validate'; |
63 |
67 |
64 if ( get_user_setting('uploader') || isset( $_GET['browser-uploader'] ) ) |
68 if ( get_user_setting( 'uploader' ) || isset( $_GET['browser-uploader'] ) ) { |
65 $form_class .= ' html-uploader'; |
69 $form_class .= ' html-uploader'; |
|
70 } |
66 ?> |
71 ?> |
67 <div class="wrap"> |
72 <div class="wrap"> |
68 <h1><?php echo esc_html( $title ); ?></h1> |
73 <h1><?php echo esc_html( $title ); ?></h1> |
69 |
74 |
70 <form enctype="multipart/form-data" method="post" action="<?php echo admin_url('media-new.php'); ?>" class="<?php echo esc_attr( $form_class ); ?>" id="file-form"> |
75 <form enctype="multipart/form-data" method="post" action="<?php echo admin_url( 'media-new.php' ); ?>" class="<?php echo esc_attr( $form_class ); ?>" id="file-form"> |
71 |
76 |
72 <?php media_upload_form(); ?> |
77 <?php media_upload_form(); ?> |
73 |
78 |
74 <script type="text/javascript"> |
79 <script type="text/javascript"> |
75 var post_id = <?php echo $post_id; ?>, shortform = 3; |
80 var post_id = <?php echo $post_id; ?>, shortform = 3; |
76 </script> |
81 </script> |
77 <input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" /> |
82 <input type="hidden" name="post_id" id="post_id" value="<?php echo $post_id; ?>" /> |
78 <?php wp_nonce_field('media-form'); ?> |
83 <?php wp_nonce_field( 'media-form' ); ?> |
79 <div id="media-items" class="hide-if-no-js"></div> |
84 <div id="media-items" class="hide-if-no-js"></div> |
80 </form> |
85 </form> |
81 </div> |
86 </div> |
82 |
87 |
83 <?php |
88 <?php |