| [ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Manage media uploaded file. 4 * 5 * There are many filters in here for media. Plugins can extend functionality 6 * by hooking into the filters. 7 * 8 * @package WordPress 9 * @subpackage Administration 10 */ 11 12 /** Load WordPress Administration Bootstrap */ 13 require_once __DIR__ . '/admin.php'; 14 15 if ( ! current_user_can( 'upload_files' ) ) { 16 wp_die( __( 'Sorry, you are not allowed to upload files.' ) ); 17 } 18 19 wp_enqueue_script( 'plupload-handlers' ); 20 wp_enqueue_media_new_upload(); 21 22 $post_id = 0; 23 if ( isset( $_REQUEST['post_id'] ) ) { 24 $post_id = absint( $_REQUEST['post_id'] ); 25 if ( ! get_post( $post_id ) || ! current_user_can( 'edit_post', $post_id ) ) { 26 $post_id = 0; 27 } 28 } 29 30 if ( $_POST ) { 31 if ( isset( $_POST['html-upload'] ) && ! empty( $_FILES ) ) { 32 check_admin_referer( 'media-form' ); 33 // Upload File button was clicked. 34 $upload_id = media_handle_upload( 'async-upload', $post_id ); 35 if ( is_wp_error( $upload_id ) ) { 36 wp_die( $upload_id ); 37 } 38 } 39 wp_redirect( admin_url( 'upload.php' ) ); 40 exit; 41 } 42 43 // Used in the HTML title tag. 44 $title = __( 'Upload Media' ); 45 $parent_file = 'upload.php'; 46 47 get_current_screen()->add_help_tab( 48 array( 49 'id' => 'overview', 50 'title' => __( 'Overview' ), 51 'content' => 52 '<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>' . 53 '<ul>' . 54 '<li>' . __( '<strong>Drag and drop</strong> your files into the area below. Multiple files are allowed.' ) . '</li>' . 55 '<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>' . 56 '<li>' . __( 'Revert to the <strong>Browser Uploader</strong> by clicking the link below the drag and drop box.' ) . '</li>' . 57 '</ul>', 58 ) 59 ); 60 get_current_screen()->set_help_sidebar( 61 '<p><strong>' . __( 'For more information:' ) . '</strong></p>' . 62 '<p>' . __( '<a href="https://wordpress.org/documentation/article/media-add-new-screen/">Documentation on Uploading Media Files</a>' ) . '</p>' . 63 '<p>' . __( '<a href="https://wordpress.org/support/forums/">Support forums</a>' ) . '</p>' 64 ); 65 66 require_once ABSPATH . 'wp-admin/admin-header.php'; 67 68 $form_class = 'wp-upload-form media-upload-form type-form validate'; 69 70 if ( get_user_setting( 'uploader' ) || isset( $_GET['browser-uploader'] ) ) { 71 $form_class .= ' html-uploader'; 72 } 73 ?> 74 <div class="wrap"> 75 <h1><?php echo esc_html( $title ); ?></h1> 76 77 <form enctype="multipart/form-data" method="post" action="<?php echo esc_url( admin_url( 'media-new.php' ) ); ?>" class="<?php echo esc_attr( $form_class ); ?>" id="file-form"> 78 79 <?php media_upload_form(); ?> 80 81 <script> 82 var post_id = <?php echo absint( $post_id ); ?>, shortform = 3; 83 </script> 84 <input type="hidden" name="post_id" id="post_id" value="<?php echo absint( $post_id ); ?>" /> 85 <?php wp_nonce_field( 'media-form' ); ?> 86 <div id="media-items" class="hide-if-no-js"></div> 87 </form> 88 </div> 89 90 <?php 91 require_once ABSPATH . 'wp-admin/admin-footer.php';
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated : Tue Nov 3 08:20:36 2026 | Cross-referenced by PHPXref |